summaryrefslogtreecommitdiff
path: root/app/frontend/user
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-06-07 15:17:49 +0200
committeremkael <emkael@tlen.pl>2016-06-10 11:46:41 +0200
commit823d71ced9b4947b1a5a5ade7245d521ed490061 (patch)
treea9a6c7cb0de74ff705e8320c284de423a698f5b5 /app/frontend/user
parentdf401552aac363655ab8f056a6c910a7611954d6 (diff)
* renaming php directory
Diffstat (limited to 'app/frontend/user')
-rw-r--r--app/frontend/user/DbUser.php60
-rw-r--r--app/frontend/user/config.xml9
2 files changed, 69 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');
+ }
+
+}
+
+?>
diff --git a/app/frontend/user/config.xml b/app/frontend/user/config.xml
new file mode 100644
index 0000000..80027e5
--- /dev/null
+++ b/app/frontend/user/config.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <modules>
+ <module id="auth" class="System.Security.TAuthManager"
+ UserManager="users" LoginPage="Login" />
+ <module id="users" class="System.Security.TDbUserManager"
+ UserClass="Application.user.DbUser" />
+ </modules>
+</configuration>