ModUser takes uid|login, can change phone and email
This commit is contained in:
		
							parent
							
								
									f66a08ff60
								
							
						
					
					
						commit
						b6cbe6c84a
					
				
					 2 changed files with 23 additions and 6 deletions
				
			
		
							
								
								
									
										12
									
								
								src/authd.cr
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								src/authd.cr
									
										
									
									
									
								
							|  | @ -220,11 +220,13 @@ class AuthD::Request | ||||||
| 	class ModUser < Request | 	class ModUser < Request | ||||||
| 		property shared_key : String | 		property shared_key : String | ||||||
| 
 | 
 | ||||||
| 		property uid        : Int32 | 		property user       : Int32 | String | ||||||
| 		property password   : String? | 		property password   : String? | ||||||
|  | 		property email      : String? | ||||||
|  | 		property phone      : String? | ||||||
| 		property avatar     : String? | 		property avatar     : String? | ||||||
| 
 | 
 | ||||||
| 		initialize :shared_key, :uid | 		initialize :shared_key, :user | ||||||
| 	end | 	end | ||||||
| 
 | 
 | ||||||
| 	class Request::Register < Request | 	class Request::Register < Request | ||||||
|  | @ -433,10 +435,12 @@ module AuthD | ||||||
| 			end | 			end | ||||||
| 		end | 		end | ||||||
| 
 | 
 | ||||||
| 		def mod_user(uid : Int32, password : String? = nil, avatar : String? = nil) : Bool | Exception | 		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 | 			request = Request::ModUser.new @key, uid_or_login | ||||||
| 
 | 
 | ||||||
| 			request.password = password if password | 			request.password = password if password | ||||||
|  | 			request.email    = email    if email | ||||||
|  | 			request.phone    = phone    if phone | ||||||
| 			request.avatar   = avatar   if avatar | 			request.avatar   = avatar   if avatar | ||||||
| 
 | 
 | ||||||
| 			send request | 			send request | ||||||
|  |  | ||||||
							
								
								
									
										17
									
								
								src/main.cr
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								src/main.cr
									
										
									
									
									
								
							|  | @ -148,7 +148,12 @@ class AuthD::Service | ||||||
| 				return Response::Error.new "invalid authentication key" | 				return Response::Error.new "invalid authentication key" | ||||||
| 			end | 			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 | 			unless user | ||||||
| 				return Response::Error.new "user not found" | 				return Response::Error.new "user not found" | ||||||
|  | @ -158,9 +163,17 @@ class AuthD::Service | ||||||
| 				user.password_hash = hash_password s | 				user.password_hash = hash_password s | ||||||
| 			end | 			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 | 			@users_per_uid.update user.uid.to_s, user | ||||||
| 
 | 
 | ||||||
| 			Response::UserEdited.new request.uid | 			Response::UserEdited.new user.uid | ||||||
| 		when Request::Register | 		when Request::Register | ||||||
| 			if ! @registrations_allowed | 			if ! @registrations_allowed | ||||||
| 				return Response::Error.new "registrations not allowed" | 				return Response::Error.new "registrations not allowed" | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Philippe PITTOLI
						Philippe PITTOLI