Skip to content
Snippets Groups Projects
Commit 0dcf1954 authored by Anna Headley's avatar Anna Headley Committed by Demian Katz
Browse files

Consolidate followup logic in the AbstractBase Controller.

- Resolves VUFIND-1001.
parent 3a1a3572
No related merge requests found
...@@ -531,4 +531,87 @@ class AbstractBase extends AbstractActionController ...@@ -531,4 +531,87 @@ class AbstractBase extends AbstractActionController
$tagSetting = isset($config->Social->tags) ? $config->Social->tags : true; $tagSetting = isset($config->Social->tags) ? $config->Social->tags : true;
return $tagSetting && $tagSetting !== 'disabled'; return $tagSetting && $tagSetting !== 'disabled';
} }
/**
* Store a referer (if appropriate) to keep post-login redirect pointing
* to an appropriate location. This is used when the user clicks the
* log in link from an arbitrary page or when a password is mistyped;
* separate logic is used for storing followup information when VuFind
* forces the user to log in from another context.
*
* @return void
*/
protected function setFollowupUrlToReferer()
{
// Get the referer -- if it's empty, there's nothing to store!
$referer = $this->getRequest()->getServer()->get('HTTP_REFERER');
if (empty($referer)) {
return;
}
$refererNorm = $this->normalizeUrlForComparison($referer);
// If the referer lives outside of VuFind, don't store it! We only
// want internal post-login redirects.
$baseUrl = $this->getServerUrl('home');
$baseUrlNorm = $this->normalizeUrlForComparison($baseUrl);
if (0 !== strpos($refererNorm, $baseUrlNorm)) {
return;
}
// If the referer is the MyResearch/Home action, it probably means
// that the user is repeatedly mistyping their password. We should
// ignore this and instead rely on any previously stored referer.
$myResearchHomeUrl = $this->getServerUrl('myresearch-home');
$mrhuNorm = $this->normalizeUrlForComparison($myResearchHomeUrl);
if ($mrhuNorm === $refererNorm) {
return;
}
// If we got this far, we want to store the referer:
$this->followup()->store(array(), $referer);
}
/**
* Normalize the referer URL so that inconsistencies in protocol and trailing
* slashes do not break comparisons.
*
* @param string $url URL to normalize
*
* @return string
*/
protected function normalizeUrlForComparison($url)
{
$parts = explode('://', $url, 2);
return trim(end($parts), '/');
}
/**
* Retrieve a referer to keep post-login redirect pointing
* to an appropriate location.
* Unset the followup before returning.
*
* @return string
*/
protected function getFollowupUrl()
{
$followup = $this->followup()->retrieve();
// followups aren't used in lightboxes.
if (isset($followup->url) && !$this->inLightbox()) {
return $followup->url;
}
return '';
}
/**
* Sometimes we need to unset the followup to trigger default behaviors
*
* @return void
*/
protected function clearFollowupUrl()
{
$followup = $this->followup()->retrieve();
if (isset($followup->url)) {
unset($followup->url);
}
}
} }
...@@ -258,14 +258,9 @@ class AbstractRecord extends AbstractBase ...@@ -258,14 +258,9 @@ class AbstractRecord extends AbstractBase
$this->flashMessenger()->setNamespace('info') $this->flashMessenger()->setNamespace('info')
->addMessage('bulk_save_success'); ->addMessage('bulk_save_success');
// Grab the followup namespace so we know where to send the user next: // redirect to followup url saved in saveAction
$followup = new SessionContainer($this->searchClassId . 'SaveFollowup'); if ($url = $this->getFollowupUrl()) {
$url = isset($followup->url) ? (string)$followup->url : false; $this->clearFollowupUrl();
if (!empty($url)) {
// Clear followup URL in session -- we're done with it now:
unset($followup->url);
// Redirect!
return $this->redirect()->toUrl($url); return $this->redirect()->toUrl($url);
} }
...@@ -300,13 +295,15 @@ class AbstractRecord extends AbstractBase ...@@ -300,13 +295,15 @@ class AbstractRecord extends AbstractBase
// ProcessSave action (to get back to where we came from after saving). // ProcessSave action (to get back to where we came from after saving).
// We shouldn't save follow-up information if it points to the Save // We shouldn't save follow-up information if it points to the Save
// screen or the "create list" screen, as this causes confusing workflows; // screen or the "create list" screen, as this causes confusing workflows;
// in these cases, we will simply default to pushing the user to record view. // in these cases, we will simply push the user to record view
$followup = new SessionContainer($this->searchClassId . 'SaveFollowup'); // by unsetting the followup and relying on default behavior in processSave.
$referer = $this->getRequest()->getServer()->get('HTTP_REFERER'); $referer = $this->getRequest()->getServer()->get('HTTP_REFERER');
if (substr($referer, -5) != '/Save' if (substr($referer, -5) != '/Save'
&& stripos($referer, 'MyResearch/EditList/NEW') === false && stripos($referer, 'MyResearch/EditList/NEW') === false
) { ) {
$followup->url = $referer; $this->setFollowupUrlToReferer();
} else {
$this->clearFollowupUrl();
} }
// Retrieve the record driver: // Retrieve the record driver:
...@@ -684,4 +681,4 @@ class AbstractRecord extends AbstractBase ...@@ -684,4 +681,4 @@ class AbstractRecord extends AbstractBase
$view->setTemplate($ajax ? 'record/ajaxtab' : 'record/view'); $view->setTemplate($ajax ? 'record/ajaxtab' : 'record/view');
return $view; return $view;
} }
} }
\ No newline at end of file
...@@ -67,56 +67,14 @@ class MyResearchController extends AbstractBase ...@@ -67,56 +67,14 @@ class MyResearchController extends AbstractBase
} }
/** /**
* Store a referer (if appropriate) to keep post-login redirect pointing * Maintaining this method for backwards compatibility;
* to an appropriate location. This is used when the user clicks the * logic moved to parent and method re-named
* log in link from an arbitrary page or when a password is mistyped;
* separate logic is used for storing followup information when VuFind
* forces the user to log in from another context.
* *
* @return void * @return void
*/ */
protected function storeRefererForPostLoginRedirect() protected function storeRefererForPostLoginRedirect()
{ {
// Get the referer -- if it's empty, there's nothing to store! $this->setFollowupUrlToReferer();
$referer = $this->getRequest()->getServer()->get('HTTP_REFERER');
if (empty($referer)) {
return;
}
$refererNorm = $this->normalizeUrlForComparison($referer);
// If the referer lives outside of VuFind, don't store it! We only
// want internal post-login redirects.
$baseUrl = $this->getServerUrl('home');
$baseUrlNorm = $this->normalizeUrlForComparison($baseUrl);
if (0 !== strpos($refererNorm, $baseUrlNorm)) {
return;
}
// If the referer is the MyResearch/Home action, it probably means
// that the user is repeatedly mistyping their password. We should
// ignore this and instead rely on any previously stored referer.
$myResearchHomeUrl = $this->getServerUrl('myresearch-home');
$mrhuNorm = $this->normalizeUrlForComparison($myResearchHomeUrl);
if ($mrhuNorm === $refererNorm) {
return;
}
// If we got this far, we want to store the referer:
$this->followup()->store(array(), $referer);
}
/**
* Normalize the referer URL so that inconsistencies in protocol and trailing
* slashes do not break comparisons.
*
* @param string $url URL to normalize
*
* @return string
*/
protected function normalizeUrlForComparison($url)
{
$parts = explode('://', $url, 2);
return trim(end($parts), '/');
} }
/** /**
...@@ -148,16 +106,13 @@ class MyResearchController extends AbstractBase ...@@ -148,16 +106,13 @@ class MyResearchController extends AbstractBase
// Not logged in? Force user to log in: // Not logged in? Force user to log in:
if (!$this->getAuthManager()->isLoggedIn()) { if (!$this->getAuthManager()->isLoggedIn()) {
$this->storeRefererForPostLoginRedirect(); $this->setFollowupUrlToReferer();
return $this->forwardTo('MyResearch', 'Login'); return $this->forwardTo('MyResearch', 'Login');
} }
// Logged in? Forward user to followup action
// Logged in? Forward user to followup action (if set and not in lightbox)
// or default action (if no followup provided): // or default action (if no followup provided):
$followup = $this->followup()->retrieve(); if ($url = $this->getFollowupUrl()) {
if (isset($followup->url) && !$this->inLightbox()) { $this->clearFollowupUrl();
$url = $followup->url;
unset($followup->url);
return $this->redirect()->toUrl($url); return $this->redirect()->toUrl($url);
} }
...@@ -191,9 +146,9 @@ class MyResearchController extends AbstractBase ...@@ -191,9 +146,9 @@ class MyResearchController extends AbstractBase
// We may have come in from a lightbox. In this case, a prior module // We may have come in from a lightbox. In this case, a prior module
// will not have set the followup information. We should grab the referer // will not have set the followup information. We should grab the referer
// so the user doesn't get lost. // so the user doesn't get lost.
$followup = $this->followup()->retrieve(); // i.e. if there's already a followup url, keep it; otherwise set one.
if (!isset($followup->url)) { if (!$this->getFollowupUrl()) {
$followup->url = $this->getRequest()->getServer()->get('HTTP_REFERER'); $this->setFollowupUrlToReferer();
} }
// Make view // Make view
...@@ -260,11 +215,8 @@ class MyResearchController extends AbstractBase ...@@ -260,11 +215,8 @@ class MyResearchController extends AbstractBase
*/ */
public function userloginAction() public function userloginAction()
{ {
$followup = $this->followup()->retrieve(); $this->clearFollowupUrl();
if (isset($followup->url)) { $this->setFollowupUrlToReferer();
unset($followup->url);
}
$this->storeRefererForPostLoginRedirect();
if ($si = $this->getSessionInitiator()) { if ($si = $this->getSessionInitiator()) {
return $this->redirect()->toUrl($si); return $this->redirect()->toUrl($si);
} }
......
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