Skip to content
Snippets Groups Projects
Commit 51037adc authored by Demian Katz's avatar Demian Katz
Browse files

Run account creation through ChoiceAuth when appropriate.

- Resolves VUFIND-1011.
parent ce598d00
No related merge requests found
......@@ -31,7 +31,7 @@ use VuFind\Exception\Auth as AuthException;
/**
* ChoiceAuth Authentication plugin
*
* This module enables a user to choose between two authentication methods.
* This module enables a user to choose between two authentication methods.
* choices are presented side-by-side and one is manually selected.
*
* See config.ini for more details
......@@ -51,7 +51,7 @@ class ChoiceAuth extends AbstractBase
*/
protected $strategies = array();
/**
/**
* Auth strategy selected by user
*
* @var string
......@@ -89,7 +89,7 @@ class ChoiceAuth extends AbstractBase
/**
* Constructor
*/
public function __construct()
public function __construct()
{
// Set up session container and load cached strategy (if found):
$this->session = new \Zend\Session\Container('ChoiceAuth');
......@@ -143,20 +143,11 @@ class ChoiceAuth extends AbstractBase
* @throws AuthException
* @return \VuFind\Db\Row\User Object representing logged-in user.
*/
public function authenticate($request)
public function authenticate($request)
{
$this->username = trim($request->getPost()->get('username'));
$this->password = trim($request->getPost()->get('password'));
// Set new strategy; fall back to old one if there is a problem:
$defaultStrategy = $this->strategy;
$this->strategy = trim($request->getPost()->get('auth_method'));
if ($this->strategy == '') {
$this->strategy = $defaultStrategy;
if (empty($this->strategy)) {
throw new AuthException('authentication_error_technical');
}
}
$this->setStrategyFromRequest($request);
// Do the actual authentication work:
$user = $this->proxyAuthMethod('authenticate', func_get_args());
......@@ -166,6 +157,25 @@ class ChoiceAuth extends AbstractBase
return $user;
}
/**
* Create a new user account from the request.
*
* @param \Zend\Http\PhpEnvironment\Request $request Request object containing
* new account details.
*
* @throws AuthException
* @return \VuFind\Db\Row\User New user row.
*/
public function create($request)
{
$this->setStrategyFromRequest($request);
$user = $this->proxyAuthMethod('create', func_get_args());
if ($user) {
$this->session->auth_method = $this->strategy;
}
return $user;
}
/**
* Set the manager for loading other authentication plugins.
*
......@@ -298,4 +308,27 @@ class ChoiceAuth extends AbstractBase
return call_user_func_array(array($authenticator, $method), $params);
}
/**
* Set the active strategy based on the auth_method value in the request,
* if found.
*
* @param \Zend\Http\PhpEnvironment\Request $request Request object to check.
*
* @return void
*/
protected function setStrategyFromRequest($request)
{
// Set new strategy; fall back to old one if there is a problem:
$defaultStrategy = $this->strategy;
$this->strategy = trim($request->getPost()->get('auth_method'));
if (null === $this->strategy) {
$this->strategy = trim($request->getQuery()->get('auth_method'));
}
if ($this->strategy == '') {
$this->strategy = $defaultStrategy;
if (empty($this->strategy)) {
throw new AuthException('authentication_error_technical');
}
}
}
}
......@@ -145,8 +145,8 @@ class MyResearchController extends AbstractBase
}
// If authentication mechanism does not support account creation, send
// the user away!
$this->setUpAuthenticationFromRequest();
if (!$this->getAuthManager()->supportsCreation()) {
$method = trim($this->params()->fromQuery('auth_method'));
if (!$this->getAuthManager()->supportsCreation($method)) {
return $this->forwardTo('MyResearch', 'Home');
}
......@@ -173,6 +173,12 @@ class MyResearchController extends AbstractBase
$this->flashMessenger()->setNamespace('error')
->addMessage($e->getMessage());
}
} else {
// If we are not processing a submission, we need to simply display
// an empty form. In case ChoiceAuth is being used, we may need to
// override the active authentication method based on request
// parameters to ensure display of the appropriate template.
$this->setUpAuthenticationFromRequest();
}
return $view;
}
......
......@@ -16,3 +16,4 @@
<label class="span-3" for="account_password2"><?=$this->transEsc('Password Again')?>:</label>
<input id="account_password2" type="password" name="password2" size="15"
class="<?=$this->jqueryValidation(array('required'=>'This field is required', 'equalTo'=>'Passwords do not match', 'equalToField'=>'#account_password'))?>"/><br class="clear"/>
<input type="hidden" name="auth_method" value="<?=$this->auth()->getManager()->getAuthMethod()?>"/>
\ No newline at end of file
......@@ -34,3 +34,4 @@
<input id="account_password2" type="password" name="password2"/>
</div>
</div>
<input type="hidden" name="auth_method" value="<?=$this->auth()->getManager()->getAuthMethod()?>"/>
\ No newline at end of file
......@@ -34,3 +34,4 @@
<input id="account_password2" type="password" name="password2" class="form-control"/>
</div>
</div>
<input type="hidden" name="auth_method" value="<?=$this->auth()->getManager()->getAuthMethod()?>"/>
\ No newline at end of file
......@@ -10,3 +10,4 @@
<input id="account_password" type="password" name="password" />
<label for="account_password2"><?=$this->transEsc('Password Again')?>:</label>
<input id="account_password2" type="password" name="password2" />
<input type="hidden" name="auth_method" value="<?=$this->auth()->getManager()->getAuthMethod()?>"/>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment