Skip to content
Browse files

refactored UserStorage for easy extensibility

  • Loading branch information...
1 parent 576a98f commit e1357f651667c4c0b47c54d81b7fcb63627177e7 @juzna committed Jul 30, 2012
Showing with 26 additions and 3 deletions.
  1. +26 −3 Nette/Http/UserStorage.php
View
29 Nette/Http/UserStorage.php
@@ -186,15 +186,15 @@ protected function getSessionSection($need)
$this->sessionSection = $section = $this->sessionHandler->getSection('Nette.Http.UserStorage/' . $this->namespace);
- if (!$section->identity instanceof IIdentity || !is_bool($section->authenticated)) {
+ if (!$this->isSessionValid($section)) {
$section->remove();
}
if ($section->authenticated && $section->expireBrowser && !$section->browserCheck) { // check if browser was closed?
$section->reason = self::BROWSER_CLOSED;
$section->authenticated = FALSE;
if ($section->expireIdentity) {
- unset($section->identity);
+ $this->clearSession($section);
}
}
@@ -203,7 +203,7 @@ protected function getSessionSection($need)
$section->reason = self::INACTIVITY;
$section->authenticated = FALSE;
if ($section->expireIdentity) {
- unset($section->identity);
+ $this->clearSession($section);
}
}
$section->expireTime = time() + $section->expireDelta; // sliding expiration
@@ -217,4 +217,27 @@ protected function getSessionSection($need)
return $this->sessionSection;
}
+
+
+ /**
+ * Checks whether a session section stores valid user info
+ * (override to extend UserStorage easily)
+ * @return bool
+ */
+ protected function isSessionValid(SessionSection $section)
+ {
+ return $section->identity instanceof IIdentity && is_bool($section->authenticated);
+ }
+
+
+
+ /**
+ * Clears user info
+ * (override to extend UserStorage easily)
+ */
+ protected function clearSession(SessionSection $section)
+ {
+ unset($section->identity);
+ }
+
}

0 comments on commit e1357f6

Please sign in to comment.
Something went wrong with that request. Please try again.