Class: Notee::User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Notee::User
- Defined in:
- app/models/notee/user.rb
Instance Attribute Summary collapse
-
#editor_id ⇒ Object
Returns the value of attribute editor_id.
-
#file ⇒ Object
accessors.
-
#password ⇒ Object
Returns the value of attribute password.
-
#password_confirm ⇒ Object
Returns the value of attribute password_confirm.
Instance Method Summary collapse
- #confirm_password ⇒ Object
- #encrypt(password) ⇒ Object
- #encrypt_password ⇒ Object
- #manage_profile_img ⇒ Object
- #sign_in(name_or_email, password) ⇒ Object
Instance Attribute Details
#editor_id ⇒ Object
Returns the value of attribute editor_id.
31 32 33 |
# File 'app/models/notee/user.rb', line 31 def editor_id @editor_id end |
#file ⇒ Object
accessors
28 29 30 |
# File 'app/models/notee/user.rb', line 28 def file @file end |
#password ⇒ Object
Returns the value of attribute password.
29 30 31 |
# File 'app/models/notee/user.rb', line 29 def password @password end |
#password_confirm ⇒ Object
Returns the value of attribute password_confirm.
30 31 32 |
# File 'app/models/notee/user.rb', line 30 def password_confirm @password_confirm end |
Instance Method Details
#confirm_password ⇒ Object
51 52 53 |
# File 'app/models/notee/user.rb', line 51 def confirm_password return false unless password == password_confirm end |
#encrypt(password) ⇒ Object
47 48 49 |
# File 'app/models/notee/user.rb', line 47 def encrypt(password) OpenSSL::Digest::MD5.hexdigest(password) end |
#encrypt_password ⇒ Object
55 56 57 |
# File 'app/models/notee/user.rb', line 55 def encrypt_password self.encrypted_password = encrypt(password) end |
#manage_profile_img ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/models/notee/user.rb', line 59 def manage_profile_img return unless file return if User.exists?(profile_img: file) image_dir = Rails.root.to_s + '/public/notee/profile/' FileUtils.mkdir_p(image_dir) unless FileTest.exist?(image_dir) image_name = Time.now.strftime('%Y%m%d%H%M%S') + '--' + SecureRandom.uuid + '.jpg' transaction do open(image_dir + '/' + image_name, 'wb') do |output| output.write(file.read) end end self.profile_img = image_name end |
#sign_in(name_or_email, password) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'app/models/notee/user.rb', line 38 def sign_in(name_or_email, password) user = find_by(name: name_or_email) user = find_by(email: name_or_email) unless user return false unless user return false unless user.encrypted_password == encrypt(password) user end |