vereto-api/app/auth/authenticate_user.rb

22 lines
436 B
Ruby
Raw Permalink Normal View History

2018-02-16 15:02:03 +00:00
class AuthenticateUser
def initialize(email, password)
@email = email
@password = password
end
# Service entry point
def call
JsonWebToken.encode(user_id: user.id) if user
end
private
attr_reader :email, :password
def user
user = User.find_by(email: email)
return user if user && user.authenticate(password)
raise(ExceptionHandler::AuthenticationError, Message.invalid_credentials)
end
end