2020-11-22 13:49:34 +01:00
|
|
|
class AuthD::Request
|
2023-06-10 17:26:12 +02:00
|
|
|
IPC::JSON.message Login, 0 do
|
2020-11-22 13:49:34 +01:00
|
|
|
property login : String
|
|
|
|
property password : String
|
|
|
|
|
|
|
|
def initialize(@login, @password)
|
|
|
|
end
|
|
|
|
|
2023-06-10 17:26:12 +02:00
|
|
|
def handle(authd : AuthD::Service, fd : Int32)
|
2020-11-22 13:49:34 +01:00
|
|
|
begin
|
|
|
|
user = authd.users_per_login.get @login
|
|
|
|
rescue e : DODB::MissingEntry
|
|
|
|
return Response::Error.new "invalid credentials"
|
|
|
|
end
|
|
|
|
|
2023-06-11 18:59:41 +02:00
|
|
|
return Response::Error.new "invalid credentials" if user.nil?
|
2020-11-22 13:49:34 +01:00
|
|
|
|
|
|
|
if user.password_hash != authd.hash_password @password
|
|
|
|
return Response::Error.new "invalid credentials"
|
|
|
|
end
|
|
|
|
|
|
|
|
user.date_last_connection = Time.local
|
|
|
|
token = user.to_token
|
|
|
|
|
2023-06-11 16:39:16 +02:00
|
|
|
# Change the date of the last connection.
|
2020-11-22 13:49:34 +01:00
|
|
|
authd.users_per_uid.update user.uid.to_s, user
|
|
|
|
|
2023-06-11 16:39:16 +02:00
|
|
|
# On successuful connection: store the authenticated user in a hash.
|
|
|
|
authd.logged_users[fd] = user.to_public
|
|
|
|
|
2023-06-10 17:26:12 +02:00
|
|
|
Response::Login.new (token.to_s authd.configuration.shared_key), user.uid
|
2020-11-22 13:49:34 +01:00
|
|
|
end
|
|
|
|
end
|
2023-06-10 17:26:12 +02:00
|
|
|
AuthD.requests << Login
|
2020-11-22 13:49:34 +01:00
|
|
|
end
|