diff --git a/app/config/errors.php b/app/config/errors.php index 156af5db8f..4345884ff5 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -211,6 +211,11 @@ return [ 'description' => 'User with the requested ID could not be found.', 'code' => 404, ], + Exception::USER_EMAIL_NOT_FOUND => [ + 'name' => Exception::USER_EMAIL_NOT_FOUND, + 'description' => 'User email could not be found.', + 'code' => 400, + ], Exception::USER_EMAIL_ALREADY_EXISTS => [ 'name' => Exception::USER_EMAIL_ALREADY_EXISTS, 'description' => 'A user with the same email already exists in the current project.', @@ -312,11 +317,21 @@ return [ 'description' => 'OAuth2 provider returned some error.', 'code' => 424, ], + Exception::USER_EMAIL_NOT_VERIFIED => [ + 'name' => Exception::USER_EMAIL_NOT_VERIFIED, + 'description' => 'User email is not verified', + 'code' => 400, + ], Exception::USER_EMAIL_ALREADY_VERIFIED => [ 'name' => Exception::USER_EMAIL_ALREADY_VERIFIED, 'description' => 'User email is already verified', 'code' => 409, ], + Exception::USER_PHONE_NOT_VERIFIED => [ + 'name' => Exception::USER_PHONE_NOT_VERIFIED, + 'description' => 'User phone is not verified', + 'code' => 400, + ], Exception::USER_PHONE_ALREADY_VERIFIED => [ 'name' => Exception::USER_PHONE_ALREADY_VERIFIED, 'description' => 'User phone is already verified', diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 6500fcc4d7..5563fc6a59 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -3595,6 +3595,10 @@ App::post('/v1/account/verifications/email') throw new Exception(Exception::GENERAL_SMTP_DISABLED, 'SMTP Disabled'); } + if (empty($user->getAttribute('email'))) { + throw new Exception(Exception::USER_EMAIL_NOT_FOUND); + } + $url = htmlentities($url); if ($user->getAttribute('emailVerification')) { throw new Exception(Exception::USER_EMAIL_ALREADY_VERIFIED); diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index b1b4f47b34..0993f68a58 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -1921,6 +1921,26 @@ class AccountCustomClientTest extends Scope return $session; } + /** + * @depends testCreateAnonymousAccount + */ + public function testCreateAnonymousAccountVerification($session): array + { + $response = $this->client->call(Client::METHOD_POST, '/account/verification', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ]), [ + 'url' => 'http://localhost/verification', + ]); + + $this->assertEquals(400, $response['body']['code']); + $this->assertEquals('user_email_not_found', $response['body']['type']); + + return []; + } + /** * @depends testCreateAnonymousAccount */