From ce598d00cd2e38e4433d33baebc8d5d7f984b2d2 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Wed, 24 Sep 2014 09:47:57 -0400
Subject: [PATCH] Support for password change through ChoiceAuth.

---
 module/VuFind/src/VuFind/Auth/ChoiceAuth.php  | 35 +++++++++++++++++++
 module/VuFind/src/VuFind/Auth/Manager.php     | 16 +++++++--
 .../src/VuFind/View/Helper/Root/Auth.php      |  2 +-
 3 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/module/VuFind/src/VuFind/Auth/ChoiceAuth.php b/module/VuFind/src/VuFind/Auth/ChoiceAuth.php
index 9882c9961b3..c184bcda380 100644
--- a/module/VuFind/src/VuFind/Auth/ChoiceAuth.php
+++ b/module/VuFind/src/VuFind/Auth/ChoiceAuth.php
@@ -202,6 +202,17 @@ class ChoiceAuth extends AbstractBase
         return $this->strategies;
     }
 
+    /**
+     * If an authentication strategy has been selected, return the active option.
+     * If not, return false.
+     *
+     * @return bool|string
+     */
+    public function getSelectedAuthOption()
+    {
+        return $this->strategy;
+    }
+
     /**
      * Perform cleanup at logout time.
      *
@@ -237,6 +248,30 @@ class ChoiceAuth extends AbstractBase
         return $this->proxyAuthMethod('getSessionInitiator', func_get_args());
     }
 
+    /**
+     * Does this authentication method support password changing
+     *
+     * @return bool
+     */
+    public function supportsPasswordChange()
+    {
+        return $this->proxyAuthMethod('supportsPasswordChange', func_get_args());
+    }
+
+    /**
+     * Update a user's password 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 updatePassword($request)
+    {
+        return $this->proxyAuthMethod('updatePassword', func_get_args());
+    }
+
     /**
      * Proxy auth method; a helper function to be called like:
      *   return $this->proxyAuthMethod(METHOD, func_get_args());
diff --git a/module/VuFind/src/VuFind/Auth/Manager.php b/module/VuFind/src/VuFind/Auth/Manager.php
index 573bd6fa755..6c328692261 100644
--- a/module/VuFind/src/VuFind/Auth/Manager.php
+++ b/module/VuFind/src/VuFind/Auth/Manager.php
@@ -209,13 +209,23 @@ class Manager
     }
 
     /**
-     * Get the name of the current authentication class.
+     * In VuFind, views are tied to the name of the active authentication class.
+     * This method returns that name so that an appropriate template can be
+     * selected. It supports authentication methods that proxy other authentication
+     * methods (see ChoiceAuth for an example).
      *
      * @return string
      */
-    public function getAuthClass()
+    public function getAuthClassForTemplateRendering()
     {
-        return get_class($this->getAuth());
+        $auth = $this->getAuth();
+        if (is_callable(array($auth, 'getSelectedAuthOption'))) {
+            $selected = $auth->getSelectedAuthOption();
+            if ($selected) {
+                $auth = $this->getAuth($selected);
+            }
+        }
+        return get_class($auth);
     }
 
     /**
diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Auth.php b/module/VuFind/src/VuFind/View/Helper/Root/Auth.php
index 92c96f6c57d..588740ff582 100644
--- a/module/VuFind/src/VuFind/View/Helper/Root/Auth.php
+++ b/module/VuFind/src/VuFind/View/Helper/Root/Auth.php
@@ -73,7 +73,7 @@ class Auth extends \Zend\View\Helper\AbstractHelper
         // Get the current auth module's class name, then start a loop
         // in case we need to use a parent class' name to find the appropriate
         // template.
-        $className = $this->getManager()->getAuthClass();
+        $className = $this->getManager()->getAuthClassForTemplateRendering();
         $topClassName = $className; // for error message
         while (true) {
             // Guess the template name for the current class:
-- 
GitLab