adapt Container usage to new soko-web
This commit is contained in:
parent
ee4a9f2ce3
commit
e52300b9e5
2
main.php
2
main.php
@ -15,9 +15,11 @@ $dotenv->load();
|
|||||||
class Container
|
class Container
|
||||||
{
|
{
|
||||||
static SokoWeb\Interfaces\Database\IConnection $dbConnection;
|
static SokoWeb\Interfaces\Database\IConnection $dbConnection;
|
||||||
|
static SokoWeb\Interfaces\PersistentData\IPersistentDataManager $persistentDataManager;
|
||||||
static SokoWeb\Routing\RouteCollection $routeCollection;
|
static SokoWeb\Routing\RouteCollection $routeCollection;
|
||||||
static SokoWeb\Interfaces\Session\ISessionHandler $sessionHandler;
|
static SokoWeb\Interfaces\Session\ISessionHandler $sessionHandler;
|
||||||
static SokoWeb\Interfaces\Request\IRequest $request;
|
static SokoWeb\Interfaces\Request\IRequest $request;
|
||||||
}
|
}
|
||||||
|
|
||||||
Container::$dbConnection = new SokoWeb\Database\Mysql\Connection($_ENV['DB_HOST'], $_ENV['DB_USER'], $_ENV['DB_PASSWORD'], $_ENV['DB_NAME']);
|
Container::$dbConnection = new SokoWeb\Database\Mysql\Connection($_ENV['DB_HOST'], $_ENV['DB_USER'], $_ENV['DB_PASSWORD'], $_ENV['DB_NAME']);
|
||||||
|
Container::$persistentDataManager = new SokoWeb\PersistentData\PersistentDataManager(Container::$dbConnection);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<?php namespace MapGuesser\Cli;
|
<?php namespace MapGuesser\Cli;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use SokoWeb\PersistentData\PersistentDataManager;
|
|
||||||
use MapGuesser\PersistentData\Model\User;
|
use MapGuesser\PersistentData\Model\User;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
@ -32,8 +31,7 @@ class AddUserCommand extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$pdm = new PersistentDataManager();
|
\Container::$persistentDataManager->saveToDb($user);
|
||||||
$pdm->saveToDb($user);
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$output->writeln('<error>Adding user failed!</error>');
|
$output->writeln('<error>Adding user failed!</error>');
|
||||||
$output->writeln('');
|
$output->writeln('');
|
||||||
|
@ -4,7 +4,6 @@ use DateTime;
|
|||||||
use SokoWeb\Database\Query\Modify;
|
use SokoWeb\Database\Query\Modify;
|
||||||
use SokoWeb\Database\Query\Select;
|
use SokoWeb\Database\Query\Select;
|
||||||
use SokoWeb\Interfaces\Database\IResultSet;
|
use SokoWeb\Interfaces\Database\IResultSet;
|
||||||
use SokoWeb\PersistentData\PersistentDataManager;
|
|
||||||
use MapGuesser\Repository\MultiRoomRepository;
|
use MapGuesser\Repository\MultiRoomRepository;
|
||||||
use MapGuesser\Repository\UserConfirmationRepository;
|
use MapGuesser\Repository\UserConfirmationRepository;
|
||||||
use MapGuesser\Repository\UserPasswordResetterRepository;
|
use MapGuesser\Repository\UserPasswordResetterRepository;
|
||||||
@ -16,8 +15,6 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
|
|
||||||
class MaintainDatabaseCommand extends Command
|
class MaintainDatabaseCommand extends Command
|
||||||
{
|
{
|
||||||
private PersistentDataManager $pdm;
|
|
||||||
|
|
||||||
private UserRepository $userRepository;
|
private UserRepository $userRepository;
|
||||||
|
|
||||||
private UserConfirmationRepository $userConfirmationRepository;
|
private UserConfirmationRepository $userConfirmationRepository;
|
||||||
@ -32,7 +29,6 @@ class MaintainDatabaseCommand extends Command
|
|||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->pdm = new PersistentDataManager();
|
|
||||||
$this->userRepository = new UserRepository();
|
$this->userRepository = new UserRepository();
|
||||||
$this->userConfirmationRepository = new UserConfirmationRepository();
|
$this->userConfirmationRepository = new UserConfirmationRepository();
|
||||||
$this->userPasswordResetterRepository = new UserPasswordResetterRepository();
|
$this->userPasswordResetterRepository = new UserPasswordResetterRepository();
|
||||||
@ -77,19 +73,19 @@ class MaintainDatabaseCommand extends Command
|
|||||||
//TODO: these can be in some wrapper class
|
//TODO: these can be in some wrapper class
|
||||||
$userConfirmation = $this->userConfirmationRepository->getByUser($user);
|
$userConfirmation = $this->userConfirmationRepository->getByUser($user);
|
||||||
if ($userConfirmation !== null) {
|
if ($userConfirmation !== null) {
|
||||||
$this->pdm->deleteFromDb($userConfirmation);
|
\Container::$persistentDataManager->deleteFromDb($userConfirmation);
|
||||||
}
|
}
|
||||||
|
|
||||||
$userPasswordResetter = $this->userPasswordResetterRepository->getByUser($user);
|
$userPasswordResetter = $this->userPasswordResetterRepository->getByUser($user);
|
||||||
if ($userPasswordResetter !== null) {
|
if ($userPasswordResetter !== null) {
|
||||||
$this->pdm->deleteFromDb($userPasswordResetter);
|
\Container::$persistentDataManager->deleteFromDb($userPasswordResetter);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->userPlayedPlaceRepository->getAllByUser($user) as $userPlayedPlace) {
|
foreach ($this->userPlayedPlaceRepository->getAllByUser($user) as $userPlayedPlace) {
|
||||||
$this->pdm->deleteFromDb($userPlayedPlace);
|
\Container::$persistentDataManager->deleteFromDb($userPlayedPlace);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pdm->deleteFromDb($user);
|
\Container::$persistentDataManager->deleteFromDb($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
\Container::$dbConnection->commit();
|
\Container::$dbConnection->commit();
|
||||||
@ -98,14 +94,14 @@ class MaintainDatabaseCommand extends Command
|
|||||||
private function deleteExpiredPasswordResetters(): void
|
private function deleteExpiredPasswordResetters(): void
|
||||||
{
|
{
|
||||||
foreach ($this->userPasswordResetterRepository->getAllExpired() as $passwordResetter) {
|
foreach ($this->userPasswordResetterRepository->getAllExpired() as $passwordResetter) {
|
||||||
$this->pdm->deleteFromDb($passwordResetter);
|
\Container::$persistentDataManager->deleteFromDb($passwordResetter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function deleteExpiredRooms(): void
|
private function deleteExpiredRooms(): void
|
||||||
{
|
{
|
||||||
foreach ($this->multiRoomRepository->getAllExpired() as $multiRoom) {
|
foreach ($this->multiRoomRepository->getAllExpired() as $multiRoom) {
|
||||||
$this->pdm->deleteFromDb($multiRoom);
|
\Container::$persistentDataManager->deleteFromDb($multiRoom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
use DateTime;
|
use DateTime;
|
||||||
use Faker\Factory;
|
use Faker\Factory;
|
||||||
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
|
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
|
||||||
use SokoWeb\Interfaces\Request\IRequest;
|
|
||||||
use SokoWeb\Response\HtmlContent;
|
use SokoWeb\Response\HtmlContent;
|
||||||
use SokoWeb\Response\JsonContent;
|
use SokoWeb\Response\JsonContent;
|
||||||
use SokoWeb\Interfaces\Response\IContent;
|
use SokoWeb\Interfaces\Response\IContent;
|
||||||
@ -13,7 +12,6 @@ use MapGuesser\PersistentData\Model\Challenge;
|
|||||||
use MapGuesser\PersistentData\Model\MultiRoom;
|
use MapGuesser\PersistentData\Model\MultiRoom;
|
||||||
use MapGuesser\PersistentData\Model\PlaceInChallenge;
|
use MapGuesser\PersistentData\Model\PlaceInChallenge;
|
||||||
use MapGuesser\PersistentData\Model\UserInChallenge;
|
use MapGuesser\PersistentData\Model\UserInChallenge;
|
||||||
use SokoWeb\PersistentData\PersistentDataManager;
|
|
||||||
use MapGuesser\Repository\ChallengeRepository;
|
use MapGuesser\Repository\ChallengeRepository;
|
||||||
use MapGuesser\Repository\MapRepository;
|
use MapGuesser\Repository\MapRepository;
|
||||||
use MapGuesser\Repository\MultiRoomRepository;
|
use MapGuesser\Repository\MultiRoomRepository;
|
||||||
@ -25,10 +23,6 @@ class GameController implements IAuthenticationRequired
|
|||||||
{
|
{
|
||||||
const NUMBER_OF_ROUNDS = 5;
|
const NUMBER_OF_ROUNDS = 5;
|
||||||
|
|
||||||
private IRequest $request;
|
|
||||||
|
|
||||||
private PersistentDataManager $pdm;
|
|
||||||
|
|
||||||
private MultiConnector $multiConnector;
|
private MultiConnector $multiConnector;
|
||||||
|
|
||||||
private MultiRoomRepository $multiRoomRepository;
|
private MultiRoomRepository $multiRoomRepository;
|
||||||
@ -41,10 +35,8 @@ class GameController implements IAuthenticationRequired
|
|||||||
|
|
||||||
private UserInChallengeRepository $userInChallengeRepository;
|
private UserInChallengeRepository $userInChallengeRepository;
|
||||||
|
|
||||||
public function __construct(IRequest $request)
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->request = $request;
|
|
||||||
$this->pdm = new PersistentDataManager();
|
|
||||||
$this->multiConnector = new MultiConnector();
|
$this->multiConnector = new MultiConnector();
|
||||||
$this->multiRoomRepository = new MultiRoomRepository();
|
$this->multiRoomRepository = new MultiRoomRepository();
|
||||||
$this->mapRepository = new MapRepository();
|
$this->mapRepository = new MapRepository();
|
||||||
@ -60,14 +52,14 @@ class GameController implements IAuthenticationRequired
|
|||||||
|
|
||||||
public function getGame(): IContent
|
public function getGame(): IContent
|
||||||
{
|
{
|
||||||
$mapId = (int) $this->request->query('mapId');
|
$mapId = (int) \Container::$request->query('mapId');
|
||||||
|
|
||||||
return new HtmlContent('game', ['mapId' => $mapId]);
|
return new HtmlContent('game', ['mapId' => $mapId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNewMultiGame(): IRedirect
|
public function getNewMultiGame(): IRedirect
|
||||||
{
|
{
|
||||||
$mapId = (int) $this->request->query('mapId');
|
$mapId = (int) \Container::$request->query('mapId');
|
||||||
$map = $this->mapRepository->getById($mapId);
|
$map = $this->mapRepository->getById($mapId);
|
||||||
$roomId = bin2hex(random_bytes(3));
|
$roomId = bin2hex(random_bytes(3));
|
||||||
$token = $this->getMultiToken($roomId);
|
$token = $this->getMultiToken($roomId);
|
||||||
@ -83,7 +75,7 @@ class GameController implements IAuthenticationRequired
|
|||||||
$room->setMembersArray(['owner' => $token, 'all' => []]);
|
$room->setMembersArray(['owner' => $token, 'all' => []]);
|
||||||
$room->setUpdatedDate(new DateTime());
|
$room->setUpdatedDate(new DateTime());
|
||||||
|
|
||||||
$this->pdm->saveToDb($room);
|
\Container::$persistentDataManager->saveToDb($room);
|
||||||
|
|
||||||
$this->multiConnector->sendMessage('create_room', ['roomId' => $roomId]);
|
$this->multiConnector->sendMessage('create_room', ['roomId' => $roomId]);
|
||||||
|
|
||||||
@ -97,14 +89,14 @@ class GameController implements IAuthenticationRequired
|
|||||||
|
|
||||||
public function getMultiGame(): IContent
|
public function getMultiGame(): IContent
|
||||||
{
|
{
|
||||||
$roomId = $this->request->query('roomId');
|
$roomId = \Container::$request->query('roomId');
|
||||||
|
|
||||||
return new HtmlContent('game', ['roomId' => $roomId]);
|
return new HtmlContent('game', ['roomId' => $roomId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getChallenge(): IContent
|
public function getChallenge(): IContent
|
||||||
{
|
{
|
||||||
$challengeToken = $this->request->query('challengeToken');
|
$challengeToken = \Container::$request->query('challengeToken');
|
||||||
|
|
||||||
return new HtmlContent('game', ['challengeToken' => $challengeToken]);
|
return new HtmlContent('game', ['challengeToken' => $challengeToken]);
|
||||||
}
|
}
|
||||||
@ -121,27 +113,27 @@ class GameController implements IAuthenticationRequired
|
|||||||
$challenge->setToken($challengeToken);
|
$challenge->setToken($challengeToken);
|
||||||
$challenge->setCreatedDate(new DateTime());
|
$challenge->setCreatedDate(new DateTime());
|
||||||
|
|
||||||
if ($this->request->post('timerEnabled') !== null && $this->request->post('timeLimit') !== null) {
|
if (\Container::$request->post('timerEnabled') !== null && \Container::$request->post('timeLimit') !== null) {
|
||||||
$challenge->setTimeLimit($this->request->post('timeLimit'));
|
$challenge->setTimeLimit(\Container::$request->post('timeLimit'));
|
||||||
}
|
}
|
||||||
if ($this->request->post('timeLimitType') !== null) {
|
if (\Container::$request->post('timeLimitType') !== null) {
|
||||||
$challenge->setTimeLimitType($this->request->post('timeLimitType'));
|
$challenge->setTimeLimitType(\Container::$request->post('timeLimitType'));
|
||||||
}
|
}
|
||||||
if ($this->request->post('noMove') !== null) {
|
if (\Container::$request->post('noMove') !== null) {
|
||||||
$challenge->setNoMove(true);
|
$challenge->setNoMove(true);
|
||||||
}
|
}
|
||||||
if ($this->request->post('noPan') !== null) {
|
if (\Container::$request->post('noPan') !== null) {
|
||||||
$challenge->setNoPan(true);
|
$challenge->setNoPan(true);
|
||||||
}
|
}
|
||||||
if ($this->request->post('noZoom') !== null) {
|
if (\Container::$request->post('noZoom') !== null) {
|
||||||
$challenge->setNoZoom(true);
|
$challenge->setNoZoom(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pdm->saveToDb($challenge);
|
\Container::$persistentDataManager->saveToDb($challenge);
|
||||||
|
|
||||||
// save owner/creator
|
// save owner/creator
|
||||||
|
|
||||||
$session = $this->request->session();
|
$session = \Container::$request->session();
|
||||||
$userId = $session->get('userId');
|
$userId = $session->get('userId');
|
||||||
|
|
||||||
$userInChallenge = new UserInChallenge();
|
$userInChallenge = new UserInChallenge();
|
||||||
@ -150,11 +142,11 @@ class GameController implements IAuthenticationRequired
|
|||||||
$userInChallenge->setTimeLeft($challenge->getTimeLimit());
|
$userInChallenge->setTimeLeft($challenge->getTimeLimit());
|
||||||
$userInChallenge->setIsOwner(true);
|
$userInChallenge->setIsOwner(true);
|
||||||
|
|
||||||
$this->pdm->saveToDb($userInChallenge);
|
\Container::$persistentDataManager->saveToDb($userInChallenge);
|
||||||
|
|
||||||
// select places
|
// select places
|
||||||
|
|
||||||
$mapId = (int) $this->request->post('mapId');
|
$mapId = (int) \Container::$request->post('mapId');
|
||||||
// $map = $this->mapRepository->getById($mapId);
|
// $map = $this->mapRepository->getById($mapId);
|
||||||
|
|
||||||
$places = $this->placeRepository->getRandomNPlaces($mapId, static::NUMBER_OF_ROUNDS, $userId);
|
$places = $this->placeRepository->getRandomNPlaces($mapId, static::NUMBER_OF_ROUNDS, $userId);
|
||||||
@ -165,7 +157,7 @@ class GameController implements IAuthenticationRequired
|
|||||||
$placeInChallenge->setPlace($place);
|
$placeInChallenge->setPlace($place);
|
||||||
$placeInChallenge->setChallenge($challenge);
|
$placeInChallenge->setChallenge($challenge);
|
||||||
$placeInChallenge->setRound($round++);
|
$placeInChallenge->setRound($round++);
|
||||||
$this->pdm->saveToDb($placeInChallenge);
|
\Container::$persistentDataManager->saveToDb($placeInChallenge);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new JsonContent(['challengeToken' => dechex($challengeToken)]);
|
return new JsonContent(['challengeToken' => dechex($challengeToken)]);
|
||||||
@ -173,9 +165,9 @@ class GameController implements IAuthenticationRequired
|
|||||||
|
|
||||||
public function prepareGame(): IContent
|
public function prepareGame(): IContent
|
||||||
{
|
{
|
||||||
$mapId = (int) $this->request->query('mapId');
|
$mapId = (int) \Container::$request->query('mapId');
|
||||||
$map = $this->mapRepository->getById($mapId);
|
$map = $this->mapRepository->getById($mapId);
|
||||||
$session = $this->request->session();
|
$session = \Container::$request->session();
|
||||||
|
|
||||||
if (!($state = $session->get('state')) || $state['mapId'] !== $mapId) {
|
if (!($state = $session->get('state')) || $state['mapId'] !== $mapId) {
|
||||||
$session->set('state', [
|
$session->set('state', [
|
||||||
@ -198,8 +190,8 @@ class GameController implements IAuthenticationRequired
|
|||||||
|
|
||||||
public function prepareMultiGame(): IContent
|
public function prepareMultiGame(): IContent
|
||||||
{
|
{
|
||||||
$roomId = $this->request->query('roomId');
|
$roomId = \Container::$request->query('roomId');
|
||||||
$userName = $this->request->post('userName');
|
$userName = \Container::$request->post('userName');
|
||||||
if (empty($userName)) {
|
if (empty($userName)) {
|
||||||
$faker = Factory::create();
|
$faker = Factory::create();
|
||||||
$userName = $faker->userName;
|
$userName = $faker->userName;
|
||||||
@ -228,7 +220,7 @@ class GameController implements IAuthenticationRequired
|
|||||||
$room->setMembersArray($members);
|
$room->setMembersArray($members);
|
||||||
$room->setUpdatedDate(new DateTime());
|
$room->setUpdatedDate(new DateTime());
|
||||||
|
|
||||||
$this->pdm->saveToDb($room);
|
\Container::$persistentDataManager->saveToDb($room);
|
||||||
|
|
||||||
$this->multiConnector->sendMessage('join_room', [
|
$this->multiConnector->sendMessage('join_room', [
|
||||||
'roomId' => $roomId,
|
'roomId' => $roomId,
|
||||||
@ -248,8 +240,8 @@ class GameController implements IAuthenticationRequired
|
|||||||
|
|
||||||
public function prepareChallenge(): IContent
|
public function prepareChallenge(): IContent
|
||||||
{
|
{
|
||||||
$challengeToken_str = $this->request->query('challengeToken');
|
$challengeToken_str = \Container::$request->query('challengeToken');
|
||||||
$session = $this->request->session();
|
$session = \Container::$request->session();
|
||||||
$userId = $session->get('userId');
|
$userId = $session->get('userId');
|
||||||
|
|
||||||
if (!isset($userId))
|
if (!isset($userId))
|
||||||
@ -270,7 +262,7 @@ class GameController implements IAuthenticationRequired
|
|||||||
$userInChallenge->setUserId($userId);
|
$userInChallenge->setUserId($userId);
|
||||||
$userInChallenge->setChallenge($challenge);
|
$userInChallenge->setChallenge($challenge);
|
||||||
$userInChallenge->setTimeLeft($challenge->getTimeLimit());
|
$userInChallenge->setTimeLeft($challenge->getTimeLimit());
|
||||||
$this->pdm->saveToDb($userInChallenge);
|
\Container::$persistentDataManager->saveToDb($userInChallenge);
|
||||||
}
|
}
|
||||||
|
|
||||||
$map = $this->mapRepository->getByChallenge($challenge);
|
$map = $this->mapRepository->getByChallenge($challenge);
|
||||||
@ -284,7 +276,7 @@ class GameController implements IAuthenticationRequired
|
|||||||
|
|
||||||
private function getMultiToken(string $roomId): string
|
private function getMultiToken(string $roomId): string
|
||||||
{
|
{
|
||||||
$session = $this->request->session();
|
$session = \Container::$request->session();
|
||||||
|
|
||||||
if (!($multiState = $session->get('multiState')) || $multiState['roomId'] !== $roomId) {
|
if (!($multiState = $session->get('multiState')) || $multiState['roomId'] !== $roomId) {
|
||||||
$token = bin2hex(random_bytes(16));
|
$token = bin2hex(random_bytes(16));
|
||||||
|
@ -2,12 +2,10 @@
|
|||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
|
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
|
||||||
use SokoWeb\Interfaces\Request\IRequest;
|
|
||||||
use MapGuesser\Util\Geo\Position;
|
use MapGuesser\Util\Geo\Position;
|
||||||
use SokoWeb\Response\JsonContent;
|
use SokoWeb\Response\JsonContent;
|
||||||
use SokoWeb\Interfaces\Response\IContent;
|
use SokoWeb\Interfaces\Response\IContent;
|
||||||
use MapGuesser\Multi\MultiConnector;
|
use MapGuesser\Multi\MultiConnector;
|
||||||
use SokoWeb\PersistentData\PersistentDataManager;
|
|
||||||
use MapGuesser\PersistentData\Model\Challenge;
|
use MapGuesser\PersistentData\Model\Challenge;
|
||||||
use MapGuesser\PersistentData\Model\Guess;
|
use MapGuesser\PersistentData\Model\Guess;
|
||||||
use MapGuesser\PersistentData\Model\Map;
|
use MapGuesser\PersistentData\Model\Map;
|
||||||
@ -27,10 +25,6 @@ class GameFlowController implements IAuthenticationRequired
|
|||||||
const NUMBER_OF_ROUNDS = 5;
|
const NUMBER_OF_ROUNDS = 5;
|
||||||
const MAX_SCORE = 1000;
|
const MAX_SCORE = 1000;
|
||||||
|
|
||||||
private IRequest $request;
|
|
||||||
|
|
||||||
private PersistentDataManager $pdm;
|
|
||||||
|
|
||||||
private MultiConnector $multiConnector;
|
private MultiConnector $multiConnector;
|
||||||
|
|
||||||
private MultiRoomRepository $multiRoomRepository;
|
private MultiRoomRepository $multiRoomRepository;
|
||||||
@ -45,10 +39,8 @@ class GameFlowController implements IAuthenticationRequired
|
|||||||
|
|
||||||
private GuessRepository $guessRepository;
|
private GuessRepository $guessRepository;
|
||||||
|
|
||||||
public function __construct(IRequest $request)
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->request = $request;
|
|
||||||
$this->pdm = new PersistentDataManager();
|
|
||||||
$this->multiConnector = new MultiConnector();
|
$this->multiConnector = new MultiConnector();
|
||||||
$this->multiRoomRepository = new MultiRoomRepository();
|
$this->multiRoomRepository = new MultiRoomRepository();
|
||||||
$this->placeRepository = new PlaceRepository();
|
$this->placeRepository = new PlaceRepository();
|
||||||
@ -65,8 +57,8 @@ class GameFlowController implements IAuthenticationRequired
|
|||||||
|
|
||||||
public function initialData(): IContent
|
public function initialData(): IContent
|
||||||
{
|
{
|
||||||
$mapId = (int) $this->request->query('mapId');
|
$mapId = (int) \Container::$request->query('mapId');
|
||||||
$session = $this->request->session();
|
$session = \Container::$request->session();
|
||||||
|
|
||||||
if (!($state = $session->get('state')) || $state['mapId'] !== $mapId) {
|
if (!($state = $session->get('state')) || $state['mapId'] !== $mapId) {
|
||||||
return new JsonContent(['error' => 'no_session_found']);
|
return new JsonContent(['error' => 'no_session_found']);
|
||||||
@ -103,8 +95,8 @@ class GameFlowController implements IAuthenticationRequired
|
|||||||
|
|
||||||
public function multiInitialData(): IContent
|
public function multiInitialData(): IContent
|
||||||
{
|
{
|
||||||
$roomId = $this->request->query('roomId');
|
$roomId = \Container::$request->query('roomId');
|
||||||
$session = $this->request->session();
|
$session = \Container::$request->session();
|
||||||
|
|
||||||
if (!($multiState = $session->get('multiState')) || $multiState['roomId'] !== $roomId) {
|
if (!($multiState = $session->get('multiState')) || $multiState['roomId'] !== $roomId) {
|
||||||
return new JsonContent(['error' => 'no_session_found']);
|
return new JsonContent(['error' => 'no_session_found']);
|
||||||
@ -122,7 +114,7 @@ class GameFlowController implements IAuthenticationRequired
|
|||||||
$this->startNewGame($state, $state['mapId']);
|
$this->startNewGame($state, $state['mapId']);
|
||||||
$room->setStateArray($state);
|
$room->setStateArray($state);
|
||||||
$room->setUpdatedDate(new DateTime());
|
$room->setUpdatedDate(new DateTime());
|
||||||
$this->pdm->saveToDb($room);
|
\Container::$persistentDataManager->saveToDb($room);
|
||||||
}
|
}
|
||||||
|
|
||||||
$places = [];
|
$places = [];
|
||||||
@ -221,9 +213,9 @@ class GameFlowController implements IAuthenticationRequired
|
|||||||
|
|
||||||
public function challengeInitialData(): IContent
|
public function challengeInitialData(): IContent
|
||||||
{
|
{
|
||||||
$session = $this->request->session();
|
$session = \Container::$request->session();
|
||||||
$userId = $session->get('userId');
|
$userId = $session->get('userId');
|
||||||
$challengeToken_str = $this->request->query('challengeToken');
|
$challengeToken_str = \Container::$request->query('challengeToken');
|
||||||
$userInChallenge = $this->userInChallengeRepository->getByUserIdAndToken($userId, $challengeToken_str, [Challenge::class]);
|
$userInChallenge = $this->userInChallengeRepository->getByUserIdAndToken($userId, $challengeToken_str, [Challenge::class]);
|
||||||
|
|
||||||
if (!isset($userInChallenge)) {
|
if (!isset($userInChallenge)) {
|
||||||
@ -245,15 +237,15 @@ class GameFlowController implements IAuthenticationRequired
|
|||||||
|
|
||||||
public function guess(): IContent
|
public function guess(): IContent
|
||||||
{
|
{
|
||||||
$mapId = (int) $this->request->query('mapId');
|
$mapId = (int) \Container::$request->query('mapId');
|
||||||
$session = $this->request->session();
|
$session = \Container::$request->session();
|
||||||
|
|
||||||
if (!($state = $session->get('state')) || $state['mapId'] !== $mapId) {
|
if (!($state = $session->get('state')) || $state['mapId'] !== $mapId) {
|
||||||
return new JsonContent(['error' => 'no_session_found']);
|
return new JsonContent(['error' => 'no_session_found']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$last = $state['rounds'][$state['currentRound']];
|
$last = $state['rounds'][$state['currentRound']];
|
||||||
$guessPosition = new Position((float) $this->request->post('lat'), (float) $this->request->post('lng'));
|
$guessPosition = new Position((float) \Container::$request->post('lat'), (float) \Container::$request->post('lng'));
|
||||||
$result = $this->evaluateGuess($last['position'], $guessPosition, $state['area']);
|
$result = $this->evaluateGuess($last['position'], $guessPosition, $state['area']);
|
||||||
|
|
||||||
$last['guessPosition'] = $guessPosition;
|
$last['guessPosition'] = $guessPosition;
|
||||||
@ -286,7 +278,7 @@ class GameFlowController implements IAuthenticationRequired
|
|||||||
// save the selected place for the round in UserPlayedPlace
|
// save the selected place for the round in UserPlayedPlace
|
||||||
private function saveVisit($placeId): void
|
private function saveVisit($placeId): void
|
||||||
{
|
{
|
||||||
$session = $this->request->session();
|
$session = \Container::$request->session();
|
||||||
$userId = $session->get('userId');
|
$userId = $session->get('userId');
|
||||||
|
|
||||||
if (isset($userId)) {
|
if (isset($userId)) {
|
||||||
@ -299,14 +291,14 @@ class GameFlowController implements IAuthenticationRequired
|
|||||||
$userPlayedPlace->incrementOccurrences();
|
$userPlayedPlace->incrementOccurrences();
|
||||||
}
|
}
|
||||||
$userPlayedPlace->setLastTimeDate(new DateTime());
|
$userPlayedPlace->setLastTimeDate(new DateTime());
|
||||||
$this->pdm->saveToDb($userPlayedPlace);
|
\Container::$persistentDataManager->saveToDb($userPlayedPlace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function multiGuess(): IContent
|
public function multiGuess(): IContent
|
||||||
{
|
{
|
||||||
$roomId = $this->request->query('roomId');
|
$roomId = \Container::$request->query('roomId');
|
||||||
$session = $this->request->session();
|
$session = \Container::$request->session();
|
||||||
|
|
||||||
if (!($multiState = $session->get('multiState')) || $multiState['roomId'] !== $roomId) {
|
if (!($multiState = $session->get('multiState')) || $multiState['roomId'] !== $roomId) {
|
||||||
return new JsonContent(['error' => 'no_session_found']);
|
return new JsonContent(['error' => 'no_session_found']);
|
||||||
@ -316,7 +308,7 @@ class GameFlowController implements IAuthenticationRequired
|
|||||||
$state = $room->getStateArray();
|
$state = $room->getStateArray();
|
||||||
|
|
||||||
$last = $state['rounds'][$state['currentRound']];
|
$last = $state['rounds'][$state['currentRound']];
|
||||||
$guessPosition = new Position((float) $this->request->post('lat'), (float) $this->request->post('lng'));
|
$guessPosition = new Position((float) \Container::$request->post('lat'), (float) \Container::$request->post('lng'));
|
||||||
$result = $this->evaluateGuess($last['position'], $guessPosition, $state['area']);
|
$result = $this->evaluateGuess($last['position'], $guessPosition, $state['area']);
|
||||||
|
|
||||||
$responseFromMulti = $this->multiConnector->sendMessage('guess', [
|
$responseFromMulti = $this->multiConnector->sendMessage('guess', [
|
||||||
@ -342,9 +334,9 @@ class GameFlowController implements IAuthenticationRequired
|
|||||||
|
|
||||||
public function challengeGuess(): IContent
|
public function challengeGuess(): IContent
|
||||||
{
|
{
|
||||||
$session = $this->request->session();
|
$session = \Container::$request->session();
|
||||||
$userId = $session->get('userId');
|
$userId = $session->get('userId');
|
||||||
$challengeToken_str = $this->request->query('challengeToken');
|
$challengeToken_str = \Container::$request->query('challengeToken');
|
||||||
$userInChallenge = $this->userInChallengeRepository->getByUserIdAndToken($userId, $challengeToken_str, [Challenge::class]);
|
$userInChallenge = $this->userInChallengeRepository->getByUserIdAndToken($userId, $challengeToken_str, [Challenge::class]);
|
||||||
|
|
||||||
if (!isset($userInChallenge)) {
|
if (!isset($userInChallenge)) {
|
||||||
@ -362,8 +354,8 @@ class GameFlowController implements IAuthenticationRequired
|
|||||||
$response = $this->prepareChallengeResponse($userId, $challenge, $nextRound);
|
$response = $this->prepareChallengeResponse($userId, $challenge, $nextRound);
|
||||||
$response['position'] = $currentPlace->getPosition()->toArray();
|
$response['position'] = $currentPlace->getPosition()->toArray();
|
||||||
|
|
||||||
if ($this->request->post('lat') && $this->request->post('lng')) {
|
if (\Container::$request->post('lat') && \Container::$request->post('lng')) {
|
||||||
$guessPosition = new Position((float) $this->request->post('lat'), (float) $this->request->post('lng'));
|
$guessPosition = new Position((float) \Container::$request->post('lat'), (float) \Container::$request->post('lng'));
|
||||||
$result = $this->evaluateGuess($currentPlace->getPosition(), $guessPosition, $map->getArea());
|
$result = $this->evaluateGuess($currentPlace->getPosition(), $guessPosition, $map->getArea());
|
||||||
|
|
||||||
// save guess
|
// save guess
|
||||||
@ -373,7 +365,7 @@ class GameFlowController implements IAuthenticationRequired
|
|||||||
$guess->setPosition($guessPosition);
|
$guess->setPosition($guessPosition);
|
||||||
$guess->setDistance($result['distance']);
|
$guess->setDistance($result['distance']);
|
||||||
$guess->setScore($result['score']);
|
$guess->setScore($result['score']);
|
||||||
$this->pdm->saveToDb($guess);
|
\Container::$persistentDataManager->saveToDb($guess);
|
||||||
|
|
||||||
$response['result'] = $result;
|
$response['result'] = $result;
|
||||||
|
|
||||||
@ -384,11 +376,11 @@ class GameFlowController implements IAuthenticationRequired
|
|||||||
|
|
||||||
// save user relevant state of challenge
|
// save user relevant state of challenge
|
||||||
$userInChallenge->setCurrentRound($nextRound);
|
$userInChallenge->setCurrentRound($nextRound);
|
||||||
$timeLeft = $this->request->post('timeLeft');
|
$timeLeft = \Container::$request->post('timeLeft');
|
||||||
if (isset($timeLeft)) {
|
if (isset($timeLeft)) {
|
||||||
$userInChallenge->setTimeLeft(intval($timeLeft));
|
$userInChallenge->setTimeLeft(intval($timeLeft));
|
||||||
}
|
}
|
||||||
$this->pdm->saveToDb($userInChallenge);
|
\Container::$persistentDataManager->saveToDb($userInChallenge);
|
||||||
|
|
||||||
if ($challenge->getTimeLimitType() === 'game' && isset($timeLeft)) {
|
if ($challenge->getTimeLimitType() === 'game' && isset($timeLeft)) {
|
||||||
$timeLimit = max(10, intval($timeLeft));
|
$timeLimit = max(10, intval($timeLeft));
|
||||||
@ -406,8 +398,8 @@ class GameFlowController implements IAuthenticationRequired
|
|||||||
|
|
||||||
public function multiNextRound(): IContent
|
public function multiNextRound(): IContent
|
||||||
{
|
{
|
||||||
$roomId = $this->request->query('roomId');
|
$roomId = \Container::$request->query('roomId');
|
||||||
$session = $this->request->session();
|
$session = \Container::$request->session();
|
||||||
|
|
||||||
if (!($multiState = $session->get('multiState')) || $multiState['roomId'] !== $roomId) {
|
if (!($multiState = $session->get('multiState')) || $multiState['roomId'] !== $roomId) {
|
||||||
return new JsonContent(['error' => 'no_session_found']);
|
return new JsonContent(['error' => 'no_session_found']);
|
||||||
@ -428,7 +420,7 @@ class GameFlowController implements IAuthenticationRequired
|
|||||||
|
|
||||||
$room->setStateArray($state);
|
$room->setStateArray($state);
|
||||||
$room->setUpdatedDate(new DateTime());
|
$room->setUpdatedDate(new DateTime());
|
||||||
$this->pdm->saveToDb($room);
|
\Container::$persistentDataManager->saveToDb($room);
|
||||||
|
|
||||||
return new JsonContent(['ok' => true]);
|
return new JsonContent(['ok' => true]);
|
||||||
}
|
}
|
||||||
@ -443,7 +435,7 @@ class GameFlowController implements IAuthenticationRequired
|
|||||||
|
|
||||||
private function startNewGame(array &$state, int $mapId): void
|
private function startNewGame(array &$state, int $mapId): void
|
||||||
{
|
{
|
||||||
$session = $this->request->session();
|
$session = \Container::$request->session();
|
||||||
$userId = $session->get('userId');
|
$userId = $session->get('userId');
|
||||||
|
|
||||||
$places = $this->placeRepository->getRandomNPlaces($mapId, static::NUMBER_OF_ROUNDS, $userId);
|
$places = $this->placeRepository->getRandomNPlaces($mapId, static::NUMBER_OF_ROUNDS, $userId);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?php namespace MapGuesser\Controller;
|
<?php namespace MapGuesser\Controller;
|
||||||
|
|
||||||
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;
|
||||||
use SokoWeb\Response\JsonContent;
|
use SokoWeb\Response\JsonContent;
|
||||||
@ -8,13 +7,6 @@ use SokoWeb\Response\Redirect;
|
|||||||
|
|
||||||
class HomeController
|
class HomeController
|
||||||
{
|
{
|
||||||
private IRequest $request;
|
|
||||||
|
|
||||||
public function __construct(IRequest $request)
|
|
||||||
{
|
|
||||||
$this->request = $request;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getIndex(): IRedirect
|
public function getIndex(): IRedirect
|
||||||
{
|
{
|
||||||
return new Redirect(\Container::$routeCollection->getRoute('maps')->generateLink(), IRedirect::TEMPORARY);
|
return new Redirect(\Container::$routeCollection->getRoute('maps')->generateLink(), IRedirect::TEMPORARY);
|
||||||
@ -24,6 +16,6 @@ class HomeController
|
|||||||
{
|
{
|
||||||
// session starts with the request, this method just sends valid data to the client
|
// session starts with the request, this method just sends valid data to the client
|
||||||
|
|
||||||
return new JsonContent(['antiCsrfToken' => $this->request->session()->get('anti_csrf_token')]);
|
return new JsonContent(['antiCsrfToken' => \Container::$request->session()->get('anti_csrf_token')]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
use DateInterval;
|
use DateInterval;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use SokoWeb\Http\Request;
|
use SokoWeb\Http\Request;
|
||||||
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;
|
||||||
use SokoWeb\Mailing\Mail;
|
use SokoWeb\Mailing\Mail;
|
||||||
@ -11,7 +10,6 @@ use SokoWeb\OAuth\GoogleOAuth;
|
|||||||
use MapGuesser\PersistentData\Model\User;
|
use MapGuesser\PersistentData\Model\User;
|
||||||
use MapGuesser\PersistentData\Model\UserConfirmation;
|
use MapGuesser\PersistentData\Model\UserConfirmation;
|
||||||
use MapGuesser\PersistentData\Model\UserPasswordResetter;
|
use MapGuesser\PersistentData\Model\UserPasswordResetter;
|
||||||
use SokoWeb\PersistentData\PersistentDataManager;
|
|
||||||
use MapGuesser\Repository\UserConfirmationRepository;
|
use MapGuesser\Repository\UserConfirmationRepository;
|
||||||
use MapGuesser\Repository\UserPasswordResetterRepository;
|
use MapGuesser\Repository\UserPasswordResetterRepository;
|
||||||
use MapGuesser\Repository\UserPlayedPlaceRepository;
|
use MapGuesser\Repository\UserPlayedPlaceRepository;
|
||||||
@ -24,10 +22,6 @@ use SokoWeb\Util\JwtParser;
|
|||||||
|
|
||||||
class LoginController
|
class LoginController
|
||||||
{
|
{
|
||||||
private IRequest $request;
|
|
||||||
|
|
||||||
private PersistentDataManager $pdm;
|
|
||||||
|
|
||||||
private UserRepository $userRepository;
|
private UserRepository $userRepository;
|
||||||
|
|
||||||
private UserConfirmationRepository $userConfirmationRepository;
|
private UserConfirmationRepository $userConfirmationRepository;
|
||||||
@ -38,22 +32,20 @@ class LoginController
|
|||||||
|
|
||||||
private string $redirectUrl;
|
private string $redirectUrl;
|
||||||
|
|
||||||
public function __construct(IRequest $request)
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->request = $request;
|
|
||||||
$this->pdm = new PersistentDataManager();
|
|
||||||
$this->userRepository = new UserRepository();
|
$this->userRepository = new UserRepository();
|
||||||
$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->redirectUrl = \Container::$request->session()->has('redirect_after_login') ?
|
||||||
$this->request->session()->get('redirect_after_login') :
|
\Container::$request->session()->get('redirect_after_login') :
|
||||||
\Container::$routeCollection->getRoute('index')->generateLink();
|
\Container::$routeCollection->getRoute('index')->generateLink();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLoginForm()
|
public function getLoginForm()
|
||||||
{
|
{
|
||||||
if ($this->request->user() !== null) {
|
if (\Container::$request->user() !== null) {
|
||||||
$this->deleteRedirectUrl();
|
$this->deleteRedirectUrl();
|
||||||
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
||||||
}
|
}
|
||||||
@ -66,13 +58,13 @@ class LoginController
|
|||||||
$state = bin2hex(random_bytes(16));
|
$state = bin2hex(random_bytes(16));
|
||||||
$nonce = bin2hex(random_bytes(16));
|
$nonce = bin2hex(random_bytes(16));
|
||||||
|
|
||||||
$this->request->session()->set('oauth_state', $state);
|
\Container::$request->session()->set('oauth_state', $state);
|
||||||
$this->request->session()->set('oauth_nonce', $nonce);
|
\Container::$request->session()->set('oauth_nonce', $nonce);
|
||||||
|
|
||||||
$oAuth = new GoogleOAuth(new Request());
|
$oAuth = new GoogleOAuth(new Request());
|
||||||
$url = $oAuth->getDialogUrl(
|
$url = $oAuth->getDialogUrl(
|
||||||
$state,
|
$state,
|
||||||
$this->request->getBase() . \Container::$routeCollection->getRoute('login-google-action')->generateLink(),
|
\Container::$request->getBase() . \Container::$routeCollection->getRoute('login-google-action')->generateLink(),
|
||||||
$nonce
|
$nonce
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -81,13 +73,13 @@ class LoginController
|
|||||||
|
|
||||||
public function getSignupForm()
|
public function getSignupForm()
|
||||||
{
|
{
|
||||||
if ($this->request->user() !== null) {
|
if (\Container::$request->user() !== null) {
|
||||||
$this->deleteRedirectUrl();
|
$this->deleteRedirectUrl();
|
||||||
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->request->session()->has('tmp_user_data')) {
|
if (\Container::$request->session()->has('tmp_user_data')) {
|
||||||
$tmpUserData = $this->request->session()->get('tmp_user_data');
|
$tmpUserData = \Container::$request->session()->get('tmp_user_data');
|
||||||
|
|
||||||
$data = ['email' => $tmpUserData['email']];
|
$data = ['email' => $tmpUserData['email']];
|
||||||
} else {
|
} else {
|
||||||
@ -104,16 +96,16 @@ class LoginController
|
|||||||
|
|
||||||
public function getSignupWithGoogleForm()
|
public function getSignupWithGoogleForm()
|
||||||
{
|
{
|
||||||
if ($this->request->user() !== null) {
|
if (\Container::$request->user() !== null) {
|
||||||
$this->deleteRedirectUrl();
|
$this->deleteRedirectUrl();
|
||||||
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->request->session()->has('google_user_data')) {
|
if (!\Container::$request->session()->has('google_user_data')) {
|
||||||
return new Redirect(\Container::$routeCollection->getRoute('login-google')->generateLink(), IRedirect::TEMPORARY);
|
return new Redirect(\Container::$routeCollection->getRoute('login-google')->generateLink(), IRedirect::TEMPORARY);
|
||||||
}
|
}
|
||||||
|
|
||||||
$userData = $this->request->session()->get('google_user_data');
|
$userData = \Container::$request->session()->get('google_user_data');
|
||||||
|
|
||||||
$user = $this->userRepository->getByEmail($userData['email']);
|
$user = $this->userRepository->getByEmail($userData['email']);
|
||||||
|
|
||||||
@ -122,12 +114,12 @@ class LoginController
|
|||||||
|
|
||||||
public function getRequestPasswordResetForm()
|
public function getRequestPasswordResetForm()
|
||||||
{
|
{
|
||||||
if ($this->request->user() !== null) {
|
if (\Container::$request->user() !== null) {
|
||||||
$this->deleteRedirectUrl();
|
$this->deleteRedirectUrl();
|
||||||
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
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' => \Container::$request->query('email')]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRequestPasswordResetSuccess(): IContent
|
public function getRequestPasswordResetSuccess(): IContent
|
||||||
@ -137,12 +129,12 @@ class LoginController
|
|||||||
|
|
||||||
public function getResetPasswordForm()
|
public function getResetPasswordForm()
|
||||||
{
|
{
|
||||||
if ($this->request->user() !== null) {
|
if (\Container::$request->user() !== null) {
|
||||||
$this->deleteRedirectUrl();
|
$this->deleteRedirectUrl();
|
||||||
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
||||||
}
|
}
|
||||||
|
|
||||||
$token = $this->request->query('token');
|
$token = \Container::$request->query('token');
|
||||||
$resetter = $this->userPasswordResetterRepository->getByToken($token);
|
$resetter = $this->userPasswordResetterRepository->getByToken($token);
|
||||||
|
|
||||||
if ($resetter === null || $resetter->getExpiresDate() < new DateTime()) {
|
if ($resetter === null || $resetter->getExpiresDate() < new DateTime()) {
|
||||||
@ -156,15 +148,15 @@ class LoginController
|
|||||||
|
|
||||||
public function login(): IContent
|
public function login(): IContent
|
||||||
{
|
{
|
||||||
if ($this->request->user() !== null) {
|
if (\Container::$request->user() !== null) {
|
||||||
$this->deleteRedirectUrl();
|
$this->deleteRedirectUrl();
|
||||||
return new JsonContent(['success' => true]);
|
return new JsonContent(['success' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->userRepository->getByEmail($this->request->post('email'));
|
$user = $this->userRepository->getByEmail(\Container::$request->post('email'));
|
||||||
|
|
||||||
if ($user === null) {
|
if ($user === null) {
|
||||||
if (strlen($this->request->post('password')) < 6) {
|
if (strlen(\Container::$request->post('password')) < 6) {
|
||||||
return new JsonContent([
|
return new JsonContent([
|
||||||
'error' => [
|
'error' => [
|
||||||
'errorText' => 'The given password is too short. Please choose a password that is at least 6 characters long!'
|
'errorText' => 'The given password is too short. Please choose a password that is at least 6 characters long!'
|
||||||
@ -173,10 +165,10 @@ class LoginController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$tmpUser = new User();
|
$tmpUser = new User();
|
||||||
$tmpUser->setPlainPassword($this->request->post('password'));
|
$tmpUser->setPlainPassword(\Container::$request->post('password'));
|
||||||
|
|
||||||
$this->request->session()->set('tmp_user_data', [
|
\Container::$request->session()->set('tmp_user_data', [
|
||||||
'email' => $this->request->post('email'),
|
'email' => \Container::$request->post('email'),
|
||||||
'password_hashed' => $tmpUser->getPassword()
|
'password_hashed' => $tmpUser->getPassword()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -198,7 +190,7 @@ class LoginController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$user->checkPassword($this->request->post('password'))) {
|
if (!$user->checkPassword(\Container::$request->post('password'))) {
|
||||||
return new JsonContent([
|
return new JsonContent([
|
||||||
'error' => [
|
'error' => [
|
||||||
'errorText' => 'The given password is wrong. You can <a href="/password/requestReset?email=' .
|
'errorText' => 'The given password is wrong. You can <a href="/password/requestReset?email=' .
|
||||||
@ -207,7 +199,7 @@ class LoginController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->request->setUser($user);
|
\Container::$request->setUser($user);
|
||||||
|
|
||||||
$this->deleteRedirectUrl();
|
$this->deleteRedirectUrl();
|
||||||
return new JsonContent(['success' => true]);
|
return new JsonContent(['success' => true]);
|
||||||
@ -215,19 +207,19 @@ class LoginController
|
|||||||
|
|
||||||
public function loginWithGoogle()
|
public function loginWithGoogle()
|
||||||
{
|
{
|
||||||
if ($this->request->user() !== null) {
|
if (\Container::$request->user() !== null) {
|
||||||
$this->deleteRedirectUrl();
|
$this->deleteRedirectUrl();
|
||||||
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->request->query('state') !== $this->request->session()->get('oauth_state')) {
|
if (\Container::$request->query('state') !== \Container::$request->session()->get('oauth_state')) {
|
||||||
return new HtmlContent('login/google_login');
|
return new HtmlContent('login/google_login');
|
||||||
}
|
}
|
||||||
|
|
||||||
$oAuth = new GoogleOAuth(new Request());
|
$oAuth = new GoogleOAuth(new Request());
|
||||||
$tokenData = $oAuth->getToken(
|
$tokenData = $oAuth->getToken(
|
||||||
$this->request->query('code'),
|
\Container::$request->query('code'),
|
||||||
$this->request->getBase() . \Container::$routeCollection->getRoute('login-google-action')->generateLink()
|
\Container::$request->getBase() . \Container::$routeCollection->getRoute('login-google-action')->generateLink()
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!isset($tokenData['id_token'])) {
|
if (!isset($tokenData['id_token'])) {
|
||||||
@ -237,7 +229,7 @@ class LoginController
|
|||||||
$jwtParser = new JwtParser($tokenData['id_token']);
|
$jwtParser = new JwtParser($tokenData['id_token']);
|
||||||
$idToken = $jwtParser->getPayload();
|
$idToken = $jwtParser->getPayload();
|
||||||
|
|
||||||
if ($idToken['nonce'] !== $this->request->session()->get('oauth_nonce')) {
|
if ($idToken['nonce'] !== \Container::$request->session()->get('oauth_nonce')) {
|
||||||
return new HtmlContent('login/google_login');
|
return new HtmlContent('login/google_login');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,12 +240,12 @@ class LoginController
|
|||||||
$user = $this->userRepository->getByGoogleSub($idToken['sub']);
|
$user = $this->userRepository->getByGoogleSub($idToken['sub']);
|
||||||
|
|
||||||
if ($user === null) {
|
if ($user === null) {
|
||||||
$this->request->session()->set('google_user_data', ['sub' => $idToken['sub'], 'email' => $idToken['email']]);
|
\Container::$request->session()->set('google_user_data', ['sub' => $idToken['sub'], 'email' => $idToken['email']]);
|
||||||
|
|
||||||
return new Redirect(\Container::$routeCollection->getRoute('signup-google')->generateLink(), IRedirect::TEMPORARY);
|
return new Redirect(\Container::$routeCollection->getRoute('signup-google')->generateLink(), IRedirect::TEMPORARY);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->request->setUser($user);
|
\Container::$request->setUser($user);
|
||||||
|
|
||||||
$this->deleteRedirectUrl();
|
$this->deleteRedirectUrl();
|
||||||
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
||||||
@ -261,23 +253,23 @@ class LoginController
|
|||||||
|
|
||||||
public function logout(): IRedirect
|
public function logout(): IRedirect
|
||||||
{
|
{
|
||||||
$this->request->setUser(null);
|
\Container::$request->setUser(null);
|
||||||
|
|
||||||
return new Redirect(\Container::$routeCollection->getRoute('index')->generateLink(), IRedirect::TEMPORARY);
|
return new Redirect(\Container::$routeCollection->getRoute('index')->generateLink(), IRedirect::TEMPORARY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function signup(): IContent
|
public function signup(): IContent
|
||||||
{
|
{
|
||||||
if ($this->request->user() !== null) {
|
if (\Container::$request->user() !== null) {
|
||||||
$this->deleteRedirectUrl();
|
$this->deleteRedirectUrl();
|
||||||
return new JsonContent(['redirect' => ['target' => $this->redirectUrl]]);
|
return new JsonContent(['redirect' => ['target' => $this->redirectUrl]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->userRepository->getByEmail($this->request->post('email'));
|
$user = $this->userRepository->getByEmail(\Container::$request->post('email'));
|
||||||
|
|
||||||
if ($user !== null) {
|
if ($user !== null) {
|
||||||
if ($user->getActive()) {
|
if ($user->getActive()) {
|
||||||
if (!$user->checkPassword($this->request->post('password'))) {
|
if (!$user->checkPassword(\Container::$request->post('password'))) {
|
||||||
return new JsonContent([
|
return new JsonContent([
|
||||||
'error' => [
|
'error' => [
|
||||||
'errorText' => 'There is a user already registered with the given email address, ' .
|
'errorText' => 'There is a user already registered with the given email address, ' .
|
||||||
@ -287,7 +279,7 @@ class LoginController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->request->setUser($user);
|
\Container::$request->setUser($user);
|
||||||
|
|
||||||
$this->deleteRedirectUrl();
|
$this->deleteRedirectUrl();
|
||||||
$data = ['redirect' => ['target' => $this->redirectUrl]];
|
$data = ['redirect' => ['target' => $this->redirectUrl]];
|
||||||
@ -303,32 +295,32 @@ class LoginController
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($_ENV['RECAPTCHA_SITEKEY'])) {
|
if (!empty($_ENV['RECAPTCHA_SITEKEY'])) {
|
||||||
if (!$this->request->post('g-recaptcha-response')) {
|
if (!\Container::$request->post('g-recaptcha-response')) {
|
||||||
return new JsonContent(['error' => ['errorText' => 'Please check "I\'m not a robot" in the reCAPTCHA box!']]);
|
return new JsonContent(['error' => ['errorText' => 'Please check "I\'m not a robot" in the reCAPTCHA box!']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$captchaValidator = new CaptchaValidator();
|
$captchaValidator = new CaptchaValidator();
|
||||||
$captchaResponse = $captchaValidator->validate($this->request->post('g-recaptcha-response'));
|
$captchaResponse = $captchaValidator->validate(\Container::$request->post('g-recaptcha-response'));
|
||||||
if (!$captchaResponse['success']) {
|
if (!$captchaResponse['success']) {
|
||||||
return new JsonContent(['error' => ['errorText' => 'reCAPTCHA challenge failed. Please try again!']]);
|
return new JsonContent(['error' => ['errorText' => 'reCAPTCHA challenge failed. Please try again!']]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter_var($this->request->post('email'), FILTER_VALIDATE_EMAIL) === false) {
|
if (filter_var(\Container::$request->post('email'), FILTER_VALIDATE_EMAIL) === false) {
|
||||||
return new JsonContent(['error' => ['errorText' => 'The given email address is not valid.']]);
|
return new JsonContent(['error' => ['errorText' => 'The given email address is not valid.']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->request->session()->has('tmp_user_data')) {
|
if (\Container::$request->session()->has('tmp_user_data')) {
|
||||||
$tmpUserData = $this->request->session()->get('tmp_user_data');
|
$tmpUserData = \Container::$request->session()->get('tmp_user_data');
|
||||||
|
|
||||||
$tmpUser = new User();
|
$tmpUser = new User();
|
||||||
$tmpUser->setPassword($tmpUserData['password_hashed']);
|
$tmpUser->setPassword($tmpUserData['password_hashed']);
|
||||||
|
|
||||||
if (!$tmpUser->checkPassword($this->request->post('password'))) {
|
if (!$tmpUser->checkPassword(\Container::$request->post('password'))) {
|
||||||
return new JsonContent(['error' => ['errorText' => 'The given passwords do not match.']]);
|
return new JsonContent(['error' => ['errorText' => 'The given passwords do not match.']]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (strlen($this->request->post('password')) < 6) {
|
if (strlen(\Container::$request->post('password')) < 6) {
|
||||||
return new JsonContent([
|
return new JsonContent([
|
||||||
'error' => [
|
'error' => [
|
||||||
'errorText' => 'The given password is too short. Please choose a password that is at least 6 characters long!'
|
'errorText' => 'The given password is too short. Please choose a password that is at least 6 characters long!'
|
||||||
@ -336,17 +328,17 @@ class LoginController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->request->post('password') !== $this->request->post('password_confirm')) {
|
if (\Container::$request->post('password') !== \Container::$request->post('password_confirm')) {
|
||||||
return new JsonContent(['error' => ['errorText' => 'The given passwords do not match.']]);
|
return new JsonContent(['error' => ['errorText' => 'The given passwords do not match.']]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = new User();
|
$user = new User();
|
||||||
$user->setEmail($this->request->post('email'));
|
$user->setEmail(\Container::$request->post('email'));
|
||||||
$user->setPlainPassword($this->request->post('password'));
|
$user->setPlainPassword(\Container::$request->post('password'));
|
||||||
$user->setCreatedDate(new DateTime());
|
$user->setCreatedDate(new DateTime());
|
||||||
|
|
||||||
$this->pdm->saveToDb($user);
|
\Container::$persistentDataManager->saveToDb($user);
|
||||||
|
|
||||||
$token = bin2hex(random_bytes(16));
|
$token = bin2hex(random_bytes(16));
|
||||||
|
|
||||||
@ -355,23 +347,23 @@ class LoginController
|
|||||||
$confirmation->setToken($token);
|
$confirmation->setToken($token);
|
||||||
$confirmation->setLastSentDate(new DateTime());
|
$confirmation->setLastSentDate(new DateTime());
|
||||||
|
|
||||||
$this->pdm->saveToDb($confirmation);
|
\Container::$persistentDataManager->saveToDb($confirmation);
|
||||||
|
|
||||||
$this->sendConfirmationEmail($user->getEmail(), $token, $user->getCreatedDate());
|
$this->sendConfirmationEmail($user->getEmail(), $token, $user->getCreatedDate());
|
||||||
|
|
||||||
$this->request->session()->delete('tmp_user_data');
|
\Container::$request->session()->delete('tmp_user_data');
|
||||||
|
|
||||||
return new JsonContent(['success' => true]);
|
return new JsonContent(['success' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function signupWithGoogle(): IContent
|
public function signupWithGoogle(): IContent
|
||||||
{
|
{
|
||||||
if ($this->request->user() !== null) {
|
if (\Container::$request->user() !== null) {
|
||||||
$this->deleteRedirectUrl();
|
$this->deleteRedirectUrl();
|
||||||
return new JsonContent(['success' => true]);
|
return new JsonContent(['success' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$userData = $this->request->session()->get('google_user_data');
|
$userData = \Container::$request->session()->get('google_user_data');
|
||||||
|
|
||||||
$user = $this->userRepository->getByEmail($userData['email']);
|
$user = $this->userRepository->getByEmail($userData['email']);
|
||||||
|
|
||||||
@ -388,14 +380,14 @@ class LoginController
|
|||||||
$user->setActive(true);
|
$user->setActive(true);
|
||||||
$user->setGoogleSub($userData['sub']);
|
$user->setGoogleSub($userData['sub']);
|
||||||
|
|
||||||
$this->pdm->saveToDb($user);
|
\Container::$persistentDataManager->saveToDb($user);
|
||||||
|
|
||||||
if ($sendWelcomeEmail) {
|
if ($sendWelcomeEmail) {
|
||||||
$this->sendWelcomeEmail($user->getEmail());
|
$this->sendWelcomeEmail($user->getEmail());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->request->session()->delete('google_user_data');
|
\Container::$request->session()->delete('google_user_data');
|
||||||
$this->request->setUser($user);
|
\Container::$request->setUser($user);
|
||||||
|
|
||||||
$this->deleteRedirectUrl();
|
$this->deleteRedirectUrl();
|
||||||
return new JsonContent(['success' => true]);
|
return new JsonContent(['success' => true]);
|
||||||
@ -403,39 +395,39 @@ class LoginController
|
|||||||
|
|
||||||
public function resetSignup(): IContent
|
public function resetSignup(): IContent
|
||||||
{
|
{
|
||||||
$this->request->session()->delete('tmp_user_data');
|
\Container::$request->session()->delete('tmp_user_data');
|
||||||
|
|
||||||
return new JsonContent(['success' => true]);
|
return new JsonContent(['success' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resetGoogleSignup(): IContent
|
public function resetGoogleSignup(): IContent
|
||||||
{
|
{
|
||||||
$this->request->session()->delete('google_user_data');
|
\Container::$request->session()->delete('google_user_data');
|
||||||
|
|
||||||
return new JsonContent(['success' => true]);
|
return new JsonContent(['success' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function activate()
|
public function activate()
|
||||||
{
|
{
|
||||||
if ($this->request->user() !== null) {
|
if (\Container::$request->user() !== null) {
|
||||||
$this->deleteRedirectUrl();
|
$this->deleteRedirectUrl();
|
||||||
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
||||||
}
|
}
|
||||||
|
|
||||||
$confirmation = $this->userConfirmationRepository->getByToken(substr($this->request->query('token'), 0, 32));
|
$confirmation = $this->userConfirmationRepository->getByToken(substr(\Container::$request->query('token'), 0, 32));
|
||||||
|
|
||||||
if ($confirmation === null) {
|
if ($confirmation === null) {
|
||||||
return new HtmlContent('login/activate');
|
return new HtmlContent('login/activate');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pdm->deleteFromDb($confirmation);
|
\Container::$persistentDataManager->deleteFromDb($confirmation);
|
||||||
|
|
||||||
$user = $this->userRepository->getById($confirmation->getUserId());
|
$user = $this->userRepository->getById($confirmation->getUserId());
|
||||||
$user->setActive(true);
|
$user->setActive(true);
|
||||||
|
|
||||||
$this->pdm->saveToDb($user);
|
\Container::$persistentDataManager->saveToDb($user);
|
||||||
|
|
||||||
$this->request->setUser($user);
|
\Container::$request->setUser($user);
|
||||||
|
|
||||||
$this->deleteRedirectUrl();
|
$this->deleteRedirectUrl();
|
||||||
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
||||||
@ -443,33 +435,33 @@ class LoginController
|
|||||||
|
|
||||||
public function cancel()
|
public function cancel()
|
||||||
{
|
{
|
||||||
if ($this->request->user() !== null) {
|
if (\Container::$request->user() !== null) {
|
||||||
$this->deleteRedirectUrl();
|
$this->deleteRedirectUrl();
|
||||||
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
return new Redirect($this->redirectUrl, IRedirect::TEMPORARY);
|
||||||
}
|
}
|
||||||
|
|
||||||
$confirmation = $this->userConfirmationRepository->getByToken(substr($this->request->query('token'), 0, 32));
|
$confirmation = $this->userConfirmationRepository->getByToken(substr(\Container::$request->query('token'), 0, 32));
|
||||||
|
|
||||||
if ($confirmation === null) {
|
if ($confirmation === null) {
|
||||||
return new HtmlContent('login/cancel', ['success' => false]);
|
return new HtmlContent('login/cancel', ['success' => false]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pdm->deleteFromDb($confirmation);
|
\Container::$persistentDataManager->deleteFromDb($confirmation);
|
||||||
|
|
||||||
$user = $this->userRepository->getById($confirmation->getUserId());
|
$user = $this->userRepository->getById($confirmation->getUserId());
|
||||||
|
|
||||||
foreach ($this->userPlayedPlaceRepository->getAllByUser($user) as $userPlayedPlace) {
|
foreach ($this->userPlayedPlaceRepository->getAllByUser($user) as $userPlayedPlace) {
|
||||||
$this->pdm->deleteFromDb($userPlayedPlace);
|
\Container::$persistentDataManager->deleteFromDb($userPlayedPlace);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pdm->deleteFromDb($user);
|
\Container::$persistentDataManager->deleteFromDb($user);
|
||||||
|
|
||||||
return new HtmlContent('login/cancel', ['success' => true]);
|
return new HtmlContent('login/cancel', ['success' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function requestPasswordReset(): IContent
|
public function requestPasswordReset(): IContent
|
||||||
{
|
{
|
||||||
if ($this->request->user() !== null) {
|
if (\Container::$request->user() !== null) {
|
||||||
$this->deleteRedirectUrl();
|
$this->deleteRedirectUrl();
|
||||||
return new JsonContent([
|
return new JsonContent([
|
||||||
'redirect' => [
|
'redirect' => [
|
||||||
@ -479,18 +471,18 @@ class LoginController
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($_ENV['RECAPTCHA_SITEKEY'])) {
|
if (!empty($_ENV['RECAPTCHA_SITEKEY'])) {
|
||||||
if (!$this->request->post('g-recaptcha-response')) {
|
if (!\Container::$request->post('g-recaptcha-response')) {
|
||||||
return new JsonContent(['error' => ['errorText' => 'Please check "I\'m not a robot" in the reCAPTCHA box!']]);
|
return new JsonContent(['error' => ['errorText' => 'Please check "I\'m not a robot" in the reCAPTCHA box!']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$captchaValidator = new CaptchaValidator();
|
$captchaValidator = new CaptchaValidator();
|
||||||
$captchaResponse = $captchaValidator->validate($this->request->post('g-recaptcha-response'));
|
$captchaResponse = $captchaValidator->validate(\Container::$request->post('g-recaptcha-response'));
|
||||||
if (!$captchaResponse['success']) {
|
if (!$captchaResponse['success']) {
|
||||||
return new JsonContent(['error' => ['errorText' => 'reCAPTCHA challenge failed. Please try again!']]);
|
return new JsonContent(['error' => ['errorText' => 'reCAPTCHA challenge failed. Please try again!']]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->userRepository->getByEmail($this->request->post('email'));
|
$user = $this->userRepository->getByEmail(\Container::$request->post('email'));
|
||||||
|
|
||||||
if ($user === null) {
|
if ($user === null) {
|
||||||
return new JsonContent([
|
return new JsonContent([
|
||||||
@ -530,10 +522,10 @@ class LoginController
|
|||||||
$passwordResetter->setExpiresDate($expires);
|
$passwordResetter->setExpiresDate($expires);
|
||||||
|
|
||||||
if ($existingResetter !== null) {
|
if ($existingResetter !== null) {
|
||||||
$this->pdm->deleteFromDb($existingResetter);
|
\Container::$persistentDataManager->deleteFromDb($existingResetter);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pdm->saveToDb($passwordResetter);
|
\Container::$persistentDataManager->saveToDb($passwordResetter);
|
||||||
|
|
||||||
$this->sendPasswordResetEmail($user->getEmail(), $token, $expires);
|
$this->sendPasswordResetEmail($user->getEmail(), $token, $expires);
|
||||||
|
|
||||||
@ -543,7 +535,7 @@ class LoginController
|
|||||||
|
|
||||||
public function resetPassword(): IContent
|
public function resetPassword(): IContent
|
||||||
{
|
{
|
||||||
if ($this->request->user() !== null) {
|
if (\Container::$request->user() !== null) {
|
||||||
$this->deleteRedirectUrl();
|
$this->deleteRedirectUrl();
|
||||||
return new JsonContent([
|
return new JsonContent([
|
||||||
'redirect' => [
|
'redirect' => [
|
||||||
@ -552,7 +544,7 @@ class LoginController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$token = $this->request->query('token');
|
$token = \Container::$request->query('token');
|
||||||
$resetter = $this->userPasswordResetterRepository->getByToken($token);
|
$resetter = $this->userPasswordResetterRepository->getByToken($token);
|
||||||
|
|
||||||
if ($resetter === null || $resetter->getExpiresDate() < new DateTime()) {
|
if ($resetter === null || $resetter->getExpiresDate() < new DateTime()) {
|
||||||
@ -563,7 +555,7 @@ class LoginController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($this->request->post('password')) < 6) {
|
if (strlen(\Container::$request->post('password')) < 6) {
|
||||||
return new JsonContent([
|
return new JsonContent([
|
||||||
'error' => [
|
'error' => [
|
||||||
'errorText' => 'The given password is too short. Please choose a password that is at least 6 characters long!'
|
'errorText' => 'The given password is too short. Please choose a password that is at least 6 characters long!'
|
||||||
@ -571,18 +563,18 @@ class LoginController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->request->post('password') !== $this->request->post('password_confirm')) {
|
if (\Container::$request->post('password') !== \Container::$request->post('password_confirm')) {
|
||||||
return new JsonContent(['error' => ['errorText' => 'The given passwords do not match.']]);
|
return new JsonContent(['error' => ['errorText' => 'The given passwords do not match.']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pdm->deleteFromDb($resetter);
|
\Container::$persistentDataManager->deleteFromDb($resetter);
|
||||||
|
|
||||||
$user = $this->userRepository->getById($resetter->getUserId());
|
$user = $this->userRepository->getById($resetter->getUserId());
|
||||||
$user->setPlainPassword($this->request->post('password'));
|
$user->setPlainPassword(\Container::$request->post('password'));
|
||||||
|
|
||||||
$this->pdm->saveToDb($user);
|
\Container::$persistentDataManager->saveToDb($user);
|
||||||
|
|
||||||
$this->request->setUser($user);
|
\Container::$request->setUser($user);
|
||||||
|
|
||||||
$this->deleteRedirectUrl();
|
$this->deleteRedirectUrl();
|
||||||
return new JsonContent(['success' => true]);
|
return new JsonContent(['success' => true]);
|
||||||
@ -595,9 +587,9 @@ class LoginController
|
|||||||
$mail->setSubject('Welcome to ' . $_ENV['APP_NAME'] . ' - Activate your account');
|
$mail->setSubject('Welcome to ' . $_ENV['APP_NAME'] . ' - Activate your account');
|
||||||
$mail->setBodyFromTemplate('signup', [
|
$mail->setBodyFromTemplate('signup', [
|
||||||
'EMAIL' => $email,
|
'EMAIL' => $email,
|
||||||
'ACTIVATE_LINK' => $this->request->getBase() .
|
'ACTIVATE_LINK' => \Container::$request->getBase() .
|
||||||
\Container::$routeCollection->getRoute('signup.activate')->generateLink(['token' => $token]),
|
\Container::$routeCollection->getRoute('signup.activate')->generateLink(['token' => $token]),
|
||||||
'CANCEL_LINK' => $this->request->getBase() .
|
'CANCEL_LINK' => \Container::$request->getBase() .
|
||||||
\Container::$routeCollection->getRoute('signup.cancel')->generateLink(['token' => $token]),
|
\Container::$routeCollection->getRoute('signup.cancel')->generateLink(['token' => $token]),
|
||||||
'ACTIVATABLE_UNTIL' => (clone $created)->add(new DateInterval('P1D'))->format('Y-m-d H:i T')
|
'ACTIVATABLE_UNTIL' => (clone $created)->add(new DateInterval('P1D'))->format('Y-m-d H:i T')
|
||||||
]);
|
]);
|
||||||
@ -614,7 +606,7 @@ class LoginController
|
|||||||
|
|
||||||
$confirmation->setLastSentDate(new DateTime());
|
$confirmation->setLastSentDate(new DateTime());
|
||||||
|
|
||||||
$this->pdm->saveToDb($confirmation);
|
\Container::$persistentDataManager->saveToDb($confirmation);
|
||||||
|
|
||||||
$this->sendConfirmationEmail($user->getEmail(), $confirmation->getToken(), $user->getCreatedDate());
|
$this->sendConfirmationEmail($user->getEmail(), $confirmation->getToken(), $user->getCreatedDate());
|
||||||
|
|
||||||
@ -639,7 +631,7 @@ class LoginController
|
|||||||
$mail->setSubject($_ENV['APP_NAME'] . ' - Password reset');
|
$mail->setSubject($_ENV['APP_NAME'] . ' - Password reset');
|
||||||
$mail->setBodyFromTemplate('password-reset', [
|
$mail->setBodyFromTemplate('password-reset', [
|
||||||
'EMAIL' => $email,
|
'EMAIL' => $email,
|
||||||
'RESET_LINK' => $this->request->getBase() .
|
'RESET_LINK' => \Container::$request->getBase() .
|
||||||
\Container::$routeCollection->getRoute('password-reset')->generateLink(['token' => $token]),
|
\Container::$routeCollection->getRoute('password-reset')->generateLink(['token' => $token]),
|
||||||
'EXPIRES' => $expires->format('Y-m-d H:i T')
|
'EXPIRES' => $expires->format('Y-m-d H:i T')
|
||||||
]);
|
]);
|
||||||
@ -648,6 +640,6 @@ class LoginController
|
|||||||
|
|
||||||
private function deleteRedirectUrl(): void
|
private function deleteRedirectUrl(): void
|
||||||
{
|
{
|
||||||
$this->request->session()->delete('redirect_after_login');
|
\Container::$request->session()->delete('redirect_after_login');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,11 @@ use DateTime;
|
|||||||
use SokoWeb\Interfaces\Authentication\IUser;
|
use SokoWeb\Interfaces\Authentication\IUser;
|
||||||
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
|
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
|
||||||
use SokoWeb\Interfaces\Authorization\ISecured;
|
use SokoWeb\Interfaces\Authorization\ISecured;
|
||||||
use SokoWeb\Interfaces\Request\IRequest;
|
|
||||||
use SokoWeb\Interfaces\Response\IContent;
|
use SokoWeb\Interfaces\Response\IContent;
|
||||||
use MapGuesser\PersistentData\Model\Challenge;
|
use MapGuesser\PersistentData\Model\Challenge;
|
||||||
use MapGuesser\PersistentData\Model\Map;
|
use MapGuesser\PersistentData\Model\Map;
|
||||||
use MapGuesser\PersistentData\Model\Place;
|
use MapGuesser\PersistentData\Model\Place;
|
||||||
use MapGuesser\PersistentData\Model\PlaceInChallenge;
|
use MapGuesser\PersistentData\Model\PlaceInChallenge;
|
||||||
use SokoWeb\PersistentData\PersistentDataManager;
|
|
||||||
use MapGuesser\Repository\ChallengeRepository;
|
use MapGuesser\Repository\ChallengeRepository;
|
||||||
use MapGuesser\Repository\GuessRepository;
|
use MapGuesser\Repository\GuessRepository;
|
||||||
use MapGuesser\Repository\MapRepository;
|
use MapGuesser\Repository\MapRepository;
|
||||||
@ -27,10 +25,6 @@ class MapAdminController implements IAuthenticationRequired, ISecured
|
|||||||
{
|
{
|
||||||
private static string $unnamedMapName = '[unnamed map]';
|
private static string $unnamedMapName = '[unnamed map]';
|
||||||
|
|
||||||
private IRequest $request;
|
|
||||||
|
|
||||||
private PersistentDataManager $pdm;
|
|
||||||
|
|
||||||
private MapRepository $mapRepository;
|
private MapRepository $mapRepository;
|
||||||
|
|
||||||
private PlaceRepository $placeRepository;
|
private PlaceRepository $placeRepository;
|
||||||
@ -45,10 +39,8 @@ class MapAdminController implements IAuthenticationRequired, ISecured
|
|||||||
|
|
||||||
private UserInChallengeRepository $userInChallengeRepository;
|
private UserInChallengeRepository $userInChallengeRepository;
|
||||||
|
|
||||||
public function __construct(IRequest $request)
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->request = $request;
|
|
||||||
$this->pdm = new PersistentDataManager();
|
|
||||||
$this->mapRepository = new MapRepository();
|
$this->mapRepository = new MapRepository();
|
||||||
$this->placeRepository = new PlaceRepository();
|
$this->placeRepository = new PlaceRepository();
|
||||||
$this->userPlayedPlaceRepository = new UserPlayedPlaceRepository();
|
$this->userPlayedPlaceRepository = new UserPlayedPlaceRepository();
|
||||||
@ -65,12 +57,12 @@ class MapAdminController implements IAuthenticationRequired, ISecured
|
|||||||
|
|
||||||
public function authorize(): bool
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
return $this->request->user()->hasPermission(IUser::PERMISSION_ADMIN);
|
return \Container::$request->user()->hasPermission(IUser::PERMISSION_ADMIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMapEditor(): IContent
|
public function getMapEditor(): IContent
|
||||||
{
|
{
|
||||||
$mapId = (int) $this->request->query('mapId');
|
$mapId = (int) \Container::$request->query('mapId');
|
||||||
|
|
||||||
if ($mapId) {
|
if ($mapId) {
|
||||||
$map = $this->mapRepository->getById($mapId);
|
$map = $this->mapRepository->getById($mapId);
|
||||||
@ -93,7 +85,7 @@ class MapAdminController implements IAuthenticationRequired, ISecured
|
|||||||
|
|
||||||
public function getPlace(): IContent
|
public function getPlace(): IContent
|
||||||
{
|
{
|
||||||
$placeId = (int) $this->request->query('placeId');
|
$placeId = (int) \Container::$request->query('placeId');
|
||||||
|
|
||||||
$place = $this->placeRepository->getById($placeId);
|
$place = $this->placeRepository->getById($placeId);
|
||||||
|
|
||||||
@ -102,14 +94,14 @@ class MapAdminController implements IAuthenticationRequired, ISecured
|
|||||||
|
|
||||||
public function saveMap(): IContent
|
public function saveMap(): IContent
|
||||||
{
|
{
|
||||||
$mapId = (int) $this->request->query('mapId');
|
$mapId = (int) \Container::$request->query('mapId');
|
||||||
|
|
||||||
if ($mapId) {
|
if ($mapId) {
|
||||||
$map = $this->mapRepository->getById($mapId);
|
$map = $this->mapRepository->getById($mapId);
|
||||||
} else {
|
} else {
|
||||||
$map = new Map();
|
$map = new Map();
|
||||||
$map->setName(self::$unnamedMapName);
|
$map->setName(self::$unnamedMapName);
|
||||||
$this->pdm->saveToDb($map);
|
\Container::$persistentDataManager->saveToDb($map);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_POST['added'])) {
|
if (isset($_POST['added'])) {
|
||||||
@ -131,7 +123,7 @@ class MapAdminController implements IAuthenticationRequired, ISecured
|
|||||||
$place->setPanoIdCachedTimestampDate(new DateTime('-1 day'));
|
$place->setPanoIdCachedTimestampDate(new DateTime('-1 day'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pdm->saveToDb($place);
|
\Container::$persistentDataManager->saveToDb($place);
|
||||||
|
|
||||||
$addedIds[] = ['tempId' => $placeRaw['id'], 'id' => $place->getId()];
|
$addedIds[] = ['tempId' => $placeRaw['id'], 'id' => $place->getId()];
|
||||||
}
|
}
|
||||||
@ -153,7 +145,7 @@ class MapAdminController implements IAuthenticationRequired, ISecured
|
|||||||
));
|
));
|
||||||
$place->setPanoIdCachedTimestampDate(new DateTime('-1 day'));
|
$place->setPanoIdCachedTimestampDate(new DateTime('-1 day'));
|
||||||
|
|
||||||
$this->pdm->saveToDb($place);
|
\Container::$persistentDataManager->saveToDb($place);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,20 +174,20 @@ class MapAdminController implements IAuthenticationRequired, ISecured
|
|||||||
$map->setUnlisted((bool)$_POST['unlisted']);
|
$map->setUnlisted((bool)$_POST['unlisted']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pdm->saveToDb($map);
|
\Container::$persistentDataManager->saveToDb($map);
|
||||||
|
|
||||||
return new JsonContent(['mapId' => $map->getId(), 'added' => $addedIds]);
|
return new JsonContent(['mapId' => $map->getId(), 'added' => $addedIds]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteMap(): IContent
|
public function deleteMap(): IContent
|
||||||
{
|
{
|
||||||
$mapId = (int) $this->request->query('mapId');
|
$mapId = (int) \Container::$request->query('mapId');
|
||||||
|
|
||||||
$map = $this->mapRepository->getById($mapId);
|
$map = $this->mapRepository->getById($mapId);
|
||||||
|
|
||||||
$this->deletePlaces($map);
|
$this->deletePlaces($map);
|
||||||
|
|
||||||
$this->pdm->deleteFromDb($map);
|
\Container::$persistentDataManager->deleteFromDb($map);
|
||||||
|
|
||||||
return new JsonContent(['success' => true]);
|
return new JsonContent(['success' => true]);
|
||||||
}
|
}
|
||||||
@ -203,14 +195,14 @@ class MapAdminController implements IAuthenticationRequired, ISecured
|
|||||||
private function deletePlace(Place $place): void
|
private function deletePlace(Place $place): void
|
||||||
{
|
{
|
||||||
foreach ($this->userPlayedPlaceRepository->getAllByPlace($place) as $userPlayedPlace) {
|
foreach ($this->userPlayedPlaceRepository->getAllByPlace($place) as $userPlayedPlace) {
|
||||||
$this->pdm->deleteFromDb($userPlayedPlace);
|
\Container::$persistentDataManager->deleteFromDb($userPlayedPlace);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->challengeRepository->getAllByPlace($place) as $challenge) {
|
foreach ($this->challengeRepository->getAllByPlace($place) as $challenge) {
|
||||||
$this->deleteChallenge($challenge);
|
$this->deleteChallenge($challenge);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pdm->deleteFromDb($place);
|
\Container::$persistentDataManager->deleteFromDb($place);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function deletePlaces(Map $map): void
|
private function deletePlaces(Map $map): void
|
||||||
@ -223,18 +215,18 @@ class MapAdminController implements IAuthenticationRequired, ISecured
|
|||||||
private function deleteChallenge(Challenge $challenge): void
|
private function deleteChallenge(Challenge $challenge): void
|
||||||
{
|
{
|
||||||
foreach ($this->userInChallengeRepository->getAllByChallenge($challenge) as $userInChallenge) {
|
foreach ($this->userInChallengeRepository->getAllByChallenge($challenge) as $userInChallenge) {
|
||||||
$this->pdm->deleteFromDb($userInChallenge);
|
\Container::$persistentDataManager->deleteFromDb($userInChallenge);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->guessRepository->getAllInChallenge($challenge, [PlaceInChallenge::class]) as $guess) {
|
foreach ($this->guessRepository->getAllInChallenge($challenge, [PlaceInChallenge::class]) as $guess) {
|
||||||
$this->pdm->deleteFromDb($guess);
|
\Container::$persistentDataManager->deleteFromDb($guess);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->placeInChallengeRepository->getAllByChallenge($challenge) as $placeInChallenge) {
|
foreach ($this->placeInChallengeRepository->getAllByChallenge($challenge) as $placeInChallenge) {
|
||||||
$this->pdm->deleteFromDb($placeInChallenge);
|
\Container::$persistentDataManager->deleteFromDb($placeInChallenge);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pdm->deleteFromDb($challenge);
|
\Container::$persistentDataManager->deleteFromDb($challenge);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function calculateMapBounds(Map $map): Bounds
|
private function calculateMapBounds(Map $map): Bounds
|
||||||
|
@ -4,19 +4,11 @@ use SokoWeb\Database\Query\Select;
|
|||||||
use SokoWeb\Database\RawExpression;
|
use SokoWeb\Database\RawExpression;
|
||||||
use SokoWeb\Interfaces\Authentication\IUser;
|
use SokoWeb\Interfaces\Authentication\IUser;
|
||||||
use SokoWeb\Interfaces\Database\IResultSet;
|
use SokoWeb\Interfaces\Database\IResultSet;
|
||||||
use SokoWeb\Interfaces\Request\IRequest;
|
|
||||||
use SokoWeb\Interfaces\Response\IContent;
|
use SokoWeb\Interfaces\Response\IContent;
|
||||||
use SokoWeb\Response\HtmlContent;
|
use SokoWeb\Response\HtmlContent;
|
||||||
|
|
||||||
class MapsController
|
class MapsController
|
||||||
{
|
{
|
||||||
private IRequest $request;
|
|
||||||
|
|
||||||
public function __construct(IRequest $request)
|
|
||||||
{
|
|
||||||
$this->request = $request;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMaps(): IContent
|
public function getMaps(): IContent
|
||||||
{
|
{
|
||||||
//TODO: from repository - count should be added
|
//TODO: from repository - count should be added
|
||||||
@ -37,7 +29,7 @@ class MapsController
|
|||||||
$select->groupBy(['maps', 'id']);
|
$select->groupBy(['maps', 'id']);
|
||||||
$select->orderBy('name');
|
$select->orderBy('name');
|
||||||
|
|
||||||
$user = $this->request->user();
|
$user = \Container::$request->user();
|
||||||
$isAdmin = $user !== null && $user->hasPermission(IUser::PERMISSION_ADMIN);
|
$isAdmin = $user !== null && $user->hasPermission(IUser::PERMISSION_ADMIN);
|
||||||
if (!$isAdmin) {
|
if (!$isAdmin) {
|
||||||
$select->where(['maps', 'unlisted'], '=', false);
|
$select->where(['maps', 'unlisted'], '=', false);
|
||||||
|
@ -3,11 +3,9 @@
|
|||||||
use DateTime;
|
use DateTime;
|
||||||
use SokoWeb\Http\Request;
|
use SokoWeb\Http\Request;
|
||||||
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
|
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
|
||||||
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;
|
||||||
use SokoWeb\OAuth\GoogleOAuth;
|
use SokoWeb\OAuth\GoogleOAuth;
|
||||||
use SokoWeb\PersistentData\PersistentDataManager;
|
|
||||||
use MapGuesser\PersistentData\Model\User;
|
use MapGuesser\PersistentData\Model\User;
|
||||||
use MapGuesser\Repository\GuessRepository;
|
use MapGuesser\Repository\GuessRepository;
|
||||||
use MapGuesser\Repository\UserConfirmationRepository;
|
use MapGuesser\Repository\UserConfirmationRepository;
|
||||||
@ -21,10 +19,6 @@ use SokoWeb\Util\JwtParser;
|
|||||||
|
|
||||||
class UserController implements IAuthenticationRequired
|
class UserController implements IAuthenticationRequired
|
||||||
{
|
{
|
||||||
private IRequest $request;
|
|
||||||
|
|
||||||
private PersistentDataManager $pdm;
|
|
||||||
|
|
||||||
private UserConfirmationRepository $userConfirmationRepository;
|
private UserConfirmationRepository $userConfirmationRepository;
|
||||||
|
|
||||||
private UserPasswordResetterRepository $userPasswordResetterRepository;
|
private UserPasswordResetterRepository $userPasswordResetterRepository;
|
||||||
@ -35,10 +29,8 @@ class UserController implements IAuthenticationRequired
|
|||||||
|
|
||||||
private GuessRepository $guessRepository;
|
private GuessRepository $guessRepository;
|
||||||
|
|
||||||
public function __construct(IRequest $request)
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->request = $request;
|
|
||||||
$this->pdm = new PersistentDataManager();
|
|
||||||
$this->userConfirmationRepository = new UserConfirmationRepository();
|
$this->userConfirmationRepository = new UserConfirmationRepository();
|
||||||
$this->userPasswordResetterRepository = new UserPasswordResetterRepository();
|
$this->userPasswordResetterRepository = new UserPasswordResetterRepository();
|
||||||
$this->userPlayedPlaceRepository = new UserPlayedPlaceRepository();
|
$this->userPlayedPlaceRepository = new UserPlayedPlaceRepository();
|
||||||
@ -56,7 +48,7 @@ class UserController implements IAuthenticationRequired
|
|||||||
/**
|
/**
|
||||||
* @var User $user
|
* @var User $user
|
||||||
*/
|
*/
|
||||||
$user = $this->request->user();
|
$user = \Container::$request->user();
|
||||||
|
|
||||||
return new HtmlContent('account/account', ['user' => $user->toArray()]);
|
return new HtmlContent('account/account', ['user' => $user->toArray()]);
|
||||||
}
|
}
|
||||||
@ -66,19 +58,19 @@ class UserController implements IAuthenticationRequired
|
|||||||
/**
|
/**
|
||||||
* @var User $user
|
* @var User $user
|
||||||
*/
|
*/
|
||||||
$user = $this->request->user();
|
$user = \Container::$request->user();
|
||||||
|
|
||||||
$state = bin2hex(random_bytes(16));
|
$state = bin2hex(random_bytes(16));
|
||||||
$nonce = bin2hex(random_bytes(16));
|
$nonce = bin2hex(random_bytes(16));
|
||||||
|
|
||||||
$this->request->session()->set('oauth_state', $state);
|
\Container::$request->session()->set('oauth_state', $state);
|
||||||
$this->request->session()->set('oauth_nonce', $nonce);
|
\Container::$request->session()->set('oauth_nonce', $nonce);
|
||||||
|
|
||||||
$oAuth = new GoogleOAuth(new Request());
|
$oAuth = new GoogleOAuth(new Request());
|
||||||
|
|
||||||
$url = $oAuth->getDialogUrl(
|
$url = $oAuth->getDialogUrl(
|
||||||
$state,
|
$state,
|
||||||
$this->request->getBase() . \Container::$routeCollection->getRoute('account.googleAuthenticate-action')->generateLink(),
|
\Container::$request->getBase() . \Container::$routeCollection->getRoute('account.googleAuthenticate-action')->generateLink(),
|
||||||
$nonce,
|
$nonce,
|
||||||
$user->getEmail()
|
$user->getEmail()
|
||||||
);
|
);
|
||||||
@ -91,16 +83,16 @@ class UserController implements IAuthenticationRequired
|
|||||||
/**
|
/**
|
||||||
* @var User $user
|
* @var User $user
|
||||||
*/
|
*/
|
||||||
$user = $this->request->user();
|
$user = \Container::$request->user();
|
||||||
|
|
||||||
if ($this->request->query('state') !== $this->request->session()->get('oauth_state')) {
|
if (\Container::$request->query('state') !== \Container::$request->session()->get('oauth_state')) {
|
||||||
return new HtmlContent('account/google_authenticate', ['success' => false]);
|
return new HtmlContent('account/google_authenticate', ['success' => false]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$oAuth = new GoogleOAuth(new Request());
|
$oAuth = new GoogleOAuth(new Request());
|
||||||
$tokenData = $oAuth->getToken(
|
$tokenData = $oAuth->getToken(
|
||||||
$this->request->query('code'),
|
\Container::$request->query('code'),
|
||||||
$this->request->getBase() . \Container::$routeCollection->getRoute('account.googleAuthenticate-action')->generateLink()
|
\Container::$request->getBase() . \Container::$routeCollection->getRoute('account.googleAuthenticate-action')->generateLink()
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!isset($tokenData['id_token'])) {
|
if (!isset($tokenData['id_token'])) {
|
||||||
@ -110,7 +102,7 @@ class UserController implements IAuthenticationRequired
|
|||||||
$jwtParser = new JwtParser($tokenData['id_token']);
|
$jwtParser = new JwtParser($tokenData['id_token']);
|
||||||
$idToken = $jwtParser->getPayload();
|
$idToken = $jwtParser->getPayload();
|
||||||
|
|
||||||
if ($idToken['nonce'] !== $this->request->session()->get('oauth_nonce')) {
|
if ($idToken['nonce'] !== \Container::$request->session()->get('oauth_nonce')) {
|
||||||
return new HtmlContent('account/google_authenticate', ['success' => false]);
|
return new HtmlContent('account/google_authenticate', ['success' => false]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +114,7 @@ class UserController implements IAuthenticationRequired
|
|||||||
}
|
}
|
||||||
|
|
||||||
$authenticatedWithGoogleUntil = new DateTime('+45 seconds');
|
$authenticatedWithGoogleUntil = new DateTime('+45 seconds');
|
||||||
$this->request->session()->set('authenticated_with_google_until', $authenticatedWithGoogleUntil);
|
\Container::$request->session()->set('authenticated_with_google_until', $authenticatedWithGoogleUntil);
|
||||||
|
|
||||||
return new HtmlContent('account/google_authenticate', [
|
return new HtmlContent('account/google_authenticate', [
|
||||||
'success' => true,
|
'success' => true,
|
||||||
@ -135,7 +127,7 @@ class UserController implements IAuthenticationRequired
|
|||||||
/**
|
/**
|
||||||
* @var User $user
|
* @var User $user
|
||||||
*/
|
*/
|
||||||
$user = $this->request->user();
|
$user = \Container::$request->user();
|
||||||
|
|
||||||
return new HtmlContent('account/delete', ['user' => $user->toArray()]);
|
return new HtmlContent('account/delete', ['user' => $user->toArray()]);
|
||||||
}
|
}
|
||||||
@ -145,19 +137,19 @@ class UserController implements IAuthenticationRequired
|
|||||||
/**
|
/**
|
||||||
* @var User $user
|
* @var User $user
|
||||||
*/
|
*/
|
||||||
$user = $this->request->user();
|
$user = \Container::$request->user();
|
||||||
|
|
||||||
if (!$this->confirmUserIdentity(
|
if (!$this->confirmUserIdentity(
|
||||||
$user,
|
$user,
|
||||||
$this->request->session()->get('authenticated_with_google_until'),
|
\Container::$request->session()->get('authenticated_with_google_until'),
|
||||||
$this->request->post('password'),
|
\Container::$request->post('password'),
|
||||||
$error
|
$error
|
||||||
)) {
|
)) {
|
||||||
return new JsonContent(['error' => ['errorText' => $error]]);
|
return new JsonContent(['error' => ['errorText' => $error]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($this->request->post('password_new')) > 0) {
|
if (strlen(\Container::$request->post('password_new')) > 0) {
|
||||||
if (strlen($this->request->post('password_new')) < 6) {
|
if (strlen(\Container::$request->post('password_new')) < 6) {
|
||||||
return new JsonContent([
|
return new JsonContent([
|
||||||
'error' => [
|
'error' => [
|
||||||
'errorText' => 'The given new password is too short. Please choose a password that is at least 6 characters long!'
|
'errorText' => 'The given new password is too short. Please choose a password that is at least 6 characters long!'
|
||||||
@ -165,7 +157,7 @@ class UserController implements IAuthenticationRequired
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->request->post('password_new') !== $this->request->post('password_new_confirm')) {
|
if (\Container::$request->post('password_new') !== \Container::$request->post('password_new_confirm')) {
|
||||||
return new JsonContent([
|
return new JsonContent([
|
||||||
'error' => [
|
'error' => [
|
||||||
'errorText' => 'The given new passwords do not match.'
|
'errorText' => 'The given new passwords do not match.'
|
||||||
@ -173,12 +165,12 @@ class UserController implements IAuthenticationRequired
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$user->setPlainPassword($this->request->post('password_new'));
|
$user->setPlainPassword(\Container::$request->post('password_new'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pdm->saveToDb($user);
|
\Container::$persistentDataManager->saveToDb($user);
|
||||||
|
|
||||||
$this->request->session()->delete('authenticated_with_google_until');
|
\Container::$request->session()->delete('authenticated_with_google_until');
|
||||||
|
|
||||||
return new JsonContent(['success' => true]);
|
return new JsonContent(['success' => true]);
|
||||||
}
|
}
|
||||||
@ -188,12 +180,12 @@ class UserController implements IAuthenticationRequired
|
|||||||
/**
|
/**
|
||||||
* @var User $user
|
* @var User $user
|
||||||
*/
|
*/
|
||||||
$user = $this->request->user();
|
$user = \Container::$request->user();
|
||||||
|
|
||||||
if (!$this->confirmUserIdentity(
|
if (!$this->confirmUserIdentity(
|
||||||
$user,
|
$user,
|
||||||
$this->request->session()->get('authenticated_with_google_until'),
|
\Container::$request->session()->get('authenticated_with_google_until'),
|
||||||
$this->request->post('password'),
|
\Container::$request->post('password'),
|
||||||
$error
|
$error
|
||||||
)) {
|
)) {
|
||||||
return new JsonContent(['error' => ['errorText' => $error]]);
|
return new JsonContent(['error' => ['errorText' => $error]]);
|
||||||
@ -201,29 +193,29 @@ class UserController implements IAuthenticationRequired
|
|||||||
|
|
||||||
$userConfirmation = $this->userConfirmationRepository->getByUser($user);
|
$userConfirmation = $this->userConfirmationRepository->getByUser($user);
|
||||||
if ($userConfirmation !== null) {
|
if ($userConfirmation !== null) {
|
||||||
$this->pdm->deleteFromDb($userConfirmation);
|
\Container::$persistentDataManager->deleteFromDb($userConfirmation);
|
||||||
}
|
}
|
||||||
|
|
||||||
$userPasswordResetter = $this->userPasswordResetterRepository->getByUser($user);
|
$userPasswordResetter = $this->userPasswordResetterRepository->getByUser($user);
|
||||||
if ($userPasswordResetter !== null) {
|
if ($userPasswordResetter !== null) {
|
||||||
$this->pdm->deleteFromDb($userPasswordResetter);
|
\Container::$persistentDataManager->deleteFromDb($userPasswordResetter);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->userPlayedPlaceRepository->getAllByUser($user) as $userPlayedPlace) {
|
foreach ($this->userPlayedPlaceRepository->getAllByUser($user) as $userPlayedPlace) {
|
||||||
$this->pdm->deleteFromDb($userPlayedPlace);
|
\Container::$persistentDataManager->deleteFromDb($userPlayedPlace);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->userInChallengeRepository->getAllByUser($user) as $userInChallenge) {
|
foreach ($this->userInChallengeRepository->getAllByUser($user) as $userInChallenge) {
|
||||||
$this->pdm->deleteFromDb($userInChallenge);
|
\Container::$persistentDataManager->deleteFromDb($userInChallenge);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->guessRepository->getAllByUser($user) as $guess) {
|
foreach ($this->guessRepository->getAllByUser($user) as $guess) {
|
||||||
$this->pdm->deleteFromDb($guess);
|
\Container::$persistentDataManager->deleteFromDb($guess);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pdm->deleteFromDb($user);
|
\Container::$persistentDataManager->deleteFromDb($user);
|
||||||
|
|
||||||
$this->request->session()->delete('authenticated_with_google_until');
|
\Container::$request->session()->delete('authenticated_with_google_until');
|
||||||
|
|
||||||
return new JsonContent(['success' => true]);
|
return new JsonContent(['success' => true]);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ use DateInterval;
|
|||||||
use DateTime;
|
use DateTime;
|
||||||
use SokoWeb\PersistentData\Model\Model;
|
use SokoWeb\PersistentData\Model\Model;
|
||||||
use SokoWeb\Http\Request;
|
use SokoWeb\Http\Request;
|
||||||
use SokoWeb\PersistentData\PersistentDataManager;
|
|
||||||
use MapGuesser\Util\Geo\Position;
|
use MapGuesser\Util\Geo\Position;
|
||||||
use MapGuesser\Util\Panorama\Pov;
|
use MapGuesser\Util\Panorama\Pov;
|
||||||
|
|
||||||
@ -163,7 +162,7 @@ class Place extends Model
|
|||||||
$this->panoIdCached = $panoId;
|
$this->panoIdCached = $panoId;
|
||||||
$this->panoIdCachedTimestamp = new DateTime();
|
$this->panoIdCachedTimestamp = new DateTime();
|
||||||
|
|
||||||
(new PersistentDataManager())->saveToDb($this);
|
\Container::$persistentDataManager->saveToDb($this);
|
||||||
|
|
||||||
return $panoId;
|
return $panoId;
|
||||||
}
|
}
|
||||||
|
@ -5,20 +5,12 @@ use SokoWeb\Database\Query\Select;
|
|||||||
use MapGuesser\PersistentData\Model\Challenge;
|
use MapGuesser\PersistentData\Model\Challenge;
|
||||||
use MapGuesser\PersistentData\Model\Place;
|
use MapGuesser\PersistentData\Model\Place;
|
||||||
use MapGuesser\PersistentData\Model\User;
|
use MapGuesser\PersistentData\Model\User;
|
||||||
use SokoWeb\PersistentData\PersistentDataManager;
|
|
||||||
|
|
||||||
class ChallengeRepository
|
class ChallengeRepository
|
||||||
{
|
{
|
||||||
private PersistentDataManager $pdm;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->pdm = new PersistentDataManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getById(int $challengeId): ?Challenge
|
public function getById(int $challengeId): ?Challenge
|
||||||
{
|
{
|
||||||
return $this->pdm->selectFromDbById($challengeId, Challenge::class);
|
return \Container::$persistentDataManager->selectFromDbById($challengeId, Challenge::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getByToken(int $token): ?Challenge
|
public function getByToken(int $token): ?Challenge
|
||||||
@ -26,7 +18,7 @@ class ChallengeRepository
|
|||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->where('token', '=', $token);
|
$select->where('token', '=', $token);
|
||||||
|
|
||||||
return $this->pdm->selectFromDb($select, Challenge::class);
|
return \Container::$persistentDataManager->selectFromDb($select, Challenge::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getByTokenStr(string $token_str): ?Challenge
|
public function getByTokenStr(string $token_str): ?Challenge
|
||||||
@ -50,7 +42,7 @@ class ChallengeRepository
|
|||||||
$select->innerJoin('users', ['users', 'id'], '=', ['user_in_challenge', 'user_id']);
|
$select->innerJoin('users', ['users', 'id'], '=', ['user_in_challenge', 'user_id']);
|
||||||
$select->where('user_id', '=', $user->getId());
|
$select->where('user_id', '=', $user->getId());
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, Challenge::class);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, Challenge::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllByOwner(User $user): Generator
|
public function getAllByOwner(User $user): Generator
|
||||||
@ -61,7 +53,7 @@ class ChallengeRepository
|
|||||||
$select->where('user_id', '=', $user->getId());
|
$select->where('user_id', '=', $user->getId());
|
||||||
$select->where('is_owner', '=', true);
|
$select->where('is_owner', '=', true);
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, Challenge::class);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, Challenge::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllByPlace(Place $place): Generator
|
public function getAllByPlace(Place $place): Generator
|
||||||
@ -70,6 +62,6 @@ class ChallengeRepository
|
|||||||
$select->innerJoin('place_in_challenge', ['challenges', 'id'], '=', ['place_in_challenge', 'challenge_id']);
|
$select->innerJoin('place_in_challenge', ['challenges', 'id'], '=', ['place_in_challenge', 'challenge_id']);
|
||||||
$select->where('place_id', '=', $place->getId());
|
$select->where('place_id', '=', $place->getId());
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, Challenge::class);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, Challenge::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,23 +7,15 @@ use MapGuesser\PersistentData\Model\Guess;
|
|||||||
use MapGuesser\PersistentData\Model\User;
|
use MapGuesser\PersistentData\Model\User;
|
||||||
use MapGuesser\PersistentData\Model\Place;
|
use MapGuesser\PersistentData\Model\Place;
|
||||||
use MapGuesser\PersistentData\Model\PlaceInChallenge;
|
use MapGuesser\PersistentData\Model\PlaceInChallenge;
|
||||||
use SokoWeb\PersistentData\PersistentDataManager;
|
|
||||||
|
|
||||||
class GuessRepository
|
class GuessRepository
|
||||||
{
|
{
|
||||||
private PersistentDataManager $pdm;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->pdm = new PersistentDataManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAllByUser(User $user): Generator
|
public function getAllByUser(User $user): Generator
|
||||||
{
|
{
|
||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->where('user_id', '=', $user->getId());
|
$select->where('user_id', '=', $user->getId());
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, Guess::class);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, Guess::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllByUserAndChallenge(User $user, Challenge $challenge): Generator
|
public function getAllByUserAndChallenge(User $user, Challenge $challenge): Generator
|
||||||
@ -33,7 +25,7 @@ class GuessRepository
|
|||||||
$select->where('user_id', '=', $user->getId());
|
$select->where('user_id', '=', $user->getId());
|
||||||
$select->where('challenge_id', '=', $challenge->getId());
|
$select->where('challenge_id', '=', $challenge->getId());
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, Guess::class);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, Guess::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getByUserAndPlaceInChallenge(User $user, Challenge $challenge, Place $place): ?Guess
|
public function getByUserAndPlaceInChallenge(User $user, Challenge $challenge, Place $place): ?Guess
|
||||||
@ -44,7 +36,7 @@ class GuessRepository
|
|||||||
$select->where('challenge_id', '=', $challenge->getId());
|
$select->where('challenge_id', '=', $challenge->getId());
|
||||||
$select->where('place_id', '=', $place->getId());
|
$select->where('place_id', '=', $place->getId());
|
||||||
|
|
||||||
return $this->pdm->selectFromDb($select, Guess::class);
|
return \Container::$persistentDataManager->selectFromDb($select, Guess::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllInChallengeByUser(int $userId, Challenge $challenge): Generator
|
public function getAllInChallengeByUser(int $userId, Challenge $challenge): Generator
|
||||||
@ -55,7 +47,7 @@ class GuessRepository
|
|||||||
$select->where('challenge_id', '=', $challenge->getId());
|
$select->where('challenge_id', '=', $challenge->getId());
|
||||||
$select->orderBy('round');
|
$select->orderBy('round');
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, Guess::class);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, Guess::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllInChallenge(Challenge $challenge, array $withRelations = []): Generator
|
public function getAllInChallenge(Challenge $challenge, array $withRelations = []): Generator
|
||||||
@ -69,7 +61,7 @@ class GuessRepository
|
|||||||
$select->where('challenge_id', '=', $challenge->getId());
|
$select->where('challenge_id', '=', $challenge->getId());
|
||||||
$select->orderBy('round');
|
$select->orderBy('round');
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, Guess::class, true, $withRelations);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, Guess::class, true, $withRelations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllInChallengeByRound(int $round, Challenge $challenge, array $withRelations = []): Generator
|
public function getAllInChallengeByRound(int $round, Challenge $challenge, array $withRelations = []): Generator
|
||||||
@ -83,7 +75,7 @@ class GuessRepository
|
|||||||
$select->where('challenge_id', '=', $challenge->getId());
|
$select->where('challenge_id', '=', $challenge->getId());
|
||||||
$select->where('round', '=', $round);
|
$select->where('round', '=', $round);
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, Guess::class, true, $withRelations);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, Guess::class, true, $withRelations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllByPlace(Place $place): Generator
|
public function getAllByPlace(Place $place): Generator
|
||||||
@ -92,6 +84,6 @@ class GuessRepository
|
|||||||
$select->innerJoin('place_in_challenge', ['place_in_challenge', 'id'], '=', ['guesses', 'place_in_challenge_id']);
|
$select->innerJoin('place_in_challenge', ['place_in_challenge', 'id'], '=', ['guesses', 'place_in_challenge_id']);
|
||||||
$select->where('place_id', '=', $place->getId());
|
$select->where('place_id', '=', $place->getId());
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, Guess::class);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, Guess::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,20 +4,12 @@ use SokoWeb\Database\Query\Select;
|
|||||||
use MapGuesser\PersistentData\Model\Challenge;
|
use MapGuesser\PersistentData\Model\Challenge;
|
||||||
use MapGuesser\PersistentData\Model\Map;
|
use MapGuesser\PersistentData\Model\Map;
|
||||||
use MapGuesser\PersistentData\Model\Place;
|
use MapGuesser\PersistentData\Model\Place;
|
||||||
use SokoWeb\PersistentData\PersistentDataManager;
|
|
||||||
|
|
||||||
class MapRepository
|
class MapRepository
|
||||||
{
|
{
|
||||||
private PersistentDataManager $pdm;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->pdm = new PersistentDataManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getById(int $mapId): ?Map
|
public function getById(int $mapId): ?Map
|
||||||
{
|
{
|
||||||
return $this->pdm->selectFromDbById($mapId, Map::class);
|
return \Container::$persistentDataManager->selectFromDbById($mapId, Map::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getByPlace(Place $place): ?Map
|
public function getByPlace(Place $place): ?Map
|
||||||
@ -33,6 +25,6 @@ class MapRepository
|
|||||||
$select->where('challenge_id', '=', $challenge->getId());
|
$select->where('challenge_id', '=', $challenge->getId());
|
||||||
$select->limit(1);
|
$select->limit(1);
|
||||||
|
|
||||||
return $this->pdm->selectFromDb($select, Map::class);
|
return \Container::$persistentDataManager->selectFromDb($select, Map::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,20 +4,12 @@ use DateTime;
|
|||||||
use Generator;
|
use Generator;
|
||||||
use SokoWeb\Database\Query\Select;
|
use SokoWeb\Database\Query\Select;
|
||||||
use MapGuesser\PersistentData\Model\MultiRoom;
|
use MapGuesser\PersistentData\Model\MultiRoom;
|
||||||
use SokoWeb\PersistentData\PersistentDataManager;
|
|
||||||
|
|
||||||
class MultiRoomRepository
|
class MultiRoomRepository
|
||||||
{
|
{
|
||||||
private PersistentDataManager $pdm;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->pdm = new PersistentDataManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getById(int $id): ?MultiRoom
|
public function getById(int $id): ?MultiRoom
|
||||||
{
|
{
|
||||||
return $this->pdm->selectFromDbById($id, MultiRoom::class);
|
return \Container::$persistentDataManager->selectFromDbById($id, MultiRoom::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getByRoomId(string $roomId): ?MultiRoom
|
public function getByRoomId(string $roomId): ?MultiRoom
|
||||||
@ -25,7 +17,7 @@ class MultiRoomRepository
|
|||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->where('room_id', '=', $roomId);
|
$select->where('room_id', '=', $roomId);
|
||||||
|
|
||||||
return $this->pdm->selectFromDb($select, MultiRoom::class);
|
return \Container::$persistentDataManager->selectFromDb($select, MultiRoom::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllExpired(): Generator
|
public function getAllExpired(): Generator
|
||||||
@ -33,6 +25,6 @@ class MultiRoomRepository
|
|||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->where('updated', '<', (new DateTime('-7 day'))->format('Y-m-d H:i:s'));
|
$select->where('updated', '<', (new DateTime('-7 day'))->format('Y-m-d H:i:s'));
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, MultiRoom::class);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, MultiRoom::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,23 +5,15 @@ use SokoWeb\Database\Query\Select;
|
|||||||
use MapGuesser\PersistentData\Model\Challenge;
|
use MapGuesser\PersistentData\Model\Challenge;
|
||||||
use MapGuesser\PersistentData\Model\Place;
|
use MapGuesser\PersistentData\Model\Place;
|
||||||
use MapGuesser\PersistentData\Model\PlaceInChallenge;
|
use MapGuesser\PersistentData\Model\PlaceInChallenge;
|
||||||
use SokoWeb\PersistentData\PersistentDataManager;
|
|
||||||
|
|
||||||
class PlaceInChallengeRepository
|
class PlaceInChallengeRepository
|
||||||
{
|
{
|
||||||
private PersistentDataManager $pdm;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->pdm = new PersistentDataManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAllByPlace(Place $place, array $withRelations = []) : Generator
|
public function getAllByPlace(Place $place, array $withRelations = []) : Generator
|
||||||
{
|
{
|
||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->where('place_id', '=', $place->getId());
|
$select->where('place_id', '=', $place->getId());
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, PlaceInChallenge::class, true, $withRelations);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, PlaceInChallenge::class, true, $withRelations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllByChallenge(Challenge $challenge) : Generator
|
public function getAllByChallenge(Challenge $challenge) : Generator
|
||||||
@ -29,7 +21,7 @@ class PlaceInChallengeRepository
|
|||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->where('challenge_id', '=', $challenge->getId());
|
$select->where('challenge_id', '=', $challenge->getId());
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, PlaceInChallenge::class);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, PlaceInChallenge::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getByPlaceAndChallenge(Place $place, Challenge $challenge) : ?PlaceInChallenge
|
public function getByPlaceAndChallenge(Place $place, Challenge $challenge) : ?PlaceInChallenge
|
||||||
@ -38,7 +30,7 @@ class PlaceInChallengeRepository
|
|||||||
$select->where('place_id', '=', $place->getId());
|
$select->where('place_id', '=', $place->getId());
|
||||||
$select->where('challenge_id', '=', $challenge->getId());
|
$select->where('challenge_id', '=', $challenge->getId());
|
||||||
|
|
||||||
return $this->pdm->selectFromDb($select, PlaceInChallenge::class);
|
return \Container::$persistentDataManager->selectFromDb($select, PlaceInChallenge::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getByRoundInChallenge(int $round, Challenge $challenge, array $withRelations = []): ?PlaceInChallenge
|
public function getByRoundInChallenge(int $round, Challenge $challenge, array $withRelations = []): ?PlaceInChallenge
|
||||||
@ -48,6 +40,6 @@ class PlaceInChallengeRepository
|
|||||||
$select->orderBy('round');
|
$select->orderBy('round');
|
||||||
$select->limit(1, $round);
|
$select->limit(1, $round);
|
||||||
|
|
||||||
return $this->pdm->selectFromDb($select, PlaceInChallenge::class, true, $withRelations);
|
return \Container::$persistentDataManager->selectFromDb($select, PlaceInChallenge::class, true, $withRelations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,20 +5,12 @@ use SokoWeb\Database\Query\Select;
|
|||||||
use MapGuesser\PersistentData\Model\Challenge;
|
use MapGuesser\PersistentData\Model\Challenge;
|
||||||
use MapGuesser\PersistentData\Model\Map;
|
use MapGuesser\PersistentData\Model\Map;
|
||||||
use MapGuesser\PersistentData\Model\Place;
|
use MapGuesser\PersistentData\Model\Place;
|
||||||
use SokoWeb\PersistentData\PersistentDataManager;
|
|
||||||
|
|
||||||
class PlaceRepository
|
class PlaceRepository
|
||||||
{
|
{
|
||||||
private PersistentDataManager $pdm;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->pdm = new PersistentDataManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getById(int $placeId): ?Place
|
public function getById(int $placeId): ?Place
|
||||||
{
|
{
|
||||||
return $this->pdm->selectFromDbById($placeId, Place::class);
|
return \Container::$persistentDataManager->selectFromDbById($placeId, Place::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllForMap(Map $map): Generator
|
public function getAllForMap(Map $map): Generator
|
||||||
@ -26,7 +18,7 @@ class PlaceRepository
|
|||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->where('map_id', '=', $map->getId());
|
$select->where('map_id', '=', $map->getId());
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, Place::class);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, Place::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: use Map and User instead of id
|
//TODO: use Map and User instead of id
|
||||||
@ -99,7 +91,7 @@ class PlaceRepository
|
|||||||
$select->where('id', 'NOT IN', $exclude);
|
$select->where('id', 'NOT IN', $exclude);
|
||||||
$select->limit(1, $randomOffset);
|
$select->limit(1, $randomOffset);
|
||||||
|
|
||||||
return $this->pdm->selectFromDb($select, Place::class);
|
return \Container::$persistentDataManager->selectFromDb($select, Place::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Never visited places
|
// Never visited places
|
||||||
@ -186,7 +178,7 @@ class PlaceRepository
|
|||||||
$select->orderBy('round');
|
$select->orderBy('round');
|
||||||
$select->limit(1, $round);
|
$select->limit(1, $round);
|
||||||
|
|
||||||
return $this->pdm->selectFromDb($select, Place::class);
|
return \Container::$persistentDataManager->selectFromDb($select, Place::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllInChallenge(Challenge $challenge): Generator
|
public function getAllInChallenge(Challenge $challenge): Generator
|
||||||
@ -196,7 +188,7 @@ class PlaceRepository
|
|||||||
$select->where('challenge_id', '=', $challenge->getId());
|
$select->where('challenge_id', '=', $challenge->getId());
|
||||||
$select->orderBy('round');
|
$select->orderBy('round');
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, Place::class);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, Place::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,20 +3,12 @@
|
|||||||
use SokoWeb\Database\Query\Select;
|
use SokoWeb\Database\Query\Select;
|
||||||
use MapGuesser\PersistentData\Model\User;
|
use MapGuesser\PersistentData\Model\User;
|
||||||
use MapGuesser\PersistentData\Model\UserConfirmation;
|
use MapGuesser\PersistentData\Model\UserConfirmation;
|
||||||
use SokoWeb\PersistentData\PersistentDataManager;
|
|
||||||
|
|
||||||
class UserConfirmationRepository
|
class UserConfirmationRepository
|
||||||
{
|
{
|
||||||
private PersistentDataManager $pdm;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->pdm = new PersistentDataManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getById(int $userConfirmationId): ?UserConfirmation
|
public function getById(int $userConfirmationId): ?UserConfirmation
|
||||||
{
|
{
|
||||||
return $this->pdm->selectFromDbById($userConfirmationId, UserConfirmation::class);
|
return \Container::$persistentDataManager->selectFromDbById($userConfirmationId, UserConfirmation::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getByToken(string $token): ?UserConfirmation
|
public function getByToken(string $token): ?UserConfirmation
|
||||||
@ -24,7 +16,7 @@ class UserConfirmationRepository
|
|||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->where('token', '=', $token);
|
$select->where('token', '=', $token);
|
||||||
|
|
||||||
return $this->pdm->selectFromDb($select, UserConfirmation::class);
|
return \Container::$persistentDataManager->selectFromDb($select, UserConfirmation::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getByUser(User $user): ?UserConfirmation
|
public function getByUser(User $user): ?UserConfirmation
|
||||||
@ -32,6 +24,6 @@ class UserConfirmationRepository
|
|||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->where('user_id', '=', $user->getId());
|
$select->where('user_id', '=', $user->getId());
|
||||||
|
|
||||||
return $this->pdm->selectFromDb($select, UserConfirmation::class);
|
return \Container::$persistentDataManager->selectFromDb($select, UserConfirmation::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,23 +5,15 @@ use SokoWeb\Database\Query\Select;
|
|||||||
use MapGuesser\PersistentData\Model\Challenge;
|
use MapGuesser\PersistentData\Model\Challenge;
|
||||||
use MapGuesser\PersistentData\Model\User;
|
use MapGuesser\PersistentData\Model\User;
|
||||||
use MapGuesser\PersistentData\Model\UserInChallenge;
|
use MapGuesser\PersistentData\Model\UserInChallenge;
|
||||||
use SokoWeb\PersistentData\PersistentDataManager;
|
|
||||||
|
|
||||||
class UserInChallengeRepository
|
class UserInChallengeRepository
|
||||||
{
|
{
|
||||||
private PersistentDataManager $pdm;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->pdm = new PersistentDataManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAllByUser(User $user) : Generator
|
public function getAllByUser(User $user) : Generator
|
||||||
{
|
{
|
||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->where('user_id', '=', $user->getId());
|
$select->where('user_id', '=', $user->getId());
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, UserInChallenge::class);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, UserInChallenge::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllByChallenge(Challenge $challenge) : Generator
|
public function getAllByChallenge(Challenge $challenge) : Generator
|
||||||
@ -29,7 +21,7 @@ class UserInChallengeRepository
|
|||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->where('challenge_id', '=', $challenge->getId());
|
$select->where('challenge_id', '=', $challenge->getId());
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, UserInChallenge::class);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, UserInChallenge::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllByChallengeWithUsers(Challenge $challenge) : Generator
|
public function getAllByChallengeWithUsers(Challenge $challenge) : Generator
|
||||||
@ -37,7 +29,7 @@ class UserInChallengeRepository
|
|||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->where('challenge_id', '=', $challenge->getId());
|
$select->where('challenge_id', '=', $challenge->getId());
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, UserInChallenge::class, true, [User::class]);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, UserInChallenge::class, true, [User::class]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getByUserIdAndChallenge(int $userId, Challenge $challenge): ?UserInChallenge
|
public function getByUserIdAndChallenge(int $userId, Challenge $challenge): ?UserInChallenge
|
||||||
@ -46,7 +38,7 @@ class UserInChallengeRepository
|
|||||||
$select->where('user_id', '=', $userId);
|
$select->where('user_id', '=', $userId);
|
||||||
$select->where('challenge_id', '=', $challenge->getId());
|
$select->where('challenge_id', '=', $challenge->getId());
|
||||||
|
|
||||||
return $this->pdm->selectFromDb($select, UserInChallenge::class);
|
return \Container::$persistentDataManager->selectFromDb($select, UserInChallenge::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getByUserIdAndToken(int $userId, string $token_str, array $withRelations = []): ?UserInChallenge
|
public function getByUserIdAndToken(int $userId, string $token_str, array $withRelations = []): ?UserInChallenge
|
||||||
@ -67,7 +59,7 @@ class UserInChallengeRepository
|
|||||||
$select->where('user_id', '=', $userId);
|
$select->where('user_id', '=', $userId);
|
||||||
$select->where('token', '=', $token);
|
$select->where('token', '=', $token);
|
||||||
|
|
||||||
return $this->pdm->selectFromDb($select, UserInChallenge::class, true, $withRelations);
|
return \Container::$persistentDataManager->selectFromDb($select, UserInChallenge::class, true, $withRelations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isUserParticipatingInChallenge(int $userId, Challenge $challenge): bool
|
public function isUserParticipatingInChallenge(int $userId, Challenge $challenge): bool
|
||||||
|
@ -5,20 +5,12 @@ use Generator;
|
|||||||
use SokoWeb\Database\Query\Select;
|
use SokoWeb\Database\Query\Select;
|
||||||
use MapGuesser\PersistentData\Model\User;
|
use MapGuesser\PersistentData\Model\User;
|
||||||
use MapGuesser\PersistentData\Model\UserPasswordResetter;
|
use MapGuesser\PersistentData\Model\UserPasswordResetter;
|
||||||
use SokoWeb\PersistentData\PersistentDataManager;
|
|
||||||
|
|
||||||
class UserPasswordResetterRepository
|
class UserPasswordResetterRepository
|
||||||
{
|
{
|
||||||
private PersistentDataManager $pdm;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->pdm = new PersistentDataManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getById(int $userConfirmationId): ?UserPasswordResetter
|
public function getById(int $userConfirmationId): ?UserPasswordResetter
|
||||||
{
|
{
|
||||||
return $this->pdm->selectFromDbById($userConfirmationId, UserPasswordResetter::class);
|
return \Container::$persistentDataManager->selectFromDbById($userConfirmationId, UserPasswordResetter::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getByToken(string $token): ?UserPasswordResetter
|
public function getByToken(string $token): ?UserPasswordResetter
|
||||||
@ -26,7 +18,7 @@ class UserPasswordResetterRepository
|
|||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->where('token', '=', $token);
|
$select->where('token', '=', $token);
|
||||||
|
|
||||||
return $this->pdm->selectFromDb($select, UserPasswordResetter::class);
|
return \Container::$persistentDataManager->selectFromDb($select, UserPasswordResetter::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getByUser(User $user): ?UserPasswordResetter
|
public function getByUser(User $user): ?UserPasswordResetter
|
||||||
@ -34,7 +26,7 @@ class UserPasswordResetterRepository
|
|||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->where('user_id', '=', $user->getId());
|
$select->where('user_id', '=', $user->getId());
|
||||||
|
|
||||||
return $this->pdm->selectFromDb($select, UserPasswordResetter::class);
|
return \Container::$persistentDataManager->selectFromDb($select, UserPasswordResetter::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllExpired(): Generator
|
public function getAllExpired(): Generator
|
||||||
@ -42,6 +34,6 @@ class UserPasswordResetterRepository
|
|||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->where('expires', '<', (new DateTime())->format('Y-m-d H:i:s'));
|
$select->where('expires', '<', (new DateTime())->format('Y-m-d H:i:s'));
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, UserPasswordResetter::class);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, UserPasswordResetter::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,23 +5,15 @@ use SokoWeb\Database\Query\Select;
|
|||||||
use MapGuesser\PersistentData\Model\User;
|
use MapGuesser\PersistentData\Model\User;
|
||||||
use MapGuesser\PersistentData\Model\Place;
|
use MapGuesser\PersistentData\Model\Place;
|
||||||
use MapGuesser\PersistentData\Model\UserPlayedPlace;
|
use MapGuesser\PersistentData\Model\UserPlayedPlace;
|
||||||
use SokoWeb\PersistentData\PersistentDataManager;
|
|
||||||
|
|
||||||
class UserPlayedPlaceRepository
|
class UserPlayedPlaceRepository
|
||||||
{
|
{
|
||||||
private PersistentDataManager $pdm;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->pdm = new PersistentDataManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getByUser(User $user): Generator
|
public function getByUser(User $user): Generator
|
||||||
{
|
{
|
||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->where('user_id', '=', $user->getId());
|
$select->where('user_id', '=', $user->getId());
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, UserPlayedPlace::class);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, UserPlayedPlace::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllByPlace(Place $place): Generator
|
public function getAllByPlace(Place $place): Generator
|
||||||
@ -29,7 +21,7 @@ class UserPlayedPlaceRepository
|
|||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->where('place_id', '=', $place->getId());
|
$select->where('place_id', '=', $place->getId());
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, UserPlayedPlace::class);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, UserPlayedPlace::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllByUser(User $user) : Generator
|
public function getAllByUser(User $user) : Generator
|
||||||
@ -37,7 +29,7 @@ class UserPlayedPlaceRepository
|
|||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->where('user_id', '=', $user->getId());
|
$select->where('user_id', '=', $user->getId());
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, UserPlayedPlace::class);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, UserPlayedPlace::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getByUserIdAndPlaceId(int $userId, int $placeId) : ?UserPlayedPlace
|
public function getByUserIdAndPlaceId(int $userId, int $placeId) : ?UserPlayedPlace
|
||||||
@ -46,6 +38,6 @@ class UserPlayedPlaceRepository
|
|||||||
$select->where('user_id', '=', $userId);
|
$select->where('user_id', '=', $userId);
|
||||||
$select->where('place_id', '=', $placeId);
|
$select->where('place_id', '=', $placeId);
|
||||||
|
|
||||||
return $this->pdm->selectFromDb($select, UserPlayedPlace::class);
|
return \Container::$persistentDataManager->selectFromDb($select, UserPlayedPlace::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,20 +6,12 @@ use SokoWeb\Interfaces\Repository\IUserRepository;
|
|||||||
use SokoWeb\Database\Query\Select;
|
use SokoWeb\Database\Query\Select;
|
||||||
use MapGuesser\PersistentData\Model\Guess;
|
use MapGuesser\PersistentData\Model\Guess;
|
||||||
use MapGuesser\PersistentData\Model\User;
|
use MapGuesser\PersistentData\Model\User;
|
||||||
use SokoWeb\PersistentData\PersistentDataManager;
|
|
||||||
|
|
||||||
class UserRepository implements IUserRepository
|
class UserRepository implements IUserRepository
|
||||||
{
|
{
|
||||||
private PersistentDataManager $pdm;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->pdm = new PersistentDataManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getById(int $userId): ?User
|
public function getById(int $userId): ?User
|
||||||
{
|
{
|
||||||
return $this->pdm->selectFromDbById($userId, User::class);
|
return \Container::$persistentDataManager->selectFromDbById($userId, User::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getByEmail(string $email): ?User
|
public function getByEmail(string $email): ?User
|
||||||
@ -27,7 +19,7 @@ class UserRepository implements IUserRepository
|
|||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->where('email', '=', $email);
|
$select->where('email', '=', $email);
|
||||||
|
|
||||||
return $this->pdm->selectFromDb($select, User::class);
|
return \Container::$persistentDataManager->selectFromDb($select, User::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getByGoogleSub(string $sub): ?User
|
public function getByGoogleSub(string $sub): ?User
|
||||||
@ -35,7 +27,7 @@ class UserRepository implements IUserRepository
|
|||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->where('google_sub', '=', $sub);
|
$select->where('google_sub', '=', $sub);
|
||||||
|
|
||||||
return $this->pdm->selectFromDb($select, User::class);
|
return \Container::$persistentDataManager->selectFromDb($select, User::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllInactiveExpired(): Generator
|
public function getAllInactiveExpired(): Generator
|
||||||
@ -44,7 +36,7 @@ class UserRepository implements IUserRepository
|
|||||||
$select->where('active', '=', false);
|
$select->where('active', '=', false);
|
||||||
$select->where('created', '<', (new DateTime('-1 day'))->format('Y-m-d H:i:s'));
|
$select->where('created', '<', (new DateTime('-1 day'))->format('Y-m-d H:i:s'));
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, User::class);
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, User::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getByGuess(Guess $guess): ?User
|
public function getByGuess(Guess $guess): ?User
|
||||||
|
2
web.php
2
web.php
@ -90,7 +90,7 @@ Container::$routeCollection->group('admin', function (RouteCollection $routeColl
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (isset($_COOKIE['COOKIES_CONSENT'])) {
|
if (isset($_COOKIE['COOKIES_CONSENT'])) {
|
||||||
Container::$sessionHandler = new DatabaseSessionHandler();
|
Container::$sessionHandler = new DatabaseSessionHandler(Container::$dbConnection);
|
||||||
|
|
||||||
session_set_save_handler(Container::$sessionHandler, true);
|
session_set_save_handler(Container::$sessionHandler, true);
|
||||||
session_start([
|
session_start([
|
||||||
|
Loading…
Reference in New Issue
Block a user