RVRNEXT-2 fix redirect after login
This commit is contained in:
parent
e4dc8ace04
commit
364d55a4b2
@ -27,21 +27,27 @@ class LoginController
|
||||
|
||||
private UserPasswordResetterRepository $userPasswordResetterRepository;
|
||||
|
||||
private string $redirectUrl;
|
||||
|
||||
public function __construct(IRequest $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->pdm = new PersistentDataManager();
|
||||
$this->userRepository = new UserRepository();
|
||||
$this->userPasswordResetterRepository = new UserPasswordResetterRepository();
|
||||
$this->redirectUrl = $this->request->session()->has('redirect_after_login') ?
|
||||
$this->request->session()->get('redirect_after_login') :
|
||||
\Container::$routeCollection->getRoute('index')->generateLink();
|
||||
}
|
||||
|
||||
public function getLoginForm()
|
||||
{
|
||||
if ($this->request->user() !== null) {
|
||||
return new Redirect(\Container::$routeCollection->getRoute('index')->generateLink(), IRedirect::TEMPORARY);
|
||||
$this->deleteRedirectUrl();
|
||||
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
||||
}
|
||||
|
||||
return new HtmlContent('login/login', ['redirectUrl' => $this->getRedirectUrl()]);
|
||||
return new HtmlContent('login/login', ['redirectUrl' => $this->redirectUrl]);
|
||||
}
|
||||
|
||||
public function getGoogleLoginRedirect(): IRedirect
|
||||
@ -65,7 +71,8 @@ class LoginController
|
||||
public function getRequestPasswordResetForm()
|
||||
{
|
||||
if ($this->request->user() !== null) {
|
||||
return new Redirect(\Container::$routeCollection->getRoute('index')->generateLink(), IRedirect::TEMPORARY);
|
||||
$this->deleteRedirectUrl();
|
||||
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
||||
}
|
||||
|
||||
return new HtmlContent('login/password_reset_request', ['email' => $this->request->query('email')]);
|
||||
@ -79,7 +86,8 @@ class LoginController
|
||||
public function getResetPasswordForm()
|
||||
{
|
||||
if ($this->request->user() !== null) {
|
||||
return new Redirect(\Container::$routeCollection->getRoute('index')->generateLink(), IRedirect::TEMPORARY);
|
||||
$this->deleteRedirectUrl();
|
||||
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
||||
}
|
||||
|
||||
$token = $this->request->query('token');
|
||||
@ -91,7 +99,7 @@ class LoginController
|
||||
|
||||
$user = $this->userRepository->getById($resetter->getUserId());
|
||||
|
||||
return new HtmlContent('login/reset_password', ['success' => true, 'token' => $token, 'email' => $user->getEmail(), 'redirectUrl' => $this->getRedirectUrl()]);
|
||||
return new HtmlContent('login/reset_password', ['success' => true, 'token' => $token, 'email' => $user->getEmail(), 'redirectUrl' => $this->redirectUrl]);
|
||||
}
|
||||
|
||||
public function login(): IContent
|
||||
@ -123,7 +131,7 @@ class LoginController
|
||||
|
||||
if ($this->request->user() !== null) {
|
||||
$this->deleteRedirectUrl();
|
||||
return new Redirect($this->getRedirectUrl(), IRedirect::TEMPORARY);
|
||||
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
||||
}
|
||||
|
||||
if ($this->request->query('state') !== $this->request->session()->get('oauth_state')) {
|
||||
@ -159,7 +167,7 @@ class LoginController
|
||||
$this->request->setUser($user);
|
||||
|
||||
$this->deleteRedirectUrl();
|
||||
return new Redirect($this->getRedirectUrl(), IRedirect::TEMPORARY);
|
||||
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
||||
}
|
||||
|
||||
public function logout(): IRedirect
|
||||
@ -175,7 +183,7 @@ class LoginController
|
||||
$this->deleteRedirectUrl();
|
||||
return new JsonContent([
|
||||
'redirect' => [
|
||||
'target' => $this->getRedirectUrl()
|
||||
'target' => $this->redirectUrl
|
||||
]
|
||||
]);
|
||||
}
|
||||
@ -239,7 +247,7 @@ class LoginController
|
||||
$this->deleteRedirectUrl();
|
||||
return new JsonContent([
|
||||
'redirect' => [
|
||||
'target' => $this->getRedirectUrl()
|
||||
'target' => $this->redirectUrl
|
||||
]
|
||||
]);
|
||||
}
|
||||
@ -298,15 +306,6 @@ class LoginController
|
||||
$mail->send();
|
||||
}
|
||||
|
||||
private function getRedirectUrl(): string
|
||||
{
|
||||
$redirectUrl = $this->request->session()->get('redirect_after_login');
|
||||
if ($redirectUrl === null) {
|
||||
return \Container::$routeCollection->getRoute('index')->generateLink();
|
||||
}
|
||||
return $redirectUrl;
|
||||
}
|
||||
|
||||
private function deleteRedirectUrl(): void
|
||||
{
|
||||
$this->request->session()->delete('redirect_after_login');
|
||||
|
Loading…
Reference in New Issue
Block a user