Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
- Defined in:
- app/models/user.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#temp_password ⇒ Object
Returns the value of attribute temp_password.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
3 4 5 |
# File 'app/models/user.rb', line 3 def password @password end |
#temp_password ⇒ Object
Returns the value of attribute temp_password.
3 4 5 |
# File 'app/models/user.rb', line 3 def temp_password @temp_password end |
Class Method Details
.authenticate(email, password) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'app/models/user.rb', line 13 def self.authenticate(email, password) user = find_by_email(email) if user && user.password_hash == ::BCrypt::Engine.hash_secret(password, user.password_salt) user else nil end end |
Instance Method Details
#encrypt_password ⇒ Object
22 23 24 25 26 27 |
# File 'app/models/user.rb', line 22 def encrypt_password if password.present? self.password_salt = ::BCrypt::Engine.generate_salt self.password_hash = ::BCrypt::Engine.hash_secret(password, password_salt) end end |
#generate_password ⇒ Object
36 37 38 39 40 41 |
# File 'app/models/user.rb', line 36 def generate_password password_length = 7 lower_alphabets = ("a".."z").to_a return Array.new(password_length){||lower_alphabets[rand(lower_alphabets.size)]}.join end |
#set_temporary_password ⇒ Object
29 30 31 32 33 34 |
# File 'app/models/user.rb', line 29 def set_temporary_password self.temp_password = generate_password self.password_salt = ::BCrypt::Engine.generate_salt self.password_hash = ::BCrypt::Engine.hash_secret(temp_password, password_salt) return temp_password end |