Client bugfix.

cbor
Karchnu 2020-11-26 04:02:19 +01:00
parent dbcfa4880b
commit 9b33f686bd
1 changed files with 31 additions and 30 deletions

View File

@ -1,3 +1,4 @@
require "ipc/json"
module AuthD module AuthD
class Client < IPC::Client class Client < IPC::Client
@ -10,9 +11,9 @@ module AuthD
end end
def get_token?(login : String, password : String) : String? def get_token?(login : String, password : String) : String?
send Request::GetToken.new login, password send_now Request::GetToken.new login, password
response = Response.from_ipc read response = AuthD.responses.parse_ipc_json read
if response.is_a?(Response::Token) if response.is_a?(Response::Token)
response.token response.token
@ -22,9 +23,9 @@ module AuthD
end end
def get_user?(login : String, password : String) : AuthD::User::Public? def get_user?(login : String, password : String) : AuthD::User::Public?
send Request::GetUserByCredentials.new login, password send_now Request::GetUserByCredentials.new login, password
response = Response.from_ipc read response = AuthD.responses.parse_ipc_json read
if response.is_a? Response::User if response.is_a? Response::User
response.user response.user
@ -34,9 +35,9 @@ module AuthD
end end
def get_user?(uid_or_login : Int32 | String) : ::AuthD::User::Public? def get_user?(uid_or_login : Int32 | String) : ::AuthD::User::Public?
send Request::GetUser.new uid_or_login send_now Request::GetUser.new uid_or_login
response = Response.from_ipc read response = AuthD.responses.parse_ipc_json read
if response.is_a? Response::User if response.is_a? Response::User
response.user response.user
@ -45,7 +46,7 @@ module AuthD
end end
end end
def send(type : Request::Type, payload) def send_now(type : Request::Type, payload)
send_now @server_fd, type.value.to_u8, payload send_now @server_fd, type.value.to_u8, payload
end end
@ -63,9 +64,9 @@ module AuthD
phone : String?, phone : String?,
profile : Hash(String, JSON::Any)?) : ::AuthD::User::Public | Exception profile : Hash(String, JSON::Any)?) : ::AuthD::User::Public | Exception
send Request::AddUser.new @key, login, password, email, phone, profile send_now Request::AddUser.new @key, login, password, email, phone, profile
response = Response.from_ipc read response = AuthD.responses.parse_ipc_json read
case response case response
when Response::UserAdded when Response::UserAdded
@ -80,9 +81,9 @@ module AuthD
end end
def validate_user(login : String, activation_key : String) : ::AuthD::User::Public | Exception def validate_user(login : String, activation_key : String) : ::AuthD::User::Public | Exception
send Request::ValidateUser.new login, activation_key send_now Request::ValidateUser.new login, activation_key
response = Response.from_ipc read response = AuthD.responses.parse_ipc_json read
case response case response
when Response::UserValidated when Response::UserValidated
@ -97,8 +98,8 @@ module AuthD
end end
def ask_password_recovery(uid_or_login : String | Int32, email : String) def ask_password_recovery(uid_or_login : String | Int32, email : String)
send Request::AskPasswordRecovery.new uid_or_login, email send_now Request::AskPasswordRecovery.new uid_or_login, email
response = Response.from_ipc read response = AuthD.responses.parse_ipc_json read
case response case response
when Response::PasswordRecoverySent when Response::PasswordRecoverySent
@ -110,8 +111,8 @@ module AuthD
end end
def change_password(uid_or_login : String | Int32, new_pass : String, renew_key : String) def change_password(uid_or_login : String | Int32, new_pass : String, renew_key : String)
send Request::PasswordRecovery.new uid_or_login, renew_key, new_pass send_now Request::PasswordRecovery.new uid_or_login, renew_key, new_pass
response = Response.from_ipc read response = AuthD.responses.parse_ipc_json read
case response case response
when Response::PasswordRecovered when Response::PasswordRecovered
@ -128,8 +129,8 @@ module AuthD
phone : String?, phone : String?,
profile : Hash(String, JSON::Any)?) : ::AuthD::User::Public? profile : Hash(String, JSON::Any)?) : ::AuthD::User::Public?
send Request::Register.new login, password, email, phone, profile send_now Request::Register.new login, password, email, phone, profile
response = Response.from_ipc read response = AuthD.responses.parse_ipc_json read
case response case response
when Response::UserAdded when Response::UserAdded
@ -146,9 +147,9 @@ module AuthD
request.phone = phone if phone request.phone = phone if phone
request.avatar = avatar if avatar request.avatar = avatar if avatar
send request send_now request
response = Response.from_ipc read response = AuthD.responses.parse_ipc_json read
case response case response
when Response::UserEdited when Response::UserEdited
@ -163,9 +164,9 @@ module AuthD
def check_permission(user : Int32, service_name : String, resource_name : String) : User::PermissionLevel def check_permission(user : Int32, service_name : String, resource_name : String) : User::PermissionLevel
request = Request::CheckPermission.new @key, user, service_name, resource_name request = Request::CheckPermission.new @key, user, service_name, resource_name
send request send_now request
response = Response.from_ipc read response = AuthD.responses.parse_ipc_json read
case response case response
when Response::PermissionCheck when Response::PermissionCheck
@ -180,9 +181,9 @@ module AuthD
def set_permission(uid : Int32, service : String, resource : String, permission : User::PermissionLevel) def set_permission(uid : Int32, service : String, resource : String, permission : User::PermissionLevel)
request = Request::SetPermission.new @key, uid, service, resource, permission request = Request::SetPermission.new @key, uid, service, resource, permission
send request send_now request
response = Response.from_ipc read response = AuthD.responses.parse_ipc_json read
case response case response
when Response::PermissionSet when Response::PermissionSet
@ -195,8 +196,8 @@ module AuthD
end end
def search_user(user_login : String) def search_user(user_login : String)
send Request::SearchUser.new user_login send_now Request::SearchUser.new user_login
response = Response.from_ipc read response = AuthD.responses.parse_ipc_json read
case response case response
when Response::MatchingUsers when Response::MatchingUsers
@ -209,8 +210,8 @@ module AuthD
end end
def edit_profile_content(user : Int32 | String, new_values) def edit_profile_content(user : Int32 | String, new_values)
send Request::EditProfileContent.new key, user, new_values send_now Request::EditProfileContent.new key, user, new_values
response = Response.from_ipc read response = AuthD.responses.parse_ipc_json read
case response case response
when Response::User when Response::User
@ -223,15 +224,15 @@ module AuthD
end end
def delete(user : Int32 | String, key : String) def delete(user : Int32 | String, key : String)
send Request::Delete.new user, key send_now Request::Delete.new user, key
delete_ delete_
end end
def delete(user : Int32 | String, login : String, pass : String) def delete(user : Int32 | String, login : String, pass : String)
send Request::Delete.new user, login, pass send_now Request::Delete.new user, login, pass
delete_ delete_
end end
def delete_ def delete_
response = Response.from_ipc read response = AuthD.responses.parse_ipc_json read
case response case response
when Response::Error when Response::Error
raise Exception.new response.reason raise Exception.new response.reason