check if username is empty in usercontroller

This commit is contained in:
bence committed 2023-09-25 20:55:21 +02:00
1 parent 467399c81b
commit a2d6376e81
1 file changed
+5 -1
+5 -1
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).']]);
}