Skip to content
Snippets Groups Projects
Commit 680d96d0 authored by Peter Rotich's avatar Peter Rotich
Browse files

Provide facility to get the auth backend for the authenticated user

Reafactor logOut to use the piggyback on auth backend
parent 4d1eb53c
No related branches found
No related tags found
No related merge requests found
...@@ -11,8 +11,11 @@ abstract class AuthenticatedUser { ...@@ -11,8 +11,11 @@ abstract class AuthenticatedUser {
abstract function getId(); abstract function getId();
abstract function getUsername(); abstract function getUsername();
abstract function getRole(); abstract function getRole();
abstract function logOut();
//Backend used to authenticate the user
abstract function getAuthBackend();
//Authentication key
function setAuthKey($key) { function setAuthKey($key) {
$this->authkey = $key; $this->authkey = $key;
} }
...@@ -20,6 +23,15 @@ abstract class AuthenticatedUser { ...@@ -20,6 +23,15 @@ abstract class AuthenticatedUser {
function getAuthKey() { function getAuthKey() {
return $this->authkey; return $this->authkey;
} }
// logOut the user
function logOut() {
if ($bk = $this->getAuthBackend())
return $bk->signOut($this);
return false;
}
} }
interface AuthDirectorySearch { interface AuthDirectorySearch {
...@@ -293,12 +305,15 @@ abstract class StaffAuthenticationBackend extends AuthenticationBackend { ...@@ -293,12 +305,15 @@ abstract class StaffAuthenticationBackend extends AuthenticationBackend {
return true; return true;
} }
/* Base signOut
*
* Backend should extend the signout and perform any additional signout
* it requires.
*/
static function signOut($staff) { static function signOut($staff) {
global $ost; global $ost;
list($id, $auth) = explode(':', $_SESSION['_auth']['staff']['key']);
//TODO: Lookup the backed and request logout..
$_SESSION['_auth']['staff'] = array(); $_SESSION['_auth']['staff'] = array();
$ost->logDebug('Staff logout', $ost->logDebug('Staff logout',
sprintf("%s logged out [%s]", sprintf("%s logged out [%s]",
...@@ -395,9 +410,6 @@ abstract class UserAuthenticationBackend extends AuthenticationBackend { ...@@ -395,9 +410,6 @@ abstract class UserAuthenticationBackend extends AuthenticationBackend {
static function signOut($user) { static function signOut($user) {
global $ost; global $ost;
list($id, $auth) = explode(':', $_SESSION['_auth']['user']['key']);
//TODO: Lookup the backed and request logout..
$_SESSION['_auth']['user'] = array(); $_SESSION['_auth']['user'] = array();
$ost->logDebug('User logout', $ost->logDebug('User logout',
sprintf("%s logged out [%s]", sprintf("%s logged out [%s]",
......
...@@ -179,8 +179,9 @@ class EndUser extends AuthenticatedUser { ...@@ -179,8 +179,9 @@ class EndUser extends AuthenticatedUser {
return $this->isOwner() ? 'owner' : 'collaborator'; return $this->isOwner() ? 'owner' : 'collaborator';
} }
function logOut() { function getAuthBackend() {
return UserAuthenticationBackend::signOut($this); list($authkey,) = explode(':', $this->getAuthKey());
return UserAuthenticationBackend::getBackend($authkey);
} }
function getTicketStats() { function getTicketStats() {
......
...@@ -105,8 +105,9 @@ class Staff extends AuthenticatedUser { ...@@ -105,8 +105,9 @@ class Staff extends AuthenticatedUser {
return 'staff'; return 'staff';
} }
function logOut() { function getAuthBackend() {
return StaffAuthenticationBackend::signOut($this); list($authkey, ) = explode(':', $this->getAuthKey());
return StaffAuthenticationBackend::getBackend($authkey);
} }
/*compares user password*/ /*compares user password*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment