summaryrefslogtreecommitdiff
path: root/app/frontend/user/DbUser.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/frontend/user/DbUser.php')
-rw-r--r--app/frontend/user/DbUser.php60
1 files changed, 60 insertions, 0 deletions
diff --git a/app/frontend/user/DbUser.php b/app/frontend/user/DbUser.php
new file mode 100644
index 0000000..d636e8b
--- /dev/null
+++ b/app/frontend/user/DbUser.php
@@ -0,0 +1,60 @@
+<?php
+
+Prado::using('System.Security.TDbUserManager');
+Prado::using('Application.model.User');
+Prado::using('Application.facades.UserFacade');
+
+class DbUser extends TDbUser {
+
+ private $_record;
+
+ public function setDbRecord(User $record) {
+ $this->_record = $record;
+ }
+
+ public function getDbRecord() {
+ if (!$this->_record) {
+ $this->_record = UserFacade::getInstance()->findByLogin($this->Name);
+ }
+ return $this->_record;
+ }
+
+ public function createUser($username) {
+ $dbUser = UserFacade::getInstance()->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 = UserFacade::getInstance()->findByLogin($login);
+ $dbPassword = $user ? $user->Password : '';
+ if (UserFacade::getInstance()->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 = [];
+ if (preg_match('/^getIs(.+)$/', $name, $match)) {
+ return $this->isInRole($match[1]);
+ }
+ throw new Exception('Unimplemented CustomDbUser method');
+ }
+
+}
+
+?>