diff options
author | emkael <emkael@tlen.pl> | 2016-03-09 15:04:31 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-03-09 15:04:31 +0100 |
commit | 58eeaba11f1abcccb947fa907c9eb23dc12a76f6 (patch) | |
tree | 89d8c78e6fbe5cfae3bf3e034481018b9e61d49b /app/php/user/DbUser.php | |
parent | cc974c9ba84353d41e3c23d253f0311e6a6f092f (diff) |
* user management
Diffstat (limited to 'app/php/user/DbUser.php')
-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'); + } + +} + +?> |