Compare commits
20 Commits
db3fe3970e
...
dfb3aefb62
Author | SHA1 | Date | |
---|---|---|---|
dfb3aefb62 | |||
751a86c823 | |||
52873fc759 | |||
0882a67019 | |||
49069f4a52 | |||
4bba7599e1 | |||
7fb75c9f25 | |||
5d367d5b35 | |||
a2d6376e81 | |||
f3c3aa69eb | |||
467399c81b | |||
84e848506f | |||
e18ed3a034 | |||
ea8b46ab91 | |||
a1b0f5e9fb | |||
b1ed28f4b5 | |||
36f4b6b4d0 | |||
2c706cc7f3 | |||
77c6e6c4e6 | |||
c25ba2dd28 |
@ -1,6 +1,6 @@
|
|||||||
# MapGuesser
|
# MapGuesser
|
||||||
|
|
||||||
[![Build Status](https://jenkins.e5tv.hu/job/mapguesser/job/develop/badge/icon)](https://jenkins.e5tv.hu/job/mapguesser/job/develop/)
|
[![Build Status](https://ci.esoko.eu/job/mapguesser/job/develop/badge/icon)](https://ci.esoko.eu/job/mapguesser/job/develop/)
|
||||||
|
|
||||||
This is the MapGuesser Application project. This is a game about guessing where you are based on a street view panorama - inspired by existing applications.
|
This is the MapGuesser Application project. This is a game about guessing where you are based on a street view panorama - inspired by existing applications.
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ docker compose up -d
|
|||||||
**And you are done!** The application is ready to use. You can create the first administrative user with the following command after attaching to the `app` container:
|
**And you are done!** The application is ready to use. You can create the first administrative user with the following command after attaching to the `app` container:
|
||||||
|
|
||||||
```
|
```
|
||||||
./mapg user:add EMAIL PASSWORD admin
|
./mapg user:add EMAIL USERNAME PASSWORD admin
|
||||||
```
|
```
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
@ -1,13 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Faker\Factory;
|
|
||||||
use MapGuesser\PersistentData\Model\User;
|
use MapGuesser\PersistentData\Model\User;
|
||||||
|
use MapGuesser\Repository\UserRepository;
|
||||||
|
use MapGuesser\Util\UsernameGenerator;
|
||||||
use SokoWeb\Database\Query\Select;
|
use SokoWeb\Database\Query\Select;
|
||||||
|
|
||||||
$select = new Select(Container::$dbConnection);
|
$select = new Select(Container::$dbConnection);
|
||||||
$users = Container::$persistentDataManager->selectMultipleFromDb($select, User::class);
|
$users = Container::$persistentDataManager->selectMultipleFromDb($select, User::class);
|
||||||
|
$userRepository = new UserRepository();
|
||||||
|
$usernameGenerator = new UsernameGenerator();
|
||||||
|
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
$user->setUsername(Factory::create()->userName);
|
do {
|
||||||
|
$username = $usernameGenerator->generate();
|
||||||
|
} while ($userRepository->getByUsername($username));
|
||||||
|
|
||||||
|
$user->setUsername($username);
|
||||||
Container::$persistentDataManager->saveToDb($user);
|
Container::$persistentDataManager->saveToDb($user);
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,9 @@ var MapGuesser = {
|
|||||||
|
|
||||||
formError.style.display = 'block';
|
formError.style.display = 'block';
|
||||||
formError.innerHTML = this.response.error.errorText;
|
formError.innerHTML = this.response.error.errorText;
|
||||||
|
if (typeof grecaptcha !== 'undefined') {
|
||||||
|
grecaptcha.reset();
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ class AddUserCommand extends Command
|
|||||||
$this->setName('user:add')
|
$this->setName('user:add')
|
||||||
->setDescription('Adding of user.')
|
->setDescription('Adding of user.')
|
||||||
->addArgument('email', InputArgument::REQUIRED, 'Email of user')
|
->addArgument('email', InputArgument::REQUIRED, 'Email of user')
|
||||||
|
->addArgument('username', InputArgument::REQUIRED, 'Username of user')
|
||||||
->addArgument('password', InputArgument::REQUIRED, 'Password of user')
|
->addArgument('password', InputArgument::REQUIRED, 'Password of user')
|
||||||
->addArgument('type', InputArgument::OPTIONAL, 'Type of user');;
|
->addArgument('type', InputArgument::OPTIONAL, 'Type of user');;
|
||||||
}
|
}
|
||||||
@ -22,6 +23,7 @@ class AddUserCommand extends Command
|
|||||||
{
|
{
|
||||||
$user = new User();
|
$user = new User();
|
||||||
$user->setEmail($input->getArgument('email'));
|
$user->setEmail($input->getArgument('email'));
|
||||||
|
$user->setUsername($input->getArgument('username'));
|
||||||
$user->setPlainPassword($input->getArgument('password'));
|
$user->setPlainPassword($input->getArgument('password'));
|
||||||
$user->setActive(true);
|
$user->setActive(true);
|
||||||
$user->setCreatedDate(new DateTime());
|
$user->setCreatedDate(new DateTime());
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Faker\Factory;
|
|
||||||
use SokoWeb\Http\Request;
|
use SokoWeb\Http\Request;
|
||||||
use SokoWeb\Interfaces\Response\IContent;
|
use SokoWeb\Interfaces\Response\IContent;
|
||||||
use SokoWeb\Interfaces\Response\IRedirect;
|
use SokoWeb\Interfaces\Response\IRedirect;
|
||||||
@ -15,6 +14,7 @@ use MapGuesser\Repository\UserConfirmationRepository;
|
|||||||
use MapGuesser\Repository\UserPasswordResetterRepository;
|
use MapGuesser\Repository\UserPasswordResetterRepository;
|
||||||
use MapGuesser\Repository\UserPlayedPlaceRepository;
|
use MapGuesser\Repository\UserPlayedPlaceRepository;
|
||||||
use MapGuesser\Repository\UserRepository;
|
use MapGuesser\Repository\UserRepository;
|
||||||
|
use MapGuesser\Util\UsernameGenerator;
|
||||||
use SokoWeb\Response\HtmlContent;
|
use SokoWeb\Response\HtmlContent;
|
||||||
use SokoWeb\Response\JsonContent;
|
use SokoWeb\Response\JsonContent;
|
||||||
use SokoWeb\Response\Redirect;
|
use SokoWeb\Response\Redirect;
|
||||||
@ -364,11 +364,24 @@ class LoginController
|
|||||||
$newUser->setPlainPassword(\Container::$request->post('password'));
|
$newUser->setPlainPassword(\Container::$request->post('password'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(\Container::$request->post('username')) > 0 && preg_match('/^[a-zA-Z0-9_\-\.]+$/', \Container::$request->post('username')) !== 1) {
|
if (strlen(\Container::$request->post('username')) > 0) {
|
||||||
return new JsonContent(['error' => ['errorText' => 'Username can contain only english letters, digits, - (hyphen), . (dot), _ (underscore).']]);
|
$username = \Container::$request->post('username');
|
||||||
|
|
||||||
|
if (preg_match('/^[a-zA-Z0-9_\-\.]+$/', $username) !== 1) {
|
||||||
|
return new JsonContent(['error' => ['errorText' => 'Username can contain only english letters, digits, - (hyphen), . (dot), _ (underscore).']]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->userRepository->getByUsername($username) !== null) {
|
||||||
|
return new JsonContent(['error' => ['errorText' => 'The given username is already taken.']]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$usernameGenerator = new UsernameGenerator();
|
||||||
|
do {
|
||||||
|
$username = $usernameGenerator->generate();
|
||||||
|
} while ($this->userRepository->getByUsername($username));
|
||||||
}
|
}
|
||||||
|
|
||||||
$newUser->setUsername(strlen(\Container::$request->post('username')) > 0 ? \Container::$request->post('username') : Factory::create()->userName);
|
$newUser->setUsername($username);
|
||||||
$newUser->setCreatedDate(new DateTime());
|
$newUser->setCreatedDate(new DateTime());
|
||||||
|
|
||||||
\Container::$persistentDataManager->saveToDb($newUser);
|
\Container::$persistentDataManager->saveToDb($newUser);
|
||||||
|
@ -290,7 +290,11 @@ class UserController implements IAuthenticationRequired
|
|||||||
}
|
}
|
||||||
|
|
||||||
$newUsername = \Container::$request->post('username');
|
$newUsername = \Container::$request->post('username');
|
||||||
if (strlen($newUsername) > 0 && $newUsername !== $user->getUsername()) {
|
if ($newUsername !== $user->getUsername()) {
|
||||||
|
if (strlen($newUsername) == 0) {
|
||||||
|
return new JsonContent(['error' => ['errorText' => 'Username cannot be empty.']]);
|
||||||
|
}
|
||||||
|
|
||||||
if (preg_match('/^[a-zA-Z0-9_\-\.]+$/', $newUsername) !== 1) {
|
if (preg_match('/^[a-zA-Z0-9_\-\.]+$/', $newUsername) !== 1) {
|
||||||
return new JsonContent(['error' => ['errorText' => 'Username can contain only english letters, digits, - (hyphen), . (dot), _ (underscore).']]);
|
return new JsonContent(['error' => ['errorText' => 'Username can contain only english letters, digits, - (hyphen), . (dot), _ (underscore).']]);
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ class User extends Model implements IUser
|
|||||||
|
|
||||||
public function getDisplayName(): string
|
public function getDisplayName(): string
|
||||||
{
|
{
|
||||||
return $this->email;
|
return $this->username;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkPassword(string $password): bool
|
public function checkPassword(string $password): bool
|
||||||
|
247
src/Util/UsernameGenerator.php
Normal file
247
src/Util/UsernameGenerator.php
Normal file
@ -0,0 +1,247 @@
|
|||||||
|
<?php namespace MapGuesser\Util;
|
||||||
|
|
||||||
|
class UsernameGenerator
|
||||||
|
{
|
||||||
|
const ADJECTIVES = [
|
||||||
|
'abundant',
|
||||||
|
'agile',
|
||||||
|
'alluring',
|
||||||
|
'ample',
|
||||||
|
'adorable',
|
||||||
|
'angry',
|
||||||
|
'anxious',
|
||||||
|
'astonishing',
|
||||||
|
'beautiful',
|
||||||
|
'big',
|
||||||
|
'bitter',
|
||||||
|
'blissful',
|
||||||
|
'blue',
|
||||||
|
'brave',
|
||||||
|
'bright',
|
||||||
|
'brilliant',
|
||||||
|
'busy',
|
||||||
|
'calm',
|
||||||
|
'captivating',
|
||||||
|
'careful',
|
||||||
|
'charming',
|
||||||
|
'cheerful',
|
||||||
|
'clumsy',
|
||||||
|
'colorful',
|
||||||
|
'confused',
|
||||||
|
'cooperative',
|
||||||
|
'courageous',
|
||||||
|
'cozy',
|
||||||
|
'crispy',
|
||||||
|
'curious',
|
||||||
|
'dazzling',
|
||||||
|
'delightful',
|
||||||
|
'determined',
|
||||||
|
'eager',
|
||||||
|
'elegant',
|
||||||
|
'enchanting',
|
||||||
|
'enthusiastic',
|
||||||
|
'exciting',
|
||||||
|
'exquisite',
|
||||||
|
'faithful',
|
||||||
|
'fancy',
|
||||||
|
'fearless',
|
||||||
|
'fierce',
|
||||||
|
'fluffy',
|
||||||
|
'fresh',
|
||||||
|
'friendly',
|
||||||
|
'frigid',
|
||||||
|
'funny',
|
||||||
|
'gentle',
|
||||||
|
'glorious',
|
||||||
|
'graceful',
|
||||||
|
'grateful',
|
||||||
|
'happy',
|
||||||
|
'harmonious',
|
||||||
|
'healthy',
|
||||||
|
'helpful',
|
||||||
|
'honest',
|
||||||
|
'hopeful',
|
||||||
|
'hot',
|
||||||
|
'humble',
|
||||||
|
'hungry',
|
||||||
|
'impressive',
|
||||||
|
'infamous',
|
||||||
|
'innocent',
|
||||||
|
'intense',
|
||||||
|
'jolly',
|
||||||
|
'joyful',
|
||||||
|
'kind',
|
||||||
|
'lively',
|
||||||
|
'lonely',
|
||||||
|
'lovely',
|
||||||
|
'lucky',
|
||||||
|
'mysterious',
|
||||||
|
'naughty',
|
||||||
|
'nervous',
|
||||||
|
'nutritious',
|
||||||
|
'obedient',
|
||||||
|
'peaceful',
|
||||||
|
'playful',
|
||||||
|
'polite',
|
||||||
|
'powerful',
|
||||||
|
'precious',
|
||||||
|
'proud',
|
||||||
|
'radiant',
|
||||||
|
'reckless',
|
||||||
|
'reliable',
|
||||||
|
'rich',
|
||||||
|
'romantic',
|
||||||
|
'rough',
|
||||||
|
'sad',
|
||||||
|
'scary',
|
||||||
|
'sensitive',
|
||||||
|
'shiny',
|
||||||
|
'silky',
|
||||||
|
'sincere',
|
||||||
|
'sleepy',
|
||||||
|
'smart',
|
||||||
|
'sneaky',
|
||||||
|
'soft',
|
||||||
|
'sparkling',
|
||||||
|
'splendid',
|
||||||
|
'strong',
|
||||||
|
'stubborn',
|
||||||
|
'sweet',
|
||||||
|
'tender',
|
||||||
|
'thoughtful',
|
||||||
|
'thrilling',
|
||||||
|
'timid',
|
||||||
|
'tranquil',
|
||||||
|
'trustworthy',
|
||||||
|
'unique',
|
||||||
|
'vibrant',
|
||||||
|
'victorious',
|
||||||
|
'warm',
|
||||||
|
'wise',
|
||||||
|
'witty',
|
||||||
|
'wonderful',
|
||||||
|
'worried',
|
||||||
|
'zealous'
|
||||||
|
];
|
||||||
|
|
||||||
|
const NOUNS = [
|
||||||
|
'airplane',
|
||||||
|
'ant',
|
||||||
|
'apple',
|
||||||
|
'aquarium',
|
||||||
|
'backpack',
|
||||||
|
'banana',
|
||||||
|
'bear',
|
||||||
|
'bee',
|
||||||
|
'camera',
|
||||||
|
'car',
|
||||||
|
'cat',
|
||||||
|
'chocolate',
|
||||||
|
'desk',
|
||||||
|
'diamond',
|
||||||
|
'dog',
|
||||||
|
'dolphin',
|
||||||
|
'duck',
|
||||||
|
'egg',
|
||||||
|
'eiffeltower',
|
||||||
|
'elephant',
|
||||||
|
'fire',
|
||||||
|
'flower',
|
||||||
|
'forest',
|
||||||
|
'fork',
|
||||||
|
'fox',
|
||||||
|
'galaxy',
|
||||||
|
'giraffe',
|
||||||
|
'globe',
|
||||||
|
'guitar',
|
||||||
|
'hammer',
|
||||||
|
'hamster',
|
||||||
|
'hat',
|
||||||
|
'house',
|
||||||
|
'icecream',
|
||||||
|
'iguana',
|
||||||
|
'island',
|
||||||
|
'jacket',
|
||||||
|
'jaguar',
|
||||||
|
'jellyfish',
|
||||||
|
'jigsaw',
|
||||||
|
'kangaroo',
|
||||||
|
'key',
|
||||||
|
'kite',
|
||||||
|
'koala',
|
||||||
|
'lamp',
|
||||||
|
'lighthouse',
|
||||||
|
'lightning',
|
||||||
|
'lion',
|
||||||
|
'llama',
|
||||||
|
'moon',
|
||||||
|
'mountain',
|
||||||
|
'mouse',
|
||||||
|
'necklace',
|
||||||
|
'nest',
|
||||||
|
'newt',
|
||||||
|
'notebook',
|
||||||
|
'ocean',
|
||||||
|
'octopus',
|
||||||
|
'orchid',
|
||||||
|
'owl',
|
||||||
|
'panda',
|
||||||
|
'pencil',
|
||||||
|
'penguin',
|
||||||
|
'piano',
|
||||||
|
'queen',
|
||||||
|
'quilt',
|
||||||
|
'quokka',
|
||||||
|
'rabbit',
|
||||||
|
'rainbow',
|
||||||
|
'robot',
|
||||||
|
'ship',
|
||||||
|
'snake',
|
||||||
|
'statue',
|
||||||
|
'sun',
|
||||||
|
'sunflower',
|
||||||
|
'table',
|
||||||
|
'telescope',
|
||||||
|
'tiger',
|
||||||
|
'tree',
|
||||||
|
'turtle',
|
||||||
|
'uakari',
|
||||||
|
'umbrella',
|
||||||
|
'unicorn',
|
||||||
|
'universe',
|
||||||
|
'vase',
|
||||||
|
'violin',
|
||||||
|
'volcano',
|
||||||
|
'vulture',
|
||||||
|
'wallaby',
|
||||||
|
'waterfall',
|
||||||
|
'whale',
|
||||||
|
'xray',
|
||||||
|
'xylophone',
|
||||||
|
'yacht',
|
||||||
|
'yak',
|
||||||
|
'yarn',
|
||||||
|
'yeti',
|
||||||
|
'zebra',
|
||||||
|
'zeppelin',
|
||||||
|
'zucchini',
|
||||||
|
];
|
||||||
|
|
||||||
|
function generate(): string
|
||||||
|
{
|
||||||
|
$numberOfAdjectives = count(self::ADJECTIVES);
|
||||||
|
$numberOfNouns = count(self::NOUNS);
|
||||||
|
|
||||||
|
$firstAdjective = self::ADJECTIVES[mt_rand(0, $numberOfAdjectives - 1)];
|
||||||
|
do {
|
||||||
|
$secondAdjective = self::ADJECTIVES[mt_rand(0, $numberOfAdjectives - 1)];
|
||||||
|
} while ($firstAdjective === $secondAdjective);
|
||||||
|
$noun = self::NOUNS[mt_rand(0, $numberOfNouns - 1)];
|
||||||
|
|
||||||
|
$firstAdjective = ucfirst($firstAdjective);
|
||||||
|
$secondAdjective = ucfirst($secondAdjective);
|
||||||
|
$noun = ucfirst($noun);
|
||||||
|
|
||||||
|
return $firstAdjective . $secondAdjective . $noun;
|
||||||
|
}
|
||||||
|
}
|
23
tests/Util/UsernameGeneratorTest.php
Normal file
23
tests/Util/UsernameGeneratorTest.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php namespace MapGuesser\Tests\Util;
|
||||||
|
|
||||||
|
use MapGuesser\Util\UsernameGenerator;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
final class UsernameGeneratorTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testCanGenerateRandomUsernameFromComponents(): void
|
||||||
|
{
|
||||||
|
$generator = new UsernameGenerator();
|
||||||
|
$parts = $this->getUsernameParts($generator->generate());
|
||||||
|
|
||||||
|
$this->assertEquals(3, count($parts));
|
||||||
|
$this->assertContains($parts[0], UsernameGenerator::ADJECTIVES);
|
||||||
|
$this->assertContains($parts[1], UsernameGenerator::ADJECTIVES);
|
||||||
|
$this->assertContains($parts[2], UsernameGenerator::NOUNS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getUsernameParts(string $username): array
|
||||||
|
{
|
||||||
|
return explode('-', strtolower(preg_replace('/([a-z])([A-Z])/', '$1-$2', $username)));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user