AuthD::Client#get_user?(login, password) added.

This commit is contained in:
Luka Vandervelden 2019-02-16 22:06:56 +01:00
parent 66ac26b46e
commit 87b90c1768
2 changed files with 38 additions and 0 deletions

View File

@ -11,6 +11,7 @@ module AuthD
GetToken
AddUser
GetUser
GetUserByCredentials
end
enum ResponseTypes
@ -46,6 +47,13 @@ module AuthD
})
end
class GetUserByCredentialsRequest
JSON.mapping({
login: String,
password: String
})
end
class Client < IPC::Client
property key : String
@ -70,6 +78,21 @@ module AuthD
end
end
def get_user?(login : String, password : String)
send RequestTypes::GetUserByCredentials, {
:login => login,
:password => password
}.to_json
response = read
if response.type == ResponseTypes::Ok.value.to_u8
User.from_json response.payload
else
nil
end
end
def get_user?(uid : Int32)
send RequestTypes::GetUser, {:uid => uid}.to_json

View File

@ -93,6 +93,21 @@ IPC::Service.new "auth" do |event|
user = passwd.add_user request.login, request.password
client.send ResponseTypes::Ok, user.to_json
when RequestTypes::GetUserByCredentials
begin
request = GetUserByCredentialsRequest.from_json payload
rescue e
client.send ResponseTypes::MalformedRequest, e.message || ""
next
end
user = passwd.get_user request.login, request.password
if user
client.send ResponseTypes::Ok, user.to_json
else
client.send ResponseTypes::UserNotFound, ""
end
when RequestTypes::GetUser
begin
request = GetUserRequest.from_json payload