Sha256: 28449620bf4907fe8e737041de369f75e3e2b02b42006ce08afd0b1a3306f5cd
Contents?: true
Size: 1.08 KB
Versions: 14
Compression:
Stored size: 1.08 KB
Contents
module Ctws class AuthenticateUser def initialize(email, password="12346") @email = email @password = password end # Service entry point def call Ctws::JsonWebToken.encode(user_id: user.id) if user # attrs_hash = {} # Ctws.jwt_auth_token_attrs.each {|a| attrs_hash.merge!({"user_#{a}": user.try(a)})} # Ctws::JsonWebToken.encode(attrs_hash) if user end private attr_reader :email, :password # verify user credentials def user user = Ctws.user_class.find_by(email: email) if Ctws.user_validate_with_password # try method of Active Record's has_secure_password or Devise valid_password? authenticated = user.try(:authenticate, password) || user.try(:valid_password?, password) elsif !Ctws.user_validate_with_password authenticated = true end return user if user && authenticated # raise Authentication error if credentials are invalid raise(Ctws::ExceptionHandler::AuthenticationError, Ctws::Message.invalid_credentials) end end end
Version data entries
14 entries across 14 versions & 1 rubygems