diff options
Diffstat (limited to 'app/php/facades/UserFacade.php')
-rw-r--r-- | app/php/facades/UserFacade.php | 78 |
1 files changed, 0 insertions, 78 deletions
diff --git a/app/php/facades/UserFacade.php b/app/php/facades/UserFacade.php deleted file mode 100644 index 1604a70..0000000 --- a/app/php/facades/UserFacade.php +++ /dev/null @@ -1,78 +0,0 @@ -<?php - -Prado::using('Application.facades.Facade'); -Prado::using('Application.user.DbUser'); -Prado::using('Application.model.User'); -Prado::using('Application.dto.TimezoneDTO'); - -class UserFacade extends Facade { - - public function findByLogin(string $login) { - return User::finder()->findByLogin($login); - } - - public function checkForUsername(string $login) { - return !User::finder()->count('login = ?', $login); - } - - public function registerUser(string $login, string $password, bool $admin) { - $transaction = $this->beginTransaction(); - try { - $newUser = new User(); - $newUser->Login = $login; - $newUser->Password = $this->generatePassword($password); - $newUser->IsAdmin = $admin; - $newUser->save(); - $this->raiseEvent('UserRegistered', $newUser); - $transaction->commit(); - return $newUser; - } catch (Exception $e) { - $transaction->rollback(); - throw $e; - } - } - - public function changePassword(DbUser $user, string $pass) { - if (!$user->IsGuest) { - $user->DbRecord->Password = $this->generatePassword($pass); - $user->DbRecord->save(); - } - } - - public function verifyUserPassword(string $password, DbUser $user) { - $dbPassword = $user->IsGuest ? '' : $user->DbRecord->Password; - return $this->verifyPassword($password, $dbPassword); - } - - public function generatePassword(string $password) { - return password_hash($password, PASSWORD_DEFAULT); - } - - public function verifyPassword(string $password, string $dbPassword) { - return password_verify($password, $dbPassword); - } - - public function setTimezonePreference(DbUser $user, string $timezone) { - if ($user->IsGuest) { - throw new TInvalidDataException( - Prado::localize( - '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()); - } - -} - -?> |