Changeset 887 for trunk/Modules/User/UserModel.php
- Timestamp:
- Nov 20, 2020, 12:08:12 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/User/UserModel.php
r878 r887 28 28 class PasswordHash 29 29 { 30 function Hash( $Password, $Salt)30 function Hash(string $Password, string $Salt): string 31 31 { 32 32 return sha1(sha1($Password).$Salt); 33 33 } 34 34 35 function Verify( $Password, $Salt, $StoredHash)35 function Verify(string $Password, string $Salt, string $StoredHash): bool 36 36 { 37 37 return $this->Hash($Password, $Salt) == $StoredHash; 38 38 } 39 39 40 function GetSalt() 40 function GetSalt(): string 41 41 { 42 42 mt_srand(microtime(true) * 100000 + memory_get_usage(true)); … … 49 49 class User extends Model 50 50 { 51 var $Roles = array(); 52 var $User = array(); 53 var $OnlineStateTimeout; 54 var $PermissionCache = array(); 55 var $PermissionGroupCache = array(); 56 var $PermissionGroupCacheOp = array(); 57 /** @var Password */ 58 var $PasswordHash; 59 60 function __construct($System) 51 public array $Roles = array(); 52 public array $User = array(); 53 public int $OnlineStateTimeout; 54 public array $PermissionCache = array(); 55 public array $PermissionGroupCache = array(); 56 public array $PermissionGroupCacheOp = array(); 57 public PasswordHash $PasswordHash; 58 59 function __construct(System $System) 61 60 { 62 61 parent::__construct($System); … … 66 65 } 67 66 68 function Check() 67 function Check(): void 69 68 { 70 69 $SID = session_id(); … … 117 116 { 118 117 $this->Database->delete('UserOnline', 'Id='.$DbRow['Id']); 119 if ($DbRow['User'] != null) $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'Logout');118 if ($DbRow['User'] != null) ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('User', 'Logout'); 120 119 } 121 120 //$this->LoadPermission($this->User['Role']); … … 125 124 } 126 125 127 function Register( $Login, $Password, $Password2, $Email, $Name)126 function Register(string $Login, string $Password, string $Password2, string $Email, string $Name): string 128 127 { 129 128 if (($Email == '') || ($Login == '') || ($Password == '') || ($Password2 == '') || ($Name == '')) $Result = DATA_MISSING; … … 172 171 173 172 $Result = USER_REGISTRATED; 174 $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'NewRegistration', $Login);173 ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('User', 'NewRegistration', $Login); 175 174 } 176 175 } … … 180 179 } 181 180 182 function RegisterConfirm( $Id, $Hash)181 function RegisterConfirm(string $Id, string $Hash): string 183 182 { 184 183 $DbResult = $this->Database->select('User', 'Id, Login, Password', 'Id = '.$Id); … … 191 190 $this->Database->update('User', 'Id='.$Row['Id'], array('Locked' => 0)); 192 191 $Output = USER_REGISTRATION_CONFIRMED; 193 $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'RegisterConfirm', 'Login='.192 ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('User', 'RegisterConfirm', 'Login='. 194 193 $Row['Login'].', Id='.$Row['Id']); 195 194 } else $Output = PASSWORDS_UNMATCHED; … … 198 197 } 199 198 200 function Login( $Login, $Password, $StayLogged = false)199 function Login(string $Login, string $Password, bool $StayLogged = false): string 201 200 { 202 201 if ($StayLogged) $StayLogged = 1; else $StayLogged = 0; … … 228 227 $Result = USER_LOGGED_IN; 229 228 $this->Check(); 230 $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'Login', 'Login='.$Login.',Host='.gethostbyaddr(GetRemoteAddress()));229 ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('User', 'Login', 'Login='.$Login.',Host='.gethostbyaddr(GetRemoteAddress())); 231 230 } 232 231 } else $Result = USER_NOT_REGISTRED; … … 234 233 } 235 234 236 function Logout() 235 function Logout(): string 237 236 { 238 237 $SID = session_id(); 239 238 $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('User' => null)); 240 $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'Logout', $this->User['Login']);239 ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('User', 'Logout', $this->User['Login']); 241 240 $this->Check(); 242 241 return USER_LOGGED_OUT; … … 248 247 $DbResult = $this->Database->select('UserRole', '*'); 249 248 while ($DbRow = $DbResult->fetch_array()) 249 { 250 250 $this->Roles[] = $DbRow; 251 } 251 252 } 252 253 … … 257 258 if ($DbResult->num_rows > 0) 258 259 while ($DbRow = $DbResult->fetch_array()) 260 { 259 261 $this->User['Permission'][$DbRow['Operation']] = $DbRow; 260 } 261 262 function PermissionMatrix() 262 } 263 } 264 265 function PermissionMatrix(): array 263 266 { 264 267 $Result = array(); … … 274 277 } 275 278 276 function CheckGroupPermission( $GroupId, $OperationId)279 function CheckGroupPermission(string $GroupId, string $OperationId): bool 277 280 { 278 281 $PermissionExists = false; … … 322 325 } 323 326 324 function CheckPermission( $Module, $Operation, $ItemType = '', $ItemIndex = 0)327 function CheckPermission(string $Module, string $Operation, string $ItemType = '', int $ItemIndex = 0): bool 325 328 { 326 329 // Get module id … … 373 376 } 374 377 375 function PasswordRecoveryRequest( $Login, $Email)378 function PasswordRecoveryRequest(string $Login, string $Email): string 376 379 { 377 380 $DbResult = $this->Database->select('User', 'Login, Name, Id, Email, Password', '`Login`="'.$Login.'" AND `Email`="'.$Email.'"'); … … 395 398 396 399 $Output = USER_PASSWORD_RECOVERY_SUCCESS; 397 $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'PasswordRecoveryRequest', 'Login='.$Login.',Email='.$Email);400 ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('User', 'PasswordRecoveryRequest', 'Login='.$Login.',Email='.$Email); 398 401 } else $Output = USER_PASSWORD_RECOVERY_FAIL; 399 402 return $Output; 400 403 } 401 404 402 function PasswordRecoveryConfirm( $Id, $Hash, $NewPassword)405 function PasswordRecoveryConfirm(string $Id, string $Hash, string $NewPassword): string 403 406 { 404 407 $DbResult = $this->Database->select('User', 'Id, Login, Password', 'Id = '.$Id); … … 414 417 'Salt' => $Salt, 'Locked' => 0)); 415 418 $Output = USER_PASSWORD_RECOVERY_CONFIRMED; 416 $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'PasswordRecoveryConfirm', 'Login='.$Row['Login']);419 ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('User', 'PasswordRecoveryConfirm', 'Login='.$Row['Login']); 417 420 } else $Output = PASSWORDS_UNMATCHED; 418 421 } else $Output = USER_NOT_FOUND; … … 420 423 } 421 424 422 function CheckToken( $Module, $Operation, $Token)425 function CheckToken(string $Module, string $Operation, string $Token): bool 423 426 { 424 427 $DbResult = $this->Database->select('APIToken', 'User', '`Token`="'.$Token.'"');
Note:
See TracChangeset
for help on using the changeset viewer.