Compare commits

..

7 Commits

Author SHA1 Message Date
bf6b5f39a5
Merge pull request 'feature/use-new-features-from-soko-web' (!58) from feature/use-new-features-from-soko-web into develop
All checks were successful
mapguesser/pipeline/head This commit looks good
Reviewed-on: #58
2023-04-16 17:49:41 +02:00
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
54a4ee4d60
use ISecured/IAuthenticationRequired correctly in containers 2023-04-16 17:14:27 +02:00
62e0261a0b
implement redirect to login for controllers for authentication is required 2023-04-16 17:09:46 +02:00
9d1bb41f02
adapt to soko-web 0.2 2023-04-16 17:01:16 +02:00
59527a1898
update soko-web to 0.3 2023-04-16 17:00:54 +02:00
15 changed files with 112 additions and 70 deletions

View File

@ -10,7 +10,7 @@
} }
], ],
"require": { "require": {
"esoko/soko-web": "0.1", "esoko/soko-web": "0.3",
"fzaninotto/faker": "^1.9" "fzaninotto/faker": "^1.9"
}, },
"require-dev": { "require-dev": {

8
composer.lock generated
View File

@ -4,15 +4,15 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "4c91d823e927375028a2b3c9d974a8bd", "content-hash": "0f82e530dedc414cfc0b04daf3c2085c",
"packages": [ "packages": [
{ {
"name": "esoko/soko-web", "name": "esoko/soko-web",
"version": "v0.1", "version": "v0.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.esoko.eu/esoko/soko-web.git", "url": "https://git.esoko.eu/esoko/soko-web.git",
"reference": "a17a88e9d44e42cef3d996fc66b4dd1134b85def" "reference": "014a5480967c03c00dda5ee34c7eaf4be224b96e"
}, },
"require": { "require": {
"phpmailer/phpmailer": "^6.8", "phpmailer/phpmailer": "^6.8",
@ -33,7 +33,7 @@
"GNU GPL 3.0" "GNU GPL 3.0"
], ],
"description": "Lightweight web framework", "description": "Lightweight web framework",
"time": "2023-04-07T17:32:15+00:00" "time": "2023-04-16T14:54:22+00:00"
}, },
{ {
"name": "fzaninotto/faker", "name": "fzaninotto/faker",

View File

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

View File

@ -1,5 +1,13 @@
<?php <?php
use SokoWeb\Interfaces\Response\IRedirect;
use SokoWeb\Interfaces\Response\IContent;
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
use SokoWeb\Interfaces\Authorization\ISecured;
use SokoWeb\Response\Redirect;
use SokoWeb\Response\HtmlContent;
use SokoWeb\Response\JsonContent;
require '../web.php'; require '../web.php';
$method = strtolower($_SERVER['REQUEST_METHOD']); $method = strtolower($_SERVER['REQUEST_METHOD']);
@ -19,35 +27,40 @@ if ($match !== null) {
$handler = $route->getHandler(); $handler = $route->getHandler();
$controller = new $handler[0](Container::$request); $controller = new $handler[0](Container::$request);
if ($controller instanceof SokoWeb\Interfaces\Authorization\ISecured) { if (
$authorized = $controller->authorize(); $controller instanceof IAuthenticationRequired &&
} else { $controller->isAuthenticationRequired() &&
$authorized = true; Container::$request->user() === null
) {
Container::$request->session()->set('redirect_after_login', substr($_SERVER['REQUEST_URI'], strlen('/')));
$response = new Redirect(Container::$routeCollection->getRoute('login')->generateLink(), IRedirect::TEMPORARY);
header('Location: ' . $response->getUrl(), true, $response->getHttpCode());
return;
} }
if ($method === 'post' && Container::$request->post('anti_csrf_token') !== Container::$request->session()->get('anti_csrf_token')) { if ($method === 'post' && Container::$request->post('anti_csrf_token') !== Container::$request->session()->get('anti_csrf_token')) {
$content = new SokoWeb\Response\JsonContent(['error' => 'no_valid_anti_csrf_token']); $content = new JsonContent(['error' => 'no_valid_anti_csrf_token']);
header('Content-Type: text/html; charset=UTF-8', true, 403); header('Content-Type: text/html; charset=UTF-8', true, 403);
$content->render(); $content->render();
return; return;
} }
if ($authorized) { if (
!($controller instanceof ISecured) ||
$controller->authorize()
) {
$response = call_user_func([$controller, $handler[1]]); $response = call_user_func([$controller, $handler[1]]);
if ($response instanceof IContent) {
if ($response instanceof SokoWeb\Interfaces\Response\IContent) {
header('Content-Type: ' . $response->getContentType() . '; charset=UTF-8'); header('Content-Type: ' . $response->getContentType() . '; charset=UTF-8');
$response->render(); $response->render();
return; return;
} elseif ($response instanceof SokoWeb\Interfaces\Response\IRedirect) { } elseif ($response instanceof IRedirect) {
header('Location: ' . $response->getUrl(), true, $response->getHttpCode()); header('Location: ' . $response->getUrl(), true, $response->getHttpCode());
return; return;
} }
} }
} }
$content = new SokoWeb\Response\HtmlContent('error/404'); $content = new HtmlContent('error/404');
header('Content-Type: text/html; charset=UTF-8', true, 404); header('Content-Type: text/html; charset=UTF-8', true, 404);
$content->render(); $content->render();

View File

@ -69,7 +69,7 @@
printTimeForHuman: function (time) { printTimeForHuman: function (time) {
const minutes = Math.floor(time / 60); const minutes = Math.floor(time / 60);
const seconds = time % 60; const seconds = time % 60;
var time_str = ''; var time_str = '';
if (minutes == 1) { if (minutes == 1) {
time_str += '1 minute'; time_str += '1 minute';
@ -141,9 +141,7 @@
if (document.getElementById('challengeButton')) { if (document.getElementById('challengeButton')) {
document.getElementById('challengeButton').onclick = function () { document.getElementById('challengeButton').onclick = function () {
MapGuesser.showModal('challenge'); MapGuesser.showModal('challenge');
document.getElementById('createNewChallengeButton').href = '/challenge/new/' + this.dataset.mapId;
document.getElementById('playMode').style.visibility = 'hidden'; document.getElementById('playMode').style.visibility = 'hidden';
var timeLimit = document.getElementById('timeLimit').value; var timeLimit = document.getElementById('timeLimit').value;
document.getElementById('timeLimitLabel').innerText = 'Time limit of ' + Util.printTimeForHuman(timeLimit); document.getElementById('timeLimitLabel').innerText = 'Time limit of ' + Util.printTimeForHuman(timeLimit);
}; };

View File

@ -2,7 +2,7 @@
use DateTime; use DateTime;
use Faker\Factory; use Faker\Factory;
use SokoWeb\Interfaces\Authorization\ISecured; use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
use SokoWeb\Interfaces\Request\IRequest; use SokoWeb\Interfaces\Request\IRequest;
use SokoWeb\Response\HtmlContent; use SokoWeb\Response\HtmlContent;
use SokoWeb\Response\JsonContent; use SokoWeb\Response\JsonContent;
@ -21,7 +21,7 @@ use MapGuesser\Repository\PlaceRepository;
use MapGuesser\Repository\UserInChallengeRepository; use MapGuesser\Repository\UserInChallengeRepository;
use SokoWeb\Response\Redirect; use SokoWeb\Response\Redirect;
class GameController implements ISecured class GameController implements IAuthenticationRequired
{ {
const NUMBER_OF_ROUNDS = 5; const NUMBER_OF_ROUNDS = 5;
@ -53,9 +53,9 @@ class GameController implements ISecured
$this->userInChallengeRepository = new UserInChallengeRepository(); $this->userInChallengeRepository = new UserInChallengeRepository();
} }
public function authorize(): bool public function isAuthenticationRequired(): bool
{ {
return !empty($_ENV['ENABLE_GAME_FOR_GUESTS']) || $this->request->user() !== null; return empty($_ENV['ENABLE_GAME_FOR_GUESTS']);
} }
public function getGame(): IContent public function getGame(): IContent

View File

@ -1,7 +1,7 @@
<?php namespace MapGuesser\Controller; <?php namespace MapGuesser\Controller;
use DateTime; use DateTime;
use SokoWeb\Interfaces\Authorization\ISecured; use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
use SokoWeb\Interfaces\Request\IRequest; use SokoWeb\Interfaces\Request\IRequest;
use MapGuesser\Util\Geo\Position; use MapGuesser\Util\Geo\Position;
use SokoWeb\Response\JsonContent; use SokoWeb\Response\JsonContent;
@ -15,17 +15,14 @@ use MapGuesser\PersistentData\Model\Place;
use MapGuesser\PersistentData\Model\PlaceInChallenge; use MapGuesser\PersistentData\Model\PlaceInChallenge;
use MapGuesser\PersistentData\Model\User; use MapGuesser\PersistentData\Model\User;
use MapGuesser\PersistentData\Model\UserPlayedPlace; use MapGuesser\PersistentData\Model\UserPlayedPlace;
use MapGuesser\Repository\ChallengeRepository;
use MapGuesser\Repository\GuessRepository; use MapGuesser\Repository\GuessRepository;
use MapGuesser\Repository\MapRepository;
use MapGuesser\Repository\MultiRoomRepository; use MapGuesser\Repository\MultiRoomRepository;
use MapGuesser\Repository\PlaceInChallengeRepository; use MapGuesser\Repository\PlaceInChallengeRepository;
use MapGuesser\Repository\PlaceRepository; use MapGuesser\Repository\PlaceRepository;
use MapGuesser\Repository\UserInChallengeRepository; use MapGuesser\Repository\UserInChallengeRepository;
use MapGuesser\Repository\UserPlayedPlaceRepository; use MapGuesser\Repository\UserPlayedPlaceRepository;
use MapGuesser\Repository\UserRepository;
class GameFlowController implements ISecured class GameFlowController implements IAuthenticationRequired
{ {
const NUMBER_OF_ROUNDS = 5; const NUMBER_OF_ROUNDS = 5;
const MAX_SCORE = 1000; const MAX_SCORE = 1000;
@ -61,9 +58,9 @@ class GameFlowController implements ISecured
$this->guessRepository = new GuessRepository(); $this->guessRepository = new GuessRepository();
} }
public function authorize(): bool public function isAuthenticationRequired(): bool
{ {
return !empty($_ENV['ENABLE_GAME_FOR_GUESTS']) || $this->request->user() !== null; return empty($_ENV['ENABLE_GAME_FOR_GUESTS']);
} }
public function initialData(): IContent public function initialData(): IContent

View File

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

View File

@ -2,6 +2,7 @@
use DateTime; use DateTime;
use SokoWeb\Interfaces\Authentication\IUser; use SokoWeb\Interfaces\Authentication\IUser;
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
use SokoWeb\Interfaces\Authorization\ISecured; use SokoWeb\Interfaces\Authorization\ISecured;
use SokoWeb\Interfaces\Request\IRequest; use SokoWeb\Interfaces\Request\IRequest;
use SokoWeb\Interfaces\Response\IContent; use SokoWeb\Interfaces\Response\IContent;
@ -22,7 +23,7 @@ use SokoWeb\Response\JsonContent;
use MapGuesser\Util\Geo\Bounds; use MapGuesser\Util\Geo\Bounds;
use MapGuesser\Util\Panorama\Pov; use MapGuesser\Util\Panorama\Pov;
class MapAdminController implements ISecured class MapAdminController implements IAuthenticationRequired, ISecured
{ {
private static string $unnamedMapName = '[unnamed map]'; private static string $unnamedMapName = '[unnamed map]';
@ -57,11 +58,14 @@ class MapAdminController implements ISecured
$this->userInChallengeRepository = new UserInChallengeRepository(); $this->userInChallengeRepository = new UserInChallengeRepository();
} }
public function isAuthenticationRequired(): bool
{
return true;
}
public function authorize(): bool public function authorize(): bool
{ {
$user = $this->request->user(); return $this->request->user()->hasPermission(IUser::PERMISSION_ADMIN);
return $user !== null && $user->hasPermission(IUser::PERMISSION_ADMIN);
} }
public function getMapEditor(): IContent public function getMapEditor(): IContent

View File

@ -2,7 +2,7 @@
use DateTime; use DateTime;
use SokoWeb\Http\Request; use SokoWeb\Http\Request;
use SokoWeb\Interfaces\Authorization\ISecured; use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
use SokoWeb\Interfaces\Request\IRequest; use SokoWeb\Interfaces\Request\IRequest;
use SokoWeb\Interfaces\Response\IContent; use SokoWeb\Interfaces\Response\IContent;
use SokoWeb\Interfaces\Response\IRedirect; use SokoWeb\Interfaces\Response\IRedirect;
@ -19,7 +19,7 @@ use SokoWeb\Response\JsonContent;
use SokoWeb\Response\Redirect; use SokoWeb\Response\Redirect;
use SokoWeb\Util\JwtParser; use SokoWeb\Util\JwtParser;
class UserController implements ISecured class UserController implements IAuthenticationRequired
{ {
private IRequest $request; private IRequest $request;
@ -46,11 +46,9 @@ class UserController implements ISecured
$this->guessRepository = new GuessRepository(); $this->guessRepository = new GuessRepository();
} }
public function authorize(): bool public function isAuthenticationRequired(): bool
{ {
$user = $this->request->user(); return true;
return $user !== null;
} }
public function getAccount(): IContent public function getAccount(): IContent

View File

@ -5,7 +5,7 @@
@section(main) @section(main)
<h2>Sign up</h2> <h2>Sign up</h2>
<div class="box"> <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): ?> <?php if ($found): ?>
<p class="justify">Please confirm that you link your account to your Google account.</p> <p class="justify">Please confirm that you link your account to your Google account.</p>
<?php else: ?> <?php else: ?>

View File

@ -3,7 +3,7 @@
@section(main) @section(main)
<h2>Login</h2> <h2>Login</h2>
<div class="box"> <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="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"> <input type="password" class="text big fullWidth marginTop" name="password" placeholder="Password" required minlength="6">
<p id="loginFormError" class="formError justify marginTop"></p> <p id="loginFormError" class="formError justify marginTop"></p>

View File

@ -4,7 +4,7 @@
<h2>Reset password</h2> <h2>Reset password</h2>
<div class="box"> <div class="box">
<?php if ($success) : ?> <?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="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" placeholder="Password" required minlength="6" autofocus>
<input type="password" class="text big fullWidth marginTop" name="password_confirm" placeholder="Password confirmation" required minlength="6"> <input type="password" class="text big fullWidth marginTop" name="password_confirm" placeholder="Password confirmation" required minlength="6">

View File

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

View File

@ -110,6 +110,7 @@ Container::$request = new SokoWeb\Request\Request(
$_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'],
$_GET, $_GET,
$_POST, $_POST,
getallheaders(),
$_SESSION, $_SESSION,
new MapGuesser\Repository\UserRepository() new MapGuesser\Repository\UserRepository()
); );