ModUser takes uid|login, can change phone and email
parent
f66a08ff60
commit
b6cbe6c84a
12
src/authd.cr
12
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
|
||||
|
|
17
src/main.cr
17
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"
|
||||
|
|
Loading…
Reference in New Issue