From af44f82e99eb3a0d2a48192625c0e12fbd81b8aa Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Wed, 22 Jan 2020 10:13:59 +0100 Subject: [PATCH] user_validation --- src/authd.cr | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/authd.cr b/src/authd.cr index 5d00cf8..3f0088c 100644 --- a/src/authd.cr +++ b/src/authd.cr @@ -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… + # it’ll 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