summaryrefslogtreecommitdiff
path: root/app/frontend/user
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-10-25 18:59:02 +0200
committeremkael <emkael@tlen.pl>2016-10-25 18:59:02 +0200
commit7f15fb107344f5e876df6f053004415ea1759c70 (patch)
tree687955f48eacfa27a2e7f1375f7a24b311187df9 /app/frontend/user
parent95e5a74b0663e9110ea638dd5d809e9fd1541fa9 (diff)
* saving and restoring user data from cookie
Diffstat (limited to 'app/frontend/user')
-rw-r--r--app/frontend/user/DbUser.php36
-rw-r--r--app/frontend/user/config.xml3
2 files changed, 38 insertions, 1 deletions
diff --git a/app/frontend/user/DbUser.php b/app/frontend/user/DbUser.php
index d636e8b..e398cb0 100644
--- a/app/frontend/user/DbUser.php
+++ b/app/frontend/user/DbUser.php
@@ -19,6 +19,16 @@ class DbUser extends TDbUser {
return $this->_record;
}
+ private $_authKey;
+
+ public function setAuthKey($key) {
+ $this->_authKey = $key;
+ }
+
+ public function getAuthKey() {
+ return $this->_authKey;
+ }
+
public function createUser($username) {
$dbUser = UserFacade::getInstance()->findByLogin($username);
if (!$dbUser) {
@@ -47,6 +57,32 @@ class DbUser extends TDbUser {
}
}
+ public function createUserFromCookie($cookie) {
+ $userFacade = UserFacade::getInstance();
+ try {
+ $userData = $userFacade->getUserFromCookieData($cookie);
+ if ($userData) {
+ $user = $this->createUser($userData->User);
+ $user->AuthKey = $userData->Key;
+ return $user;
+ }
+ return NULL;
+ } catch (TInvalidDataException $e) {
+ return NULL;
+ }
+ return NULL;
+ }
+
+ public function saveUserToCookie($cookie) {
+ $userFacade = UserFacade::getInstance();
+ $authKey = $userFacade->createUserAuthKey($this);
+ if ($authKey) {
+ $cookieData = $userFacade->compileCookieData($authKey);
+ $cookie->setValue($cookieData);
+ $cookie->setExpire(4294967296); // 2**32
+ }
+ }
+
public function __call($name, $args) {
$match = [];
if (preg_match('/^getIs(.+)$/', $name, $match)) {
diff --git a/app/frontend/user/config.xml b/app/frontend/user/config.xml
index 80027e5..d4ca867 100644
--- a/app/frontend/user/config.xml
+++ b/app/frontend/user/config.xml
@@ -2,7 +2,8 @@
<configuration>
<modules>
<module id="auth" class="System.Security.TAuthManager"
- UserManager="users" LoginPage="Login" />
+ UserManager="users" LoginPage="Login"
+ AllowAutoLogin="true" />
<module id="users" class="System.Security.TDbUserManager"
UserClass="Application.user.DbUser" />
</modules>