This repository has been archived by the owner on Nov 27, 2018. It is now read-only.
forked from MUNComputerScienceSociety/ABALookup
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Controllers refactored to use the API.
- Moved session handling into its own class. - A LOT of TODO comments added - Refactored the 3 controllers Due to the state of the codebase, I'm not sure if any of this works.
- Loading branch information
Showing
5 changed files
with
199 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace AbaLookup\Session; | ||
|
||
use Zend\Session\Container; | ||
|
||
/** | ||
* Wrapper class around Zend\Session\Container | ||
*/ | ||
class Session | ||
{ | ||
/** | ||
* 3 months in seconds | ||
*/ | ||
const SECONDS_3_MONTHS = 7884000; | ||
|
||
/** | ||
* Namespace and keys for the user | ||
*/ | ||
const USER_NAMESPACE = 'user'; | ||
const USER_KEY_ID = 'id'; | ||
|
||
/** | ||
* Sets the user ID for the session | ||
* | ||
* @param int $id The user ID. | ||
* @param bool $remember Whether to set an explicit TTL for the user session. | ||
* @return void | ||
*/ | ||
public static function setUserId($id, $remember = FALSE) | ||
{ | ||
$session = new Container(Session::SESSION_USER_NAMESPACE); | ||
$session->getManager() | ||
->getConfig() | ||
->setCookieHttpOnly(TRUE) // As per issue #87 | ||
->rememberMe((is_bool($remember) && $remember) ? Session::SECONDS_3_MONTHS : 0); | ||
$session->offsetSet(Session::SESSION_USER_KEY_ID, $id); | ||
} | ||
|
||
/** | ||
* @return int|NULL The ID of the user in session. | ||
*/ | ||
public static function getUserId() | ||
{ | ||
return (new Container(Session::SESSION_USER_NAMESPACE))->offsetGet(Session::SESSION_USER_ID_KEY); | ||
} | ||
|
||
/** | ||
* Unsets the user ID for the session | ||
* | ||
* @return void | ||
*/ | ||
public static function unsetUserId() | ||
{ | ||
(new Container(Session::SESSION_USER_NAMESPACE))->offsetUnset(Session::SESSION_USER_ID_KEY); | ||
} | ||
} |
Oops, something went wrong.