diff --git a/module/VuFind/src/VuFind/Auth/ChoiceAuth.php b/module/VuFind/src/VuFind/Auth/ChoiceAuth.php index c184bcda38063c856d1861c36555130523ceacba..32316de1852f1113a2bbd629a99f8435c3309c91 100644 --- a/module/VuFind/src/VuFind/Auth/ChoiceAuth.php +++ b/module/VuFind/src/VuFind/Auth/ChoiceAuth.php @@ -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'); + } + } + } } diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php index a6623b55c7ee141dc9c64c8d5ef007be22958667..2baf0a1f2bcd699b2887e585c934f4ed580b0acc 100644 --- a/module/VuFind/src/VuFind/Controller/MyResearchController.php +++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php @@ -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; } diff --git a/themes/blueprint/templates/Auth/Database/create.phtml b/themes/blueprint/templates/Auth/Database/create.phtml index 340d5ae37d61dc2d9c97f9aa609e07ce3868dac1..0bd86692e4ade6ac787383a617ac8e1016e93a5f 100644 --- a/themes/blueprint/templates/Auth/Database/create.phtml +++ b/themes/blueprint/templates/Auth/Database/create.phtml @@ -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 diff --git a/themes/bootstrap/templates/Auth/Database/create.phtml b/themes/bootstrap/templates/Auth/Database/create.phtml index bf43e8bdbd378eb60f0a75f16dbb05bba975acd2..4c6e40137f6c48db3d64a693312776bdc8c6f1d5 100644 --- a/themes/bootstrap/templates/Auth/Database/create.phtml +++ b/themes/bootstrap/templates/Auth/Database/create.phtml @@ -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 diff --git a/themes/bootstrap3/templates/Auth/Database/create.phtml b/themes/bootstrap3/templates/Auth/Database/create.phtml index 0ea591691b592a3b66bf13a37d0838e39da3a460..d2ded90581c418ef7d36e7c731519fc959aa084b 100644 --- a/themes/bootstrap3/templates/Auth/Database/create.phtml +++ b/themes/bootstrap3/templates/Auth/Database/create.phtml @@ -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 diff --git a/themes/jquerymobile/templates/Auth/Database/create.phtml b/themes/jquerymobile/templates/Auth/Database/create.phtml index 1444efdd6c2bdc0250ab89e5ab40322b4c240a91..57ddcb5b750ac9cab28b2e213092977aa23b9e2d 100644 --- a/themes/jquerymobile/templates/Auth/Database/create.phtml +++ b/themes/jquerymobile/templates/Auth/Database/create.phtml @@ -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