From b6cbe6c84a347838821523ef723b3a76844c9370 Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Sun, 9 Feb 2020 15:47:44 +0100 Subject: [PATCH] ModUser takes uid|login, can change phone and email --- src/authd.cr | 12 ++++++++---- src/main.cr | 17 +++++++++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/authd.cr b/src/authd.cr index 57f185d..2114598 100644 --- a/src/authd.cr +++ b/src/authd.cr @@ -220,11 +220,13 @@ class AuthD::Request class ModUser < Request property shared_key : String - property uid : Int32 + property user : Int32 | String property password : String? + property email : String? + property phone : String? property avatar : String? - initialize :shared_key, :uid + initialize :shared_key, :user end class Request::Register < Request @@ -433,10 +435,12 @@ module AuthD end end - def mod_user(uid : Int32, password : String? = nil, avatar : String? = nil) : Bool | Exception - request = Request::ModUser.new @key, uid + def mod_user(uid_or_login : Int32 | String, password : String? = nil, email : String? = nil, phone : String? = nil, avatar : String? = nil) : Bool | Exception + request = Request::ModUser.new @key, uid_or_login request.password = password if password + request.email = email if email + request.phone = phone if phone request.avatar = avatar if avatar send request diff --git a/src/main.cr b/src/main.cr index 147ff26..072f218 100644 --- a/src/main.cr +++ b/src/main.cr @@ -148,7 +148,12 @@ class AuthD::Service return Response::Error.new "invalid authentication key" end - user = @users_per_uid.get? request.uid.to_s + uid_or_login = request.user + user = if uid_or_login.is_a? Int32 + @users_per_uid.get? uid_or_login.to_s + else + @users_per_login.get? uid_or_login + end unless user return Response::Error.new "user not found" @@ -158,9 +163,17 @@ class AuthD::Service user.password_hash = hash_password s end + request.email.try do |email| + user.contact.email = email + end + + request.phone.try do |phone| + user.contact.phone = phone + end + @users_per_uid.update user.uid.to_s, user - Response::UserEdited.new request.uid + Response::UserEdited.new user.uid when Request::Register if ! @registrations_allowed return Response::Error.new "registrations not allowed"