aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/legacy/LegacyController.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/legacy/LegacyController.php')
-rw-r--r--application/legacy/LegacyController.php44
1 files changed, 38 insertions, 6 deletions
diff --git a/application/legacy/LegacyController.php b/application/legacy/LegacyController.php
index 26465d2c..826604e7 100644
--- a/application/legacy/LegacyController.php
+++ b/application/legacy/LegacyController.php
@@ -39,29 +39,44 @@ class LegacyController extends ShaarliVisitorController
39 /** Legacy route: ?post= */ 39 /** Legacy route: ?post= */
40 public function post(Request $request, Response $response): Response 40 public function post(Request $request, Response $response): Response
41 { 41 {
42 $parameters = count($request->getQueryParams()) > 0 ? '?' . http_build_query($request->getQueryParams()) : ''; 42 $route = '/admin/shaare';
43 $buildParameters = function (?array $parameters, bool $encode) {
44 if ($encode) {
45 $parameters = array_map('urlencode', $parameters);
46 }
47
48 return count($parameters) > 0 ? '?' . http_build_query($parameters) : '';
49 };
50
43 51
44 if (!$this->container->loginManager->isLoggedIn()) { 52 if (!$this->container->loginManager->isLoggedIn()) {
45 return $this->redirect($response, '/login' . $parameters); 53 $parameters = $buildParameters($request->getQueryParams(), true);
54 return $this->redirect($response, '/login?returnurl='. $this->getBasePath() . $route . $parameters);
46 } 55 }
47 56
48 return $this->redirect($response, '/admin/shaare' . $parameters); 57 $parameters = $buildParameters($request->getQueryParams(), false);
58
59 return $this->redirect($response, $route . $parameters);
49 } 60 }
50 61
51 /** Legacy route: ?addlink= */ 62 /** Legacy route: ?addlink= */
52 protected function addlink(Request $request, Response $response): Response 63 protected function addlink(Request $request, Response $response): Response
53 { 64 {
65 $route = '/admin/add-shaare';
66
54 if (!$this->container->loginManager->isLoggedIn()) { 67 if (!$this->container->loginManager->isLoggedIn()) {
55 return $this->redirect($response, '/login'); 68 return $this->redirect($response, '/login?returnurl=' . $this->getBasePath() . $route);
56 } 69 }
57 70
58 return $this->redirect($response, '/admin/add-shaare'); 71 return $this->redirect($response, $route);
59 } 72 }
60 73
61 /** Legacy route: ?do=login */ 74 /** Legacy route: ?do=login */
62 protected function login(Request $request, Response $response): Response 75 protected function login(Request $request, Response $response): Response
63 { 76 {
64 return $this->redirect($response, '/login'); 77 $returnUrl = $request->getQueryParam('returnurl');
78
79 return $this->redirect($response, '/login' . ($returnUrl ? '?returnurl=' . $returnUrl : ''));
65 } 80 }
66 81
67 /** Legacy route: ?do=logout */ 82 /** Legacy route: ?do=logout */
@@ -127,4 +142,21 @@ class LegacyController extends ShaarliVisitorController
127 142
128 return $this->redirect($response, '/feed/' . $feedType . $parameters); 143 return $this->redirect($response, '/feed/' . $feedType . $parameters);
129 } 144 }
145
146 /** Legacy route: ?do=configure */
147 protected function configure(Request $request, Response $response): Response
148 {
149 $route = '/admin/configure';
150
151 if (!$this->container->loginManager->isLoggedIn()) {
152 return $this->redirect($response, '/login?returnurl=' . $this->getBasePath() . $route);
153 }
154
155 return $this->redirect($response, $route);
156 }
157
158 protected function getBasePath(): string
159 {
160 return $this->container->basePath ?: '';
161 }
130} 162}