mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-06 06:48:21 +00:00
24 lines
428 B
Ruby
24 lines
428 B
Ruby
class AuthenticateUser
|
|
prepend SimpleCommand
|
|
|
|
def initialize(email, password)
|
|
@email = email
|
|
@password = password
|
|
end
|
|
|
|
def call
|
|
JsonWebToken.encode(user_id: user.id) if user
|
|
end
|
|
|
|
private
|
|
|
|
attr_accessor :email, :password
|
|
|
|
def user
|
|
user = User.find_by_email(email)
|
|
return user if user && user.authenticate(password)
|
|
|
|
errors.add :user_authentication, 'invalid credentials'
|
|
nil
|
|
end
|
|
end
|