Skip to content

Commit

Permalink
Fixed issue #9171 : Unable to subscribe to event
Browse files Browse the repository at this point in the history
Dev : Target not anymore needed for auth plugins events, every auth plugin knows if he has to process event
Dev : This way, auth events (i.e. afterLogout) can be processed also by other plugins
Dev : Method afterLoginFormSubmit can be in parent class (preventing code duplication)
  • Loading branch information
Aestu committed Dec 14, 2014
1 parent f5e4885 commit 3984edb
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 23 deletions.
4 changes: 2 additions & 2 deletions application/controllers/admin/authentication.php
Expand Up @@ -110,14 +110,14 @@ public function logout()

/* Adding beforeLogout event */
$beforeLogout = new PluginEvent('beforeLogout');
App()->getPluginManager()->dispatchEvent($beforeLogout, array($plugin));
App()->getPluginManager()->dispatchEvent($beforeLogout);

App()->user->logout();
App()->user->setFlash('loginmessage', gT('Logout successful.'));

/* Adding afterLogout event */
$event = new PluginEvent('afterLogout');
App()->getPluginManager()->dispatchEvent($event, array($plugin));
App()->getPluginManager()->dispatchEvent($event);

$this->getController()->redirect(array('/admin/authentication/sa/login'));
}
Expand Down
2 changes: 1 addition & 1 deletion application/core/LSUserIdentity.php
Expand Up @@ -66,7 +66,7 @@ public function authenticate() {
// Delegate actual authentication to plugin
$authEvent = new PluginEvent('newUserSession', $this);
$authEvent->set('identity', $this);
App()->getPluginManager()->dispatchEvent($authEvent, array($this->plugin));
App()->getPluginManager()->dispatchEvent($authEvent);
$pluginResult = $authEvent->get('result');
if ($pluginResult instanceof LSAuthResult) {
$result = $pluginResult;
Expand Down
17 changes: 7 additions & 10 deletions application/core/plugins/AuthLDAP/AuthLDAP.php
Expand Up @@ -108,16 +108,6 @@ public function newLoginForm()
->addContent(CHtml::tag('li', array(), "<label for='password'>" . gT("Password") . "</label><input name='password' id='password' type='password' size='40' maxlength='40' value='' />"));
}

public function afterLoginFormSubmit()
{
// Here we handle post data
$request = $this->api->getRequest();
if ($request->getIsPostRequest()) {
$this->setUsername( $request->getPost('user'));
$this->setPassword($request->getPost('password'));
}
}

/**
* Modified getPluginSettings since we have a select box that autosubmits
* and we only want to show the relevant options.
Expand Down Expand Up @@ -166,6 +156,13 @@ public function getPluginSettings($getValues = true)

public function newUserSession()
{
// Do nothing if this user is not Authdb type
$identity = $this->getEvent()->get('identity');
if ($identity->plugin != 'AuthLDAP')
{
return;
}

// Here we do the actual authentication
$username = $this->getUsername();
$password = $this->getPassword();
Expand Down
15 changes: 6 additions & 9 deletions application/core/plugins/Authdb/Authdb.php
Expand Up @@ -75,18 +75,15 @@ public function newLoginForm()
->addContent(CHtml::tag('li', array(), "<label for='password'>" . gT("Password") . "</label>".CHtml::passwordField('password',$sPassword,array('size'=>40,'maxlength'=>40))));
}

public function afterLoginFormSubmit()
public function newUserSession()
{
// Here we handle post data
$request = $this->api->getRequest();
if ($request->getIsPostRequest()) {
$this->setUsername( $request->getPost('user'));
$this->setPassword($request->getPost('password'));
// Do nothing if this user is not Authdb type
$identity = $this->getEvent()->get('identity');
if ($identity->plugin != 'Authdb')
{
return;
}
}

public function newUserSession()
{
// Here we do the actual authentication
$username = $this->getUsername();
$password = $this->getPassword();
Expand Down
7 changes: 7 additions & 0 deletions application/core/plugins/Authwebserver/Authwebserver.php
Expand Up @@ -72,6 +72,13 @@ public function beforeLogin()

public function newUserSession()
{
// Do nothing if this user is not Authdb type
$identity = $this->getEvent()->get('identity');
if ($identity->plugin != 'Authwebserver')
{
return;
}

/* @var $identity LSUserIdentity */
$sUser = $this->getUserName();

Expand Down
17 changes: 16 additions & 1 deletion application/libraries/PluginManager/AuthPluginBase.php
Expand Up @@ -34,7 +34,22 @@ protected function getUserName()
{
return $this->_username;
}


/**
* Set username and password
*
* @return null
*/
public function afterLoginFormSubmit()
{
// Here we handle post data
$request = $this->api->getRequest();
if ($request->getIsPostRequest()) {
$this->setUsername( $request->getPost('user'));
$this->setPassword($request->getPost('password'));
}
}

/**
* Set authentication result to success for the given user object.
*
Expand Down

0 comments on commit 3984edb

Please sign in to comment.