Module: CowAuth::User
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/cow_auth/user.rb
Instance Method Summary collapse
- #authenticate_with_password(password) ⇒ Object
- #authenticate_with_token(auth_token) ⇒ Object
- #create_auth_token ⇒ Object
- #destroy_auth_token ⇒ Object
- #password=(new_password) ⇒ Object
Instance Method Details
#authenticate_with_password(password) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/cow_auth/user.rb', line 18 def authenticate_with_password(password) return false if self.encrypted_password.blank? if SCrypt::Password.new(self.encrypted_password) == password self.update(sign_in_count: self.sign_in_count + 1) return true end return false end |
#authenticate_with_token(auth_token) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/cow_auth/user.rb', line 27 def authenticate_with_token(auth_token) if self.auth_token.present? && self.expires_at.present? && self.auth_token == auth_token && self.expires_at > Time.zone.now return true end return false end |
#create_auth_token ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/cow_auth/user.rb', line 37 def create_auth_token self.update( auth_token: self.token_valid? ? self.auth_token : self.generate_auth_token, expires_at: self.generate_token_expires_at ) return true end |
#destroy_auth_token ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/cow_auth/user.rb', line 45 def destroy_auth_token self.update( auth_token: nil, expires_at: nil ) return true end |
#password=(new_password) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/cow_auth/user.rb', line 53 def password=(new_password) return false if new_password.blank? salt = SCrypt::Engine.generate_salt self.encrypted_password = SCrypt::Engine.hash_secret(new_password, salt) return true end |