Compare commits

...

2 Commits

Author SHA1 Message Date
ed80fe544f
add adminer to docker-compose
All checks were successful
mapguesser/pipeline/pr-develop This commit looks good
2023-04-16 17:48:12 +02:00
3e4c24bbc1
implement redirect after login 2023-04-16 17:48:12 +02:00
7 changed files with 61 additions and 32 deletions

View File

@ -29,6 +29,12 @@ services:
MYSQL_DATABASE: 'mapguesser'
MYSQL_USER: 'mapguesser'
MYSQL_PASSWORD: 'mapguesser'
adminer:
image: adminer:4.8.1-standalone
ports:
- 9090:8080
environment:
- ADMINER_DEFAULT_SERVER=mariadb
mail:
image: marcopas/docker-mailslurper:latest
ports:

View File

@ -141,9 +141,7 @@
if (document.getElementById('challengeButton')) {
document.getElementById('challengeButton').onclick = function () {
MapGuesser.showModal('challenge');
document.getElementById('createNewChallengeButton').href = '/challenge/new/' + this.dataset.mapId;
document.getElementById('playMode').style.visibility = 'hidden';
var timeLimit = document.getElementById('timeLimit').value;
document.getElementById('timeLimitLabel').innerText = 'Time limit of ' + Util.printTimeForHuman(timeLimit);
};

View File

@ -36,6 +36,8 @@ class LoginController
private UserPlayedPlaceRepository $userPlayedPlaceRepository;
private string $redirectUrl;
public function __construct(IRequest $request)
{
$this->request = $request;
@ -44,15 +46,19 @@ class LoginController
$this->userConfirmationRepository = new UserConfirmationRepository();
$this->userPasswordResetterRepository = new UserPasswordResetterRepository();
$this->userPlayedPlaceRepository = new UserPlayedPlaceRepository();
$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');
return new HtmlContent('login/login', ['redirectUrl' => '/' . $this->redirectUrl]);
}
public function getGoogleLoginRedirect(): IRedirect
@ -76,7 +82,8 @@ class LoginController
public function getSignupForm()
{
if ($this->request->user() !== null) {
return new Redirect(\Container::$routeCollection->getRoute('index')->generateLink(), IRedirect::TEMPORARY);
$this->deleteRedirectUrl();
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
}
if ($this->request->session()->has('tmp_user_data')) {
@ -98,7 +105,8 @@ class LoginController
public function getSignupWithGoogleForm()
{
if ($this->request->user() !== null) {
return new Redirect(\Container::$routeCollection->getRoute('index')->generateLink(), IRedirect::TEMPORARY);
$this->deleteRedirectUrl();
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
}
if (!$this->request->session()->has('google_user_data')) {
@ -109,13 +117,14 @@ class LoginController
$user = $this->userRepository->getByEmail($userData['email']);
return new HtmlContent('login/google_signup', ['found' => $user !== null, 'email' => $userData['email']]);
return new HtmlContent('login/google_signup', ['found' => $user !== null, 'email' => $userData['email'], 'redirectUrl' => '/' . $this->redirectUrl]);
}
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')]);
@ -129,7 +138,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');
@ -141,12 +151,13 @@ class LoginController
$user = $this->userRepository->getById($resetter->getUserId());
return new HtmlContent('login/reset_password', ['success' => true, 'token' => $token, 'email' => $user->getEmail()]);
return new HtmlContent('login/reset_password', ['success' => true, 'token' => $token, 'email' => $user->getEmail(), 'redirectUrl' => '/' . $this->redirectUrl]);
}
public function login(): IContent
{
if ($this->request->user() !== null) {
$this->deleteRedirectUrl();
return new JsonContent(['success' => true]);
}
@ -198,13 +209,15 @@ class LoginController
$this->request->setUser($user);
$this->deleteRedirectUrl();
return new JsonContent(['success' => true]);
}
public function loginWithGoogle()
{
if ($this->request->user() !== null) {
return new Redirect(\Container::$routeCollection->getRoute('index')->generateLink(), IRedirect::TEMPORARY);
$this->deleteRedirectUrl();
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
}
if ($this->request->query('state') !== $this->request->session()->get('oauth_state')) {
@ -242,7 +255,8 @@ class LoginController
$this->request->setUser($user);
return new Redirect(\Container::$routeCollection->getRoute('index')->generateLink(), IRedirect::TEMPORARY);
$this->deleteRedirectUrl();
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
}
public function logout(): IRedirect
@ -255,7 +269,8 @@ class LoginController
public function signup(): IContent
{
if ($this->request->user() !== null) {
return new JsonContent(['redirect' => ['target' => '/' . \Container::$routeCollection->getRoute('home')->generateLink()]]);
$this->deleteRedirectUrl();
return new JsonContent(['redirect' => ['target' => '/' . $this->redirectUrl]]);
}
$user = $this->userRepository->getByEmail($this->request->post('email'));
@ -274,7 +289,8 @@ class LoginController
$this->request->setUser($user);
$data = ['redirect' => ['target' => '/' . \Container::$routeCollection->getRoute('index')->generateLink()]];
$this->deleteRedirectUrl();
$data = ['redirect' => ['target' => '/' . $this->redirectUrl]];
} else {
$data = [
'error' => [
@ -355,6 +371,7 @@ class LoginController
public function signupWithGoogle(): IContent
{
if ($this->request->user() !== null) {
$this->deleteRedirectUrl();
return new JsonContent(['success' => true]);
}
@ -384,6 +401,7 @@ class LoginController
$this->request->session()->delete('google_user_data');
$this->request->setUser($user);
$this->deleteRedirectUrl();
return new JsonContent(['success' => true]);
}
@ -404,7 +422,8 @@ class LoginController
public function activate()
{
if ($this->request->user() !== null) {
return new Redirect(\Container::$routeCollection->getRoute('index')->generateLink(), IRedirect::TEMPORARY);
$this->deleteRedirectUrl();
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
}
$confirmation = $this->userConfirmationRepository->getByToken(substr($this->request->query('token'), 0, 32));
@ -426,13 +445,15 @@ class LoginController
$this->request->setUser($user);
return new Redirect(\Container::$routeCollection->getRoute('index')->generateLink(), IRedirect::TEMPORARY);
$this->deleteRedirectUrl();
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
}
public function cancel()
{
if ($this->request->user() !== null) {
return new Redirect(\Container::$routeCollection->getRoute('index')->generateLink(), IRedirect::TEMPORARY);
$this->deleteRedirectUrl();
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
}
$confirmation = $this->userConfirmationRepository->getByToken(substr($this->request->query('token'), 0, 32));
@ -461,9 +482,10 @@ class LoginController
public function requestPasswordReset(): IContent
{
if ($this->request->user() !== null) {
$this->deleteRedirectUrl();
return new JsonContent([
'redirect' => [
'target' => '/' . \Container::$routeCollection->getRoute('home')->generateLink()
'target' => '/' . $this->redirectUrl
]
]);
}
@ -538,9 +560,10 @@ class LoginController
public function resetPassword(): IContent
{
if ($this->request->user() !== null) {
$this->deleteRedirectUrl();
return new JsonContent([
'redirect' => [
'target' => '/' . \Container::$routeCollection->getRoute('home')->generateLink()
'target' => '/' . $this->redirectUrl
]
]);
}
@ -581,6 +604,7 @@ class LoginController
$this->request->setUser($user);
$this->deleteRedirectUrl();
return new JsonContent(['success' => true]);
}
@ -641,4 +665,9 @@ class LoginController
]);
$mail->send();
}
private function deleteRedirectUrl(): void
{
$this->request->session()->delete('redirect_after_login');
}
}

View File

@ -5,7 +5,7 @@
@section(main)
<h2>Sign up</h2>
<div class="box">
<form id="googleSignupForm" action="/signup/google" method="post" data-redirect-on-success="/">
<form id="googleSignupForm" action="/signup/google" method="post" data-redirect-on-success="<?= $redirectUrl ?>">
<?php if ($found): ?>
<p class="justify">Please confirm that you link your account to your Google account.</p>
<?php else: ?>

View File

@ -3,7 +3,7 @@
@section(main)
<h2>Login</h2>
<div class="box">
<form id="loginForm" action="/login" method="post" data-redirect-on-success="/">
<form id="loginForm" action="/login" method="post" data-redirect-on-success="<?= $redirectUrl ?>">
<input type="email" class="text big fullWidth" name="email" placeholder="Email address" required autofocus>
<input type="password" class="text big fullWidth marginTop" name="password" placeholder="Password" required minlength="6">
<p id="loginFormError" class="formError justify marginTop"></p>

View File

@ -4,7 +4,7 @@
<h2>Reset password</h2>
<div class="box">
<?php if ($success) : ?>
<form id="resetPasswordForm" action="/password/reset/<?= $token ?>" method="post" data-redirect-on-success="/">
<form id="resetPasswordForm" action="/password/reset/<?= $token ?>" method="post" data-redirect-on-success="<?= $redirectUrl ?>">
<input type="email" class="text big fullWidth" name="email" placeholder="Email address" value="<?= $email ?>" disabled>
<input type="password" class="text big fullWidth marginTop" name="password" placeholder="Password" required minlength="6" autofocus>
<input type="password" class="text big fullWidth marginTop" name="password_confirm" placeholder="Password confirmation" required minlength="6">

View File

@ -96,7 +96,6 @@ TODO: condition!
</div>
</div>
<div class="buttonContainer">
<?php if (!empty($_ENV['ENABLE_GAME_FOR_GUESTS']) || Container::$request->user()): ?>
<?php if ($isAdmin): ?>
<button class="button fullWidth noRightRadius playButton" data-map-id="<?= $map['id'] ?>" data-map-name="<?= htmlspecialchars($map['name']) ?>" title="Play map '<?= $map['name'] ?>'">Play this map</button>
<a class="button yellow fullWidth noLeftRadius noRightRadius" href="/admin/mapEditor/<?= $map['id']; ?>" title="Edit map '<?= $map['name'] ?>'">Edit</a>
@ -104,9 +103,6 @@ TODO: condition!
<?php else: ?>
<button class="button fullWidth playButton" data-map-id="<?= $map['id'] ?>" data-map-name="<?= htmlspecialchars($map['name']) ?>" title="Play map '<?= $map['name'] ?>'">Play this map</button>
<?php endif; ?>
<?php else: ?>
<a href="/login" class="button fullWidth" title="Play map '<?= $map['name'] ?>'">Play this map</a>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>