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/user/DbUser.php | 64 +++---------------------------------------------- 1 file changed, 3 insertions(+), 61 deletions(-) (limited to 'app/php/user') diff --git a/app/php/user/DbUser.php b/app/php/user/DbUser.php index 7e6096c..ce4da4c 100644 --- a/app/php/user/DbUser.php +++ b/app/php/user/DbUser.php @@ -2,8 +2,7 @@ Prado::using('System.Security.TDbUserManager'); Prado::using('Application.model.User'); -Prado::using('Application.model.Calendar'); -Prado::using('Application.dto.TimezoneDTO'); +Prado::using('Application.facades.UserFacade'); class DbUser extends TDbUser { @@ -38,7 +37,8 @@ class DbUser extends TDbUser { public function validateUser($login, $password) { $user = User::finder()->findByLogin($login); $dbPassword = $user ? $user->Password : ''; - if (self::verifyPassword($password, $dbPassword) && $user) { + if (UserFacade::getInstance()->verifyPassword($password, $dbPassword) + && $user) { $user->LastLogin = date('Y-m-d H:i:s'); $user->save(); return TRUE; @@ -55,64 +55,6 @@ class DbUser extends TDbUser { throw new Exception('Unimplemented CustomDbUser method'); } - public function getCalendarPreference() { - if ($this->IsGuest) { - return Calendar::finder()->findAllByIsVisible(1); - } else { - return $this->DbRecord->Calendars; - } - } - - public function isCalendarPreferred($calendarID) { - return in_array( - $calendarID, - array_map( - function($calendar) { - return $calendar->UID; - }, - $this->getCalendarPreference() - ) - ); - } - - public function setTimezonePreference($timezone) { - if ($this->IsGuest) { - throw new TInvalidDataException('Timezone preference change impossible for guest user'); - } - $this->DbRecord->Timezone = $timezone; - $this->DbRecord->save(); - } - - public function getTimezonePreference() { - if (!$this->IsGuest) { - try { - return new TimezoneDTO($this->DbRecord->Timezone); - } catch(Exception $e) {} - } - return new TimezoneDTO(date_default_timezone_get()); - } - - public function changePassword($pass) { - if (!$this->IsGuest) { - $this->DbRecord->Password = self::generatePassword($pass); - $this->DbRecord->save(); - } - } - - public function getPassword() { - if (!$this->IsGuest) { - return $this->DbRecord->Password; - } - } - - public static function generatePassword($password) { - return password_hash($password, PASSWORD_DEFAULT); - } - - public static function verifyPassword($password, $dbPassword) { - return password_verify($password, $dbPassword); - } - } ?> -- cgit v1.2.3