Skip to content

Commit

Permalink
build in authenticator hooks
Browse files Browse the repository at this point in the history
to be implemented in calling application
  • Loading branch information
gte451f committed Aug 20, 2015
1 parent e6e01c3 commit b12cb2f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/Authentication/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ interface AdapterInterface
{

/**
* each adapter mush provide a way to authenticate a user
* each adapter must provide a way to authenticate a user
*
* @param string $userName
* @param string $password
* @return boolean
Expand Down
42 changes: 41 additions & 1 deletion src/Authentication/Authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @author jjenkins
*
*/
final class Authenticator extends Injectable implements AuthenticatorInterface
class Authenticator extends Injectable implements AuthenticatorInterface
{

/**
Expand Down Expand Up @@ -70,9 +70,11 @@ public function isLoggedIn($token)
public function logUserOut($token)
{
$result = $this->isLoggedIn($token);
$this->beforeLogout($token);
if ($result) {
$result = $this->profile->resetToken(true);
}
$this->afterLogout($token, $result);
return $result;
}

Expand All @@ -86,11 +88,13 @@ public function logUserOut($token)
*/
public function authenticate($userName, $password)
{
$this->beforeLogin($userName, $password);
$result = $this->adapter->authenticate($userName, $password);
if ($result) {
$this->profile->loadProfile("$this->userNameFieldName = '$userName'");
$this->profile->resetToken();
}
$this->afterLogin($userName, $password, $result);
return $result;
}

Expand All @@ -104,4 +108,40 @@ function getProfile($userName = false)
{
return $this->profile;
}

/**
* hook to call before a login attempt
*
* @param string $userName
* @param string $password
*/
public function beforeLogin($userName, $password)
{}

/**
* hook to call after a login attempt
*
* @param string $userName
* @param string $password
*/
public function afterLogin($userName, $password, $result)
{}

/**
* hook to call before a logout attempt
*
* @param string $userName
* @param string $password
*/
public function beforeLogout($token)
{}

/**
* hook to call after a logout attempt
*
* @param string $userName
* @param string $password
*/
public function afterLogout($token, $result)
{}
}
5 changes: 2 additions & 3 deletions src/Authentication/AuthenticatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
*
*/
interface AuthenticatorInterface
{

// persiste to cache or session?
{
// persist to cache or session?
/**
* is the current user logged in?
Expand Down

0 comments on commit b12cb2f

Please sign in to comment.