module ActsAsHocUser::ClassMethods

Public Instance Methods

acts_as_hoc_user(_options = {}) click to toggle source
# File lib/acts_as_hoc_user/acts_as_hoc_user.rb, line 40
def acts_as_hoc_user(_options = {})
  has_secure_password
  validates_presence_of :email
  validates :email, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP }
  validates :password, length: { minimum: ActsAsHocUser.configuration.min_password_length }, if: -> { password.present? }
end
authenticate_with_authentication_token(token) click to toggle source
# File lib/acts_as_hoc_user/acts_as_hoc_user.rb, line 26
def authenticate_with_authentication_token(token)
  decoded_auth_token = JsonWebToken.decode(token)
  return nil if decoded_auth_token.nil?
  user = User.find(decoded_auth_token[:user_id])
  return user
end
authenticate_with_credentials(email, password, expiration = 14.days.from_now) click to toggle source
# File lib/acts_as_hoc_user/acts_as_hoc_user.rb, line 13
def authenticate_with_credentials(email, password, expiration = 14.days.from_now)
  user = User.find_by(email:email)
  return nil if user.nil?
  return user.authentication_token(expiration) if user.authenticate(password)
  nil
end
authenticate_with_http_headers(headers = {}) click to toggle source
# File lib/acts_as_hoc_user/acts_as_hoc_user.rb, line 33
def authenticate_with_http_headers(headers = {})
  if headers['Authorization'].present?
    return authenticate_with_authentication_token(headers['Authorization'].split(' ').last)
  end
  return nil
end
authenticate_with_sso_token(token) click to toggle source
# File lib/acts_as_hoc_user/acts_as_hoc_user.rb, line 20
def authenticate_with_sso_token(token)
  user = User.find_by(sso_token: token)
  return nil if user.nil?
  return user.authentication_token(expiration)
end