UserID: from Int32 to UInt32.
This commit is contained in:
		
							parent
							
								
									c462bbafa1
								
							
						
					
					
						commit
						5ac733cbc3
					
				
					 10 changed files with 25 additions and 26 deletions
				
			
		|  | @ -10,8 +10,8 @@ require "ipc" | |||
| 
 | ||||
| require "baguette-crystal-base" | ||||
| 
 | ||||
| # In any message, a user can be referred by its Int32 uid or its login. | ||||
| alias UserID = Int32 | String | ||||
| # In any message, a user can be referred by its UInt32 uid or its login. | ||||
| alias UserID = UInt32 | String | ||||
| 
 | ||||
| # Allows get configuration from a provided file. | ||||
| # See Baguette::Configuration::Base.get | ||||
|  |  | |||
|  | @ -40,7 +40,7 @@ module AuthD | |||
| 			parse_message [Response::User], read | ||||
| 		end | ||||
| 
 | ||||
| 		def get_user?(uid_or_login : Int32 | String) | ||||
| 		def get_user?(uid_or_login : UserID) | ||||
| 			send_now Request::GetUser.new uid_or_login | ||||
| 			parse_message [Response::User], read | ||||
| 		end | ||||
|  | @ -84,12 +84,12 @@ module AuthD | |||
| 			parse_message [Response::UserValidated], read | ||||
| 		end | ||||
| 
 | ||||
| 		def ask_password_recovery(uid_or_login : String | Int32) | ||||
| 		def ask_password_recovery(uid_or_login : UserID) | ||||
| 			send_now Request::AskPasswordRecovery.new uid_or_login | ||||
| 			parse_message [Response::PasswordRecoverySent], read | ||||
| 		end | ||||
| 
 | ||||
| 		def change_password(uid_or_login : String | Int32, new_pass : String, renew_key : String) | ||||
| 		def change_password(uid_or_login : UserID, new_pass : String, renew_key : String) | ||||
| 			send_now Request::PasswordRecovery.new uid_or_login, renew_key, new_pass | ||||
| 			parse_message [Response::PasswordRecovered], read | ||||
| 		end | ||||
|  | @ -137,12 +137,12 @@ module AuthD | |||
| 			parse_message [Response::MatchingUsers], read | ||||
| 		end | ||||
| 
 | ||||
| 		def edit_profile_content(user : Int32 | String, new_values) | ||||
| 		def edit_profile_content(user : UserID, new_values) | ||||
| 			send_now Request::EditProfileEntries.new user, new_values | ||||
| 			parse_message [Response::User], read | ||||
| 		end | ||||
| 
 | ||||
| 		def delete(user : Int32 | String) | ||||
| 		def delete(user : UserID) | ||||
| 			send_now Request::Delete.new user | ||||
| 			parse_message [Response::UserDeleted], read | ||||
| 		end | ||||
|  |  | |||
|  | @ -4,7 +4,7 @@ class AuthD::Token | |||
| 	include JSON::Serializable | ||||
| 
 | ||||
| 	property login : String | ||||
| 	property uid   : Int32 | ||||
| 	property uid   : UInt32 | ||||
| 
 | ||||
| 	def initialize(@login, @uid) | ||||
| 	end | ||||
|  | @ -23,7 +23,7 @@ class AuthD::Token | |||
| 	def self.from_s(key, str) | ||||
| 		payload, meta = JWT.decode str, key, JWT::Algorithm::HS256 | ||||
| 
 | ||||
| 		self.new payload["login"].as_s, payload["uid"].as_i | ||||
| 		self.new payload["login"].as_s, payload["uid"].as_i64.to_u32 | ||||
| 	end | ||||
| end | ||||
| 
 | ||||
|  |  | |||
|  | @ -32,7 +32,7 @@ class AuthD::User | |||
| 
 | ||||
| 	# Public. | ||||
| 	property login         : String | ||||
| 	property uid           : Int32 | ||||
| 	property uid           : UInt32 | ||||
| 	property admin         : Bool = false | ||||
| 	property profile       : Hash(String, JSON::Any)? | ||||
| 
 | ||||
|  | @ -60,7 +60,7 @@ class AuthD::User | |||
| 		include JSON::Serializable | ||||
| 
 | ||||
| 		property login   : String | ||||
| 		property uid     : Int32 | ||||
| 		property uid     : UInt32 | ||||
| 		property admin   : Bool = false | ||||
| 		property profile : Hash(String, JSON::Any)? | ||||
| 
 | ||||
|  |  | |||
|  | @ -172,7 +172,7 @@ class Actions | |||
| 
 | ||||
