_record = $record; } public function getDbRecord() { if (!$this->_record) { $this->_record = User::finder()->findByLogin($this->Name); } return $this->_record; } public function createUser($username) { $dbUser = User::finder()->findByLogin($username); if (!$dbUser) { return NULL; } $user = new DbUser($this->Manager); $user->setDbRecord($dbUser); $user->Name = $dbUser->Login; if ($dbUser->IsAdmin) { $user->Roles = 'Admin'; } $user->IsGuest = FALSE; return $user; } public function validateUser($login, $password) { $user = User::finder()->findByLogin($login); $dbPassword = $user ? $user->Password : ''; if (self::verifyPassword($password, $dbPassword) && $user) { $user->LastLogin = date('Y-m-d H:i:s'); $user->save(); return TRUE; } else { return FALSE; } } public function __call($name, $args) { $match = array(); if (preg_match('/^getIs(.+)$/', $name, $match)) { return $this->isInRole($match[1]); } throw new Exception('Unimplemented CustomDbUser method'); } public function getCalendarPreference() { if ($this->IsGuest) { return Calendar::finder()->findAllByIsVisible(1); } else { return $this->DbRecord->Calendars; } } public static function generatePassword($password) { return password_hash($password, PASSWORD_DEFAULT); } public static function verifyPassword($password, $dbPassword) { return password_verify($password, $dbPassword); } } ?>