user_validation

ipc07
Philippe PITTOLI 2020-01-22 10:13:59 +01:00
parent bef2e73fff
commit af44f82e99
1 changed files with 36 additions and 0 deletions

View File

@ -69,6 +69,13 @@ class AuthD::Response
initialize :uid
end
class UserValidated < Response
property uid : Int32
property email : String
initialize :uid, :email
end
class UsersList < Response
property users : Array(::AuthD::User::Public)
@ -187,6 +194,17 @@ class AuthD::Request
initialize :shared_key, :login, :password, :email, :phone, :profile
end
class ValidateUser < Request
# Only clients that have the right shared key will be allowed
# to validate users.
property shared_key : String
property email : String
property activation_key : String
initialize :shared_key, :email, :activation_key
end
class GetUser < Request
property user : Int32 | String
@ -380,6 +398,24 @@ module AuthD
end
end
def validate_user(email : String, activation_key : String) : ::AuthD::User::Public | Exception
send Request::AddUser.new @key, email, activation_key
response = Response.from_ipc read
case response
when Response::UserValidated
response.user
when Response::Error
raise Exception.new response.reason
else
# Should not happen in serialized connections, but…
# itll happen if you run several requests at once.
Exception.new
end
end
def register(login : String, password : String, profile : JSON::Any?) : ::AuthD::User::Public?
send Request::Register.new login, password, profile