From 58eeaba11f1abcccb947fa907c9eb23dc12a76f6 Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 9 Mar 2016 15:04:31 +0100 Subject: * user management --- app/php/user/DbUser.php | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 app/php/user/DbUser.php (limited to 'app/php/user/DbUser.php') 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 @@ +_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'); + } + +} + +?> -- cgit v1.2.3