Module: TinyAuth::Model::ClassMethods
- Defined in:
- lib/tiny_auth/model.rb
Instance Method Summary collapse
-
#exchange_reset_token(token) ⇒ ActiveRecord::Base?
Finds a resource by their reset token and nillifies
reset_password_digestandreset_token_expires_atfields. -
#find_by_credentials(email, password) ⇒ ActiveRecord::Base?
Find a resource by their email address and password This assumes that you’ve added
has_secure_passwordto your model. -
#find_by_email(email) ⇒ ActiveRecord::Base?
Find a resource by email, ignoring case.
-
#find_by_token(token) ⇒ ActiveRecord::Base?
Finds a resource by a token.
Instance Method Details
#exchange_reset_token(token) ⇒ ActiveRecord::Base?
Finds a resource by their reset token and nillifies reset_password_digest and reset_token_expires_at fields
43 44 45 46 47 48 49 50 |
# File 'lib/tiny_auth/model.rb', line 43 def exchange_reset_token(token) digest = TinyAuth.hexdigest(token) not_expired = arel_table[:reset_token_expires_at].gt(Time.now) resource = where(not_expired).find_by(reset_token_digest: digest) resource&.reset_token_digest = nil resource&.reset_token_expires_at = nil resource end |
#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) ⇒ ActiveRecord::Base?
Finds a resource by a token
33 34 35 36 37 |
# File 'lib/tiny_auth/model.rb', line 33 def find_by_token(token) resource = GlobalID::Locator.locate_signed(token, for: :access) resource if resource.kind_of?(self) rescue ActiveRecord::RecordNotFound end |