AuthD::Client#get_user?(login, password) added.
parent
66ac26b46e
commit
87b90c1768
23
src/authd.cr
23
src/authd.cr
|
@ -11,6 +11,7 @@ module AuthD
|
||||||
GetToken
|
GetToken
|
||||||
AddUser
|
AddUser
|
||||||
GetUser
|
GetUser
|
||||||
|
GetUserByCredentials
|
||||||
end
|
end
|
||||||
|
|
||||||
enum ResponseTypes
|
enum ResponseTypes
|
||||||
|
@ -46,6 +47,13 @@ module AuthD
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class GetUserByCredentialsRequest
|
||||||
|
JSON.mapping({
|
||||||
|
login: String,
|
||||||
|
password: String
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
class Client < IPC::Client
|
class Client < IPC::Client
|
||||||
property key : String
|
property key : String
|
||||||
|
|
||||||
|
@ -70,6 +78,21 @@ module AuthD
|
||||||
end
|
end
|
||||||
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)
|
def get_user?(uid : Int32)
|
||||||
send RequestTypes::GetUser, {:uid => uid}.to_json
|
send RequestTypes::GetUser, {:uid => uid}.to_json
|
||||||
|
|
||||||
|
|
15
src/main.cr
15
src/main.cr
|
@ -93,6 +93,21 @@ IPC::Service.new "auth" do |event|
|
||||||
user = passwd.add_user request.login, request.password
|
user = passwd.add_user request.login, request.password
|
||||||
|
|
||||||
client.send ResponseTypes::Ok, user.to_json
|
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
|
when RequestTypes::GetUser
|
||||||
begin
|
begin
|
||||||
request = GetUserRequest.from_json payload
|
request = GetUserRequest.from_json payload
|
||||||
|
|
Loading…
Reference in New Issue