IsGuest) { throw new TInvalidDataException( 'Timezone preference change impossible for guest user' ); } $user->DbRecord->Timezone = $timezone; $user->DbRecord->save(); } public function getTimezonePreference(DbUser $user) { if (!$user->IsGuest) { try { return new TimezoneDTO($user->DbRecord->Timezone); } catch(Exception $e) {} } return new TimezoneDTO(date_default_timezone_get()); } public function checkForUsername($login) { return !User::finder()->countByLogin($login); } public function registerUser($login, $password, $admin) { $newUser = new User(); $newUser->Login = $login; $newUser->Password = $this->generatePassword($password); $newUser->IsAdmin = $admin; $newUser->save(); return $newUser; } public function changePassword(DbUser $user, $pass) { if (!$user->IsGuest) { $user->DbRecord->Password = $this->generatePassword($pass); $user->DbRecord->save(); } } public function verifyUserPassword($password, DbUser $user) { $dbPassword = $user->IsGuest ? '' : $user->DbRecord->Password; return $this->verifyPassword($password, $dbPassword); } public function generatePassword($password) { return password_hash($password, PASSWORD_DEFAULT); } public function verifyPassword($password, $dbPassword) { return password_verify($password, $dbPassword); } } ?>