diff options
Diffstat (limited to 'app/php/user')
-rw-r--r-- | app/php/user/DbUser.php | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/app/php/user/DbUser.php b/app/php/user/DbUser.php new file mode 100644 index 0000000..e864bc0 --- /dev/null +++ b/app/php/user/DbUser.php @@ -0,0 +1,55 @@ +<?php + +Prado::using('System.Security.TDbUserManager'); +Prado::using('Application.model.User'); + +class DbUser extends TDbUser { + + private $_record; + + public function setDbRecord(User $record) { + $this->_record = $record; + } + + public function getDbRecord() { + return $this->_record; + } + + public function createUser($username) { + $dbUser = User::finder()->findByLogin($username); + if (!$dbUser) { + return NULL; + } + $user = new DbUser($this->Manager); + $user->DbRecord = $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 (password_verify($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'); + } + +} + +?> |