Add authentication by token.
parent
4a10456f27
commit
66ebcb662d
|
@ -1,4 +1,17 @@
|
||||||
class AuthD::Request
|
class AuthD::Request
|
||||||
|
def self.perform_login(authd : AuthD::Service, fd : Int32, user : AuthD::User)
|
||||||
|
user.date_last_connection = Time.local
|
||||||
|
token = user.to_token
|
||||||
|
|
||||||
|
# Change the date of the last connection.
|
||||||
|
authd.users_per_uid.update user.uid.to_s, user
|
||||||
|
|
||||||
|
# On successuful connection: store the authenticated user in a hash.
|
||||||
|
authd.logged_users[fd] = user.to_public
|
||||||
|
|
||||||
|
Response::Login.new (token.to_s authd.configuration.secret_key), user.uid
|
||||||
|
end
|
||||||
|
|
||||||
IPC::JSON.message Login, 0 do
|
IPC::JSON.message Login, 0 do
|
||||||
property login : String
|
property login : String
|
||||||
property password : String
|
property password : String
|
||||||
|
@ -29,17 +42,25 @@ class AuthD::Request
|
||||||
return Response::ErrorInvalidCredentials.new
|
return Response::ErrorInvalidCredentials.new
|
||||||
end
|
end
|
||||||
|
|
||||||
user.date_last_connection = Time.local
|
AuthD::Request.perform_login authd, fd, user.not_nil!
|
||||||
token = user.to_token
|
|
||||||
|
|
||||||
# Change the date of the last connection.
|
|
||||||
authd.users_per_uid.update user.uid.to_s, user
|
|
||||||
|
|
||||||
# On successuful connection: store the authenticated user in a hash.
|
|
||||||
authd.logged_users[fd] = user.to_public
|
|
||||||
|
|
||||||
Response::Login.new (token.to_s authd.configuration.secret_key), user.uid
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
AuthD.requests << Login
|
AuthD.requests << Login
|
||||||
|
|
||||||
|
IPC::JSON.message AuthByToken, 15 do
|
||||||
|
property token : String
|
||||||
|
|
||||||
|
def initialize(@token)
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle(authd : AuthD::Service, fd : Int32)
|
||||||
|
token_payload = AuthD::Token.from_s authd.configuration.secret_key, token
|
||||||
|
user = authd.users_per_uid.get? token_payload.uid.to_s
|
||||||
|
|
||||||
|
return Response::ErrorUserNotFound.new if user.nil?
|
||||||
|
|
||||||
|
AuthD::Request.perform_login authd, fd, user
|
||||||
|
end
|
||||||
|
end
|
||||||
|
AuthD.requests << AuthByToken
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue