Ignore:
Timestamp:
Nov 20, 2020, 12:08:12 AM (3 years ago)
Author:
chronos
Message:
  • Added: Static types added to almost all classes, methods and function. Supported by PHP 7.4.
  • Fixed: Various found code issues.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/User/UserModel.php

    r878 r887  
    2828class PasswordHash
    2929{
    30   function Hash($Password, $Salt)
     30  function Hash(string $Password, string $Salt): string
    3131  {
    3232    return sha1(sha1($Password).$Salt);
    3333  }
    3434
    35   function Verify($Password, $Salt, $StoredHash)
     35  function Verify(string $Password, string $Salt, string $StoredHash): bool
    3636  {
    3737    return $this->Hash($Password, $Salt) == $StoredHash;
    3838  }
    3939
    40   function GetSalt()
     40  function GetSalt(): string
    4141  {
    4242    mt_srand(microtime(true) * 100000 + memory_get_usage(true));
     
    4949class User extends Model
    5050{
    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)
    6160  {
    6261    parent::__construct($System);
     
    6665  }
    6766
    68   function Check()
     67  function Check(): void
    6968  {
    7069    $SID = session_id();
     
    117116    {
    118117      $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');
    120119    }
    121120    //$this->LoadPermission($this->User['Role']);
     
    125124  }
    126125
    127   function Register($Login, $Password, $Password2, $Email, $Name)
     126  function Register(string $Login, string $Password, string $Password2, string $Email, string $Name): string
    128127  {
    129128    if (($Email == '') || ($Login == '') || ($Password == '') || ($Password2 == '')  || ($Name == '')) $Result = DATA_MISSING;
     
    172171
    173172            $Result = USER_REGISTRATED;
    174             $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'NewRegistration', $Login);
     173            ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('User', 'NewRegistration', $Login);
    175174          }
    176175        }
     
    180179  }
    181180
    182   function RegisterConfirm($Id, $Hash)
     181  function RegisterConfirm(string $Id, string $Hash): string
    183182  {
    184183    $DbResult = $this->Database->select('User', 'Id, Login, Password', 'Id = '.$Id);
     
    191190        $this->Database->update('User', 'Id='.$Row['Id'], array('Locked' => 0));
    192191        $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='.
    194193          $Row['Login'].', Id='.$Row['Id']);
    195194      } else $Output = PASSWORDS_UNMATCHED;
     
    198197  }
    199198
    200   function Login($Login, $Password, $StayLogged = false)
     199  function Login(string $Login, string $Password, bool $StayLogged = false): string
    201200  {
    202201    if ($StayLogged) $StayLogged = 1; else $StayLogged = 0;
     
    228227        $Result = USER_LOGGED_IN;
    229228        $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()));
    231230      }
    232231    } else $Result = USER_NOT_REGISTRED;
     
    234233  }
    235234
    236   function Logout()
     235  function Logout(): string
    237236  {
    238237    $SID = session_id();
    239238    $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']);
    241240    $this->Check();
    242241    return USER_LOGGED_OUT;
     
    248247    $DbResult = $this->Database->select('UserRole', '*');
    249248    while ($DbRow = $DbResult->fetch_array())
     249    {
    250250      $this->Roles[] = $DbRow;
     251    }
    251252  }
    252253
     
    257258    if ($DbResult->num_rows > 0)
    258259    while ($DbRow = $DbResult->fetch_array())
     260    {
    259261      $this->User['Permission'][$DbRow['Operation']] = $DbRow;
    260   }
    261 
    262   function PermissionMatrix()
     262    }
     263  }
     264
     265  function PermissionMatrix(): array
    263266  {
    264267    $Result = array();
     
    274277  }
    275278
    276   function CheckGroupPermission($GroupId, $OperationId)
     279  function CheckGroupPermission(string $GroupId, string $OperationId): bool
    277280  {
    278281    $PermissionExists = false;
     
    322325  }
    323326
    324   function CheckPermission($Module, $Operation, $ItemType = '', $ItemIndex = 0)
     327  function CheckPermission(string $Module, string $Operation, string $ItemType = '', int $ItemIndex = 0): bool
    325328  {
    326329    // Get module id
     
    373376  }
    374377
    375   function PasswordRecoveryRequest($Login, $Email)
     378  function PasswordRecoveryRequest(string $Login, string $Email): string
    376379  {
    377380    $DbResult = $this->Database->select('User', 'Login, Name, Id, Email, Password', '`Login`="'.$Login.'" AND `Email`="'.$Email.'"');
     
    395398
    396399      $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);
    398401    } else $Output = USER_PASSWORD_RECOVERY_FAIL;
    399402    return $Output;
    400403  }
    401404
    402   function PasswordRecoveryConfirm($Id, $Hash, $NewPassword)
     405  function PasswordRecoveryConfirm(string $Id, string $Hash, string $NewPassword): string
    403406  {
    404407    $DbResult = $this->Database->select('User', 'Id, Login, Password', 'Id = '.$Id);
     
    414417          'Salt' => $Salt, 'Locked' => 0));
    415418        $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']);
    417420      } else $Output = PASSWORDS_UNMATCHED;
    418421    } else $Output = USER_NOT_FOUND;
     
    420423  }
    421424
    422   function CheckToken($Module, $Operation, $Token)
     425  function CheckToken(string $Module, string $Operation, string $Token): bool
    423426  {
    424427    $DbResult = $this->Database->select('APIToken', 'User', '`Token`="'.$Token.'"');
Note: See TracChangeset for help on using the changeset viewer.