From dca614de1560a332630e257c6eb0738a4e41a18c Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Wed, 10 Oct 2012 10:09:00 -0400
Subject: [PATCH] Resolving VUFIND-695 (Stay on current page when logging
 in/out).

---
 .../src/VuFind/Controller/MyResearchController.php    | 11 ++++++++++-
 .../VuFind/src/VuFind/Controller/Plugin/Followup.php  |  9 ++++++---
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php
index 5bc0556e7b9..2af194976a4 100644
--- a/module/VuFind/src/VuFind/Controller/MyResearchController.php
+++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php
@@ -66,6 +66,10 @@ class MyResearchController extends AbstractBase
 
         // Not logged in?  Force user to log in:
         if (!$this->getAuthManager()->isLoggedIn()) {
+            $this->followup()->store(
+                array(),
+                $this->getRequest()->getServer()->get('HTTP_REFERER')
+            );
             return $this->forwardTo('MyResearch', 'Login');
         }
 
@@ -165,8 +169,13 @@ class MyResearchController extends AbstractBase
      */
     public function logoutAction()
     {
+        $logoutTarget = $this->getRequest()->getServer()->get('HTTP_REFERER');
+        if (empty($logoutTarget)) {
+            $logoutTarget = $this->getServerUrl('home');
+        }
+
         return $this->redirect()
-            ->toUrl($this->getAuthManager()->logout($this->getServerUrl('home')));
+            ->toUrl($this->getAuthManager()->logout($logoutTarget));
     }
 
     /**
diff --git a/module/VuFind/src/VuFind/Controller/Plugin/Followup.php b/module/VuFind/src/VuFind/Controller/Plugin/Followup.php
index e4378db93fa..d2d79771b12 100644
--- a/module/VuFind/src/VuFind/Controller/Plugin/Followup.php
+++ b/module/VuFind/src/VuFind/Controller/Plugin/Followup.php
@@ -64,14 +64,17 @@ class Followup extends AbstractPlugin
      * Store the current URL (and optional additional information) in the session
      * for use following a successful login.
      *
-     * @param array $extras Associative array of extra fields to store.
+     * @param array  $extras      Associative array of extra fields to store.
+     * @param string $overrideUrl URL to store in place of current server URL (null
+     * for no override)
      *
      * @return void
      */
-    public function store($extras = array())
+    public function store($extras = array(), $overrideUrl = null)
     {
         // Store the current URL:
-        $this->session->url = $this->getController()->getServerUrl();
+        $this->session->url = !empty($overrideUrl)
+            ? $overrideUrl : $this->getController()->getServerUrl();
 
         // Store the extra parameters:
         foreach ($extras as $key => $value) {
-- 
GitLab