From a43e887c380fc414121792658136a34051526b6a Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 6 May 2016 15:40:50 +0200 Subject: * DbUser refactored to use a facade --- app/php/facades/UserFacade.php | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 app/php/facades/UserFacade.php (limited to 'app/php/facades/UserFacade.php') diff --git a/app/php/facades/UserFacade.php b/app/php/facades/UserFacade.php new file mode 100644 index 0000000..696f77f --- /dev/null +++ b/app/php/facades/UserFacade.php @@ -0,0 +1,66 @@ +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); + } + + + +} + +?> -- cgit v1.2.3