check if username is empty in usercontroller

This commit is contained in:
Bence Pőcze 2023-09-25 20:55:21 +02:00
parent 467399c81b
commit a2d6376e81
Signed by: bence
GPG Key ID: DC5BD6E95A333E6D

View File

@ -290,7 +290,11 @@ class UserController implements IAuthenticationRequired
}
$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) {
return new JsonContent(['error' => ['errorText' => 'Username can contain only english letters, digits, - (hyphen), . (dot), _ (underscore).']]);
}