From 22295ce5865989b9866f4a1255877b4010e07437 Mon Sep 17 00:00:00 2001 From: Akhil Date: Mon, 17 Jun 2024 16:30:17 +0530 Subject: [PATCH 1/4] lowercase username before processing --- lib/Controller/AccountController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index de1f8d41..e797abc3 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -138,6 +138,7 @@ class AccountController extends Controller { } try { + $username = $mbox = mb_strtolower($username, 'UTF-8'); $mainDomain = $this->userService->getMainDomain(); $userEmail = $username.'@'.$mainDomain; $this->userService->registerUser($displayname, $recoveryEmail, $username, $userEmail, $password); -- GitLab From e63224a5d4494bdac8cc154414036191d8fb28c9 Mon Sep 17 00:00:00 2001 From: Akhil Date: Mon, 17 Jun 2024 11:11:56 +0000 Subject: [PATCH 2/4] Apply 1 suggestion(s) to 1 file(s) --- lib/Controller/AccountController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index e797abc3..09ed1264 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -138,7 +138,7 @@ class AccountController extends Controller { } try { - $username = $mbox = mb_strtolower($username, 'UTF-8'); + $username = mb_strtolower($username, 'UTF-8'); $mainDomain = $this->userService->getMainDomain(); $userEmail = $username.'@'.$mainDomain; $this->userService->registerUser($displayname, $recoveryEmail, $username, $userEmail, $password); -- GitLab From 6f5b1fe44d4a65960f013008ec47babc2e18facb Mon Sep 17 00:00:00 2001 From: Akhil Date: Mon, 17 Jun 2024 17:08:39 +0530 Subject: [PATCH 3/4] lowercase username before checking if it is available too --- lib/Controller/AccountController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 09ed1264..615f1907 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -224,6 +224,7 @@ class AccountController extends Controller { } try { + $username = mb_strtolower($username, 'UTF-8'); if (!$this->userService->userExists($username) && !$this->userService->isUsernameTaken($username)) { $response->setStatus(200); $this->session->set(self::SESSION_USERNAME_CHECK, true); -- GitLab From d38b6d2ce12f10ee6fedd7b253d5c628f729d0a1 Mon Sep 17 00:00:00 2001 From: Akhil Date: Mon, 17 Jun 2024 17:20:32 +0530 Subject: [PATCH 4/4] Check is username taken at registerUser --- lib/Controller/AccountController.php | 1 + lib/Service/UserService.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 615f1907..82aa8507 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -216,6 +216,7 @@ class AccountController extends Controller { * @return \OCP\AppFramework\Http\DataResponse */ public function checkUsernameAvailable(string $username) : DataResponse { + $this->session->remove(self::SESSION_USERNAME_CHECK); $response = new DataResponse(); $response->setStatus(400); diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index c2db1c52..0101604b 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -249,7 +249,7 @@ class UserService { */ public function registerUser(string $displayname, string $recoveryEmail, string $username, string $userEmail, string $password): void { - if ($this->userExists($username)) { + if ($this->userExists($username) || $this->isUsernameTaken($username)) { throw new Exception("Username '$username' is already taken."); } if (!empty($recoveryEmail)) { -- GitLab