| 	def user_deletion | ||||
| 		args = Context.args.not_nil! | ||||
| 		userid = args[0].to_i | ||||
| 		userid = args[0].to_u32 | ||||
| 
 | ||||
| 		res = authd.delete userid | ||||
| 
 | ||||
|  | @ -203,7 +203,7 @@ class Actions | |||
| 	def permission_check | ||||
| 		args = Context.args.not_nil! | ||||
| 		user, application, resource = args[0..2] | ||||
| 		res = @authd.check_permission user.to_i, application, resource | ||||
| 		res = @authd.check_permission user.to_u32, application, resource | ||||
| 		case res | ||||
| 		when Response::PermissionCheck | ||||
| 			s = res.service | ||||
|  | @ -218,7 +218,7 @@ class Actions | |||
| 		args = Context.args.not_nil! | ||||
| 		user, application, resource, permission = args[0..3] | ||||
| 		perm = AuthD::User::PermissionLevel.parse(permission) | ||||
| 		res = @authd.set_permission user.to_i, application, resource, perm | ||||
| 		res = @authd.set_permission user.to_u32, application, resource, perm | ||||
| 		case res | ||||
| 		when Response::PermissionSet | ||||
| 			s = res.service | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| class AuthD::Response | ||||
| 	IPC::JSON.message Contacts, 12 do | ||||
| 		property user : Int32 | ||||
| 		property user : UInt32 | ||||
| 		property email : String? = nil | ||||
| 		def initialize(@user, @email) | ||||
| 		end | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| class AuthD::Response | ||||
| 	IPC::JSON.message Login, 1 do | ||||
| 		property uid    : Int32 | ||||
| 		property uid    : UInt32 | ||||
| 		property token  : String | ||||
| 		def initialize(@token, @uid) | ||||
| 		end | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| class AuthD::Response | ||||
| 	IPC::JSON.message PermissionCheck, 7 do | ||||
| 		property user       : Int32 | ||||
| 		property user       : UInt32 | ||||
| 		property service    : String | ||||
| 		property resource   : String | ||||
| 		property permission : ::AuthD::User::PermissionLevel | ||||
|  | @ -10,7 +10,7 @@ class AuthD::Response | |||
| 	AuthD.responses << PermissionCheck | ||||
| 
 | ||||
| 	IPC::JSON.message PermissionSet, 8 do | ||||
| 		property user       : Int32 | ||||
| 		property user       : UInt32 | ||||
| 		property service    : String | ||||
| 		property resource   : String | ||||
| 		property permission : ::AuthD::User::PermissionLevel | ||||
|  |  | |||
|  | @ -14,7 +14,7 @@ class AuthD::Response | |||
| 	AuthD.responses << UserAdded | ||||
| 
 | ||||
| 	IPC::JSON.message UserEdited, 4 do | ||||
| 		property uid    : Int32 | ||||
| 		property uid    : UInt32 | ||||
| 		def initialize(@uid) | ||||
| 		end | ||||
| 	end | ||||
|  | @ -42,7 +42,7 @@ class AuthD::Response | |||
| 	AuthD.responses << MatchingUsers | ||||
| 
 | ||||
| 	IPC::JSON.message UserDeleted, 12 do | ||||
| 		property uid    : Int32 | ||||
| 		property uid    : UInt32 | ||||
| 		def initialize(@uid) | ||||
| 		end | ||||
| 	end | ||||
|  |  | |||
|  | @ -63,13 +63,12 @@ class AuthD::Service < IPC | |||
| 	# | ||||
| 	# WARNING: to record this new UID, new_uid_commit must be called. | ||||
| 	# WARNING: new_uid isn't thread safe. | ||||
| 	def new_uid | ||||
| 		begin | ||||
| 			uid = File.read(@last_uid_file).to_i | ||||
| 	def new_uid : UInt32 | ||||
| 		uid : UInt32 = begin | ||||
| 			File.read(@last_uid_file).to_u32 | ||||
| 		rescue | ||||
| 			uid = 999 | ||||
| 			999.to_u32 | ||||
| 		end | ||||
| 
 | ||||
| 		uid += 1 | ||||
| 	end | ||||
| 
 | ||||
|  | @ -92,7 +91,7 @@ class AuthD::Service < IPC | |||
| 	end | ||||
| 
 | ||||
| 	def user?(uid_or_login : UserID) | ||||
| 		if uid_or_login.is_a? Int32 | ||||
| 		if uid_or_login.is_a? UInt32 | ||||
| 			@users_per_uid.get? uid_or_login.to_s | ||||
| 		else | ||||
| 			@users_per_login.get? uid_or_login | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue