check if username is used during signup
This commit is contained in:
parent
a2d6376e81
commit
5d367d5b35
@ -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') : (new UsernameGenerator())->generate());
|
$newUser->setUsername($username);
|
||||||
$newUser->setCreatedDate(new DateTime());
|
$newUser->setCreatedDate(new DateTime());
|
||||||
|
|
||||||
\Container::$persistentDataManager->saveToDb($newUser);
|
\Container::$persistentDataManager->saveToDb($newUser);
|
||||||
|
Loading…
Reference in New Issue
Block a user