module TinyAuth::Model::ClassMethods

Public Instance Methods

find_by_credentials(email, password) click to toggle source

Find a resource by their email address and password This assumes that you've added `has_secure_password` to your model. @param email [String] @param password [String] @return [ActiveRecord::Base,nil]

# 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) click to toggle source

Find a resource by email, ignoring case @param email [String] @return [ActiveRecord::Base,nil]

# 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) click to toggle source

Finds a resource by a token @param token [String] @param purpose [Symbol] defaults to `:access` @return [ActiveRecord::Base,nil]

# 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