diff --git a/app/config/errors.php b/app/config/errors.php index c5c6a489b8..a071b0cb7e 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -125,6 +125,11 @@ return [ 'description' => 'Console registration is restricted to specific emails. Contact your administrator for more information.', 'code' => 401, ], + Exception::USER_CODE_INVALID => [ + 'name' => Exception::USER_CODE_INVALID, + 'description' => 'The specified code is not valid. Contact your administrator for more information.', + 'code' => 401, + ], Exception::USER_IP_NOT_WHITELISTED => [ 'name' => Exception::USER_IP_NOT_WHITELISTED, 'description' => 'Console registration is restricted to specific IPs. Contact your administrator for more information.', diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 43261dc176..9ec9b47ece 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -44,8 +44,8 @@ use Utopia\Validator\WhiteList; $oauthDefaultSuccess = '/auth/oauth2/success'; $oauthDefaultFailure = '/auth/oauth2/failure'; -App::post('/v1/account/code/:code') - ->desc('Create Account') +App::post('/v1/account/invite') + ->desc('Create Account using an invite code') ->groups(['api', 'account', 'auth']) ->label('event', 'users.[userId].create') ->label('scope', 'public') @@ -56,7 +56,7 @@ App::post('/v1/account/code/:code') ->label('usage.metric', 'users.{scope}.requests.create') ->label('sdk.auth', []) ->label('sdk.namespace', 'account') - ->label('sdk.method', 'create') + ->label('sdk.method', 'createWithInviteCode') ->label('sdk.description', '/docs/references/account/create.md') ->label('sdk.response.code', Response::STATUS_CODE_CREATED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) @@ -77,18 +77,10 @@ App::post('/v1/account/code/:code') $email = \strtolower($email); if ('console' === $project->getId()) { - $whitelistEmails = $project->getAttribute('authWhitelistEmails'); - $whitelistIPs = $project->getAttribute('authWhitelistIPs'); $whitelistCodes = (!empty(App::getEnv('_APP_CONSOLE_WHITELIST_CODES', null))) ? \explode(',', App::getEnv('_APP_CONSOLE_WHITELIST_CODES', null)) : []; if (!empty($whitelistCodes) && !\in_array($code, $whitelistCodes)) { - if (!empty($whitelistEmails) && !\in_array($email, $whitelistEmails)) { - throw new Exception(Exception::USER_EMAIL_NOT_WHITELISTED); - } - - if (!empty($whitelistIPs) && !\in_array($request->getIP(), $whitelistIPs)) { - throw new Exception(Exception::USER_IP_NOT_WHITELISTED); - } + throw new Exception(Exception::USER_CODE_INVALID); } } diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index d25cfb0d40..9f035863eb 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -60,6 +60,7 @@ class Exception extends \Exception public const USER_PASSWORD_RESET_REQUIRED = 'user_password_reset_required'; public const USER_EMAIL_NOT_WHITELISTED = 'user_email_not_whitelisted'; public const USER_IP_NOT_WHITELISTED = 'user_ip_not_whitelisted'; + public const USER_CODE_INVALID = 'user_code_invalid'; public const USER_INVALID_CREDENTIALS = 'user_invalid_credentials'; public const USER_ANONYMOUS_CONSOLE_PROHIBITED = 'user_anonymous_console_prohibited'; public const USER_SESSION_ALREADY_EXISTS = 'user_session_already_exists';