feat: use session instead of referer for redirects

This commit is contained in:
Michael Ciociola 2022-12-04 14:16:00 -06:00 committed by Michael
parent f9c5403529
commit 13bd448e01
3 changed files with 13 additions and 18 deletions

View file

@ -626,7 +626,7 @@ class ConfigController extends Controller
$em->persist($user); $em->persist($user);
$em->flush(); $em->flush();
return $this->redirect($request->headers->get('referer')); return $this->redirect($request->getSession()->get('prevUrl'));
} }
/** /**

View file

@ -110,9 +110,7 @@ class EntryController extends Controller
$em->flush(); $em->flush();
} }
$redirectUrl = $this->get(Redirect::class)->to($request->headers->get('referer')); return $this->redirect($this->get(Redirect::class)->to($request->getSession()->get('prevUrl')));
return $this->redirect($redirectUrl);
} }
/** /**
@ -379,6 +377,7 @@ class EntryController extends Controller
public function viewAction(Entry $entry) public function viewAction(Entry $entry)
{ {
$this->checkUserAction($entry); $this->checkUserAction($entry);
$this->get('session')->set('prevUrl', $this->generateUrl('view', ['id' => $entry->getId()]));
return $this->render( return $this->render(
'@WallabagCore/Entry/entry.html.twig', '@WallabagCore/Entry/entry.html.twig',
@ -443,9 +442,7 @@ class EntryController extends Controller
$message $message
); );
$redirectUrl = $this->get(Redirect::class)->to($request->headers->get('referer')); return $this->redirect($this->get(Redirect::class)->to($request->getSession()->get('prevUrl')));
return $this->redirect($redirectUrl);
} }
/** /**
@ -473,9 +470,7 @@ class EntryController extends Controller
$message $message
); );
$redirectUrl = $this->get(Redirect::class)->to($request->headers->get('referer')); return $this->redirect($this->get(Redirect::class)->to($request->getSession()->get('prevUrl')));
return $this->redirect($redirectUrl);
} }
/** /**
@ -509,10 +504,9 @@ class EntryController extends Controller
'flashes.entry.notice.entry_deleted' 'flashes.entry.notice.entry_deleted'
); );
// don't redirect user to the deleted entry (check that the referer doesn't end with the same url) // don't redirect user to the deleted entry
$referer = $request->headers->get('referer'); $prev = $request->getSession()->get('prevUrl');
$to = (1 !== preg_match('#' . $url . '$#i', $referer) ? $referer : null); $to = (1 !== preg_match('#' . $url . '$#i', $prev) ? $prev : null);
$redirectUrl = $this->get(Redirect::class)->to($to); $redirectUrl = $this->get(Redirect::class)->to($to);
return $this->redirect($redirectUrl); return $this->redirect($redirectUrl);
@ -612,6 +606,7 @@ class EntryController extends Controller
$repository = $this->get(EntryRepository::class); $repository = $this->get(EntryRepository::class);
$searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : ''); $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : '');
$currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : ''); $currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : '');
$request->getSession()->set('prevUrl', $request->getRequestUri());
$formOptions = []; $formOptions = [];

View file

@ -76,7 +76,7 @@ class TagController extends Controller
$em->flush(); $em->flush();
} }
$redirectUrl = $this->get(Redirect::class)->to($request->headers->get('referer'), '', true); $redirectUrl = $this->get(Redirect::class)->to($request->getSession()->get('prevUrl'), '', true);
return $this->redirect($redirectUrl); return $this->redirect($redirectUrl);
} }
@ -159,7 +159,7 @@ class TagController extends Controller
$form = $this->createForm(RenameTagType::class, new Tag()); $form = $this->createForm(RenameTagType::class, new Tag());
$form->handleRequest($request); $form->handleRequest($request);
$redirectUrl = $this->get(Redirect::class)->to($request->headers->get('referer'), '', true); $redirectUrl = $this->get(Redirect::class)->to($request->getSession()->get('prevUrl'), '', true);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$newTag = new Tag(); $newTag = new Tag();
@ -227,7 +227,7 @@ class TagController extends Controller
$em->flush(); $em->flush();
return $this->redirect($this->get(Redirect::class)->to($request->headers->get('referer'), '', true)); return $this->redirect($this->get(Redirect::class)->to($request->getSession()->get('prevUrl'), '', true));
} }
/** /**
@ -253,6 +253,6 @@ class TagController extends Controller
$redirectUrl = $this->get(Redirect::class)->to($request->headers->get('referer'), '', true); $redirectUrl = $this->get(Redirect::class)->to($request->headers->get('referer'), '', true);
return $this->redirect($redirectUrl); return $this->redirect($this->get(Redirect::class)->to($request->getSession()->get('prevUrl'), '', true));
} }
} }