Module: TinyAuth::Model::ClassMethods
- Defined in:
- lib/tiny_auth/model.rb
Instance Method Summary collapse
-
#find_by_credentials(email, password) ⇒ ActiveRecord::Base?
Find a resource by their email address and password This assumes that you’ve added ‘has_secure_password` to your model.
-
#find_by_email(email) ⇒ ActiveRecord::Base?
Find a resource by email, ignoring case.
-
#find_by_token(token, purpose: :access) ⇒ ActiveRecord::Base?
Finds a resource by a token.
Instance Method Details
#find_by_credentials(email, password) ⇒ ActiveRecord::Base?
Find a resource by their email address and password This assumes that you’ve added ‘has_secure_password` to your model.
25 26 27 28 |
# File 'lib/tiny_auth/model.rb', line 25 def find_by_credentials(email, password) resource = find_by_email(email) resource if resource&.authenticate(password) end |
#find_by_email(email) ⇒ ActiveRecord::Base?
Find a resource by email, ignoring case
16 17 18 |
# File 'lib/tiny_auth/model.rb', line 16 def find_by_email(email) find_by(arel_table[:email].lower.eq(email.downcase)) end |
#find_by_token(token, purpose: :access) ⇒ ActiveRecord::Base?
Finds a resource by a token
34 35 36 37 38 |
# File 'lib/tiny_auth/model.rb', line 34 def find_by_token(token, purpose: :access) id, token_version = TinyAuth.verifier.verify(token, purpose: purpose) find_by(id: id, token_version: token_version) rescue ActiveSupport::MessageVerifier::InvalidSignature end |