diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php index 815f0bae5f565e04660ffea3d0987ead71c076e3..4e2d8e5fb08e14b62db1521e2c822409a4c2675a 100644 --- a/module/VuFind/src/VuFind/Controller/MyResearchController.php +++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php @@ -47,6 +47,30 @@ use Zend\View\Model\ViewModel; */ class MyResearchController extends AbstractBase { + /** + * Are we currently in a lightbox context? + * + * @return bool + */ + protected function inLightbox() + { + return $this->getRequest()->getQuery('layout', 'no') === 'lightbox' + || 'layout/lightbox' == $this->layout()->getTemplate(); + } + + /** + * Construct an HTTP 205 (refresh) response. Useful for reporting success + * in the lightbox without actually rendering content. + * + * @return \Zend\Http\Response + */ + protected function getRefreshResponse() + { + $response = $this->getResponse(); + $response->setStatusCode(205); + return $response; + } + /** * Process an authentication error. * @@ -128,6 +152,14 @@ class MyResearchController extends AbstractBase try { if (!$this->getAuthManager()->isLoggedIn()) { $this->getAuthManager()->login($this->getRequest()); + // Return early to avoid unnecessary processing if we are being + // called from login lightbox and don't have a followup action. + if ($this->params()->fromPost('processLogin') + && $this->inLightbox() + && empty($this->getFollowupUrl()) + ) { + return $this->getRefreshResponse(); + } } } catch (AuthException $e) { $this->processAuthenticationException($e); @@ -258,15 +290,9 @@ class MyResearchController extends AbstractBase { // Don't log in if already logged in! if ($this->getAuthManager()->isLoggedIn()) { - // inLightbox (only instance) - if ($this->getRequest()->getQuery('layout', 'no') === 'lightbox' - || 'layout/lightbox' == $this->layout()->getTemplate() - ) { - $response = $this->getResponse(); - $response->setStatusCode(205); - return $response; - } - return $this->redirect()->toRoute('home'); + return $this->inLightbox() // different behavior for lightbox context + ? $this->getRefreshResponse() + : $this->redirect()->toRoute('home'); } $this->clearFollowupUrl(); $this->setFollowupUrlToReferer();