mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
feat: add corporateEmails policy to block non-corporate sign-ups
This commit is contained in:
1 parent
f090e990f3
commit
60d434f53c
8 files changed
+25
No files matched your search
@@ -49,6 +49,7 @@ $console = [
|
||||
'disposableEmails' => false,
|
||||
'canonicalEmails' => false,
|
||||
'freeEmails' => false,
|
||||
'corporateEmails' => false,
|
||||
'invalidateSessions' => true
|
||||
],
|
||||
'authWhitelistEmails' => (!empty(System::getEnv('_APP_CONSOLE_WHITELIST_EMAILS', null))) ? \explode(',', System::getEnv('_APP_CONSOLE_WHITELIST_EMAILS', null)) : [],
|
||||
|
||||
@@ -350,6 +350,10 @@ Http::post('/v1/account')
|
||||
throw new Exception(Exception::USER_EMAIL_FREE);
|
||||
}
|
||||
|
||||
if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) {
|
||||
throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE);
|
||||
}
|
||||
|
||||
try {
|
||||
$userId = $userId == 'unique()' ? ID::unique() : $userId;
|
||||
$user->setAttributes([
|
||||
@@ -3438,6 +3442,10 @@ Http::patch('/v1/account/email')
|
||||
throw new Exception(Exception::USER_EMAIL_FREE);
|
||||
}
|
||||
|
||||
if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) {
|
||||
throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE);
|
||||
}
|
||||
|
||||
$user
|
||||
->setAttribute('email', $email)
|
||||
->setAttribute('emailVerification', false) // After this user needs to confirm mail again
|
||||
|
||||
@@ -148,6 +148,10 @@ function createUser(Hash $hash, string $userId, ?string $email, ?string $passwor
|
||||
throw new Exception(Exception::USER_EMAIL_FREE);
|
||||
}
|
||||
|
||||
if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) {
|
||||
throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE);
|
||||
}
|
||||
|
||||
$hashedPassword = null;
|
||||
|
||||
$isHashed = !$hash instanceof Plaintext;
|
||||
@@ -1612,6 +1616,10 @@ Http::patch('/v1/users/:userId/email')
|
||||
throw new Exception(Exception::USER_EMAIL_FREE);
|
||||
}
|
||||
|
||||
if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) {
|
||||
throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE);
|
||||
}
|
||||
|
||||
$user
|
||||
->setAttribute('email', $email)
|
||||
->setAttribute('emailVerification', false)
|
||||
|
||||
@@ -84,6 +84,7 @@ class Exception extends \Exception
|
||||
public const string USER_EMAIL_ALREADY_EXISTS = 'user_email_already_exists';
|
||||
public const string USER_EMAIL_DISPOSABLE = 'user_email_disposable';
|
||||
public const string USER_EMAIL_FREE = 'user_email_free';
|
||||
public const string USER_EMAIL_NOT_CORPORATE = 'user_email_not_corporate';
|
||||
public const string USER_EMAIL_NOT_CANONICAL = 'user_email_not_canonical';
|
||||
public const string USER_PASSWORD_MISMATCH = 'user_password_mismatch';
|
||||
public const string USER_SESSION_NOT_FOUND = 'user_session_not_found';
|
||||
|
||||
@@ -94,6 +94,7 @@ class Create extends Action
|
||||
'disposableEmails' => false,
|
||||
'canonicalEmails' => false,
|
||||
'freeEmails' => false,
|
||||
'corporateEmails' => false,
|
||||
'mockNumbers' => [],
|
||||
'sessionAlerts' => false,
|
||||
'membershipsUserName' => false,
|
||||
|
||||
@@ -97,6 +97,7 @@ class Create extends Action
|
||||
'disposableEmails' => false,
|
||||
'canonicalEmails' => false,
|
||||
'freeEmails' => false,
|
||||
'corporateEmails' => false,
|
||||
'mockNumbers' => [],
|
||||
'sessionAlerts' => false,
|
||||
'membershipsUserName' => false,
|
||||
|
||||
@@ -204,6 +204,10 @@ class Create extends Action
|
||||
throw new Exception(Exception::USER_EMAIL_FREE);
|
||||
}
|
||||
|
||||
if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) {
|
||||
throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE);
|
||||
}
|
||||
|
||||
$hash = $proofForPassword->hash($proofForPassword->generate());
|
||||
|
||||
$userId = ID::unique();
|
||||
|
||||
@@ -51,6 +51,7 @@ class V26 extends Filter
|
||||
$content['authDisposableEmails'] = $auths->getAttribute('disposableEmails', false);
|
||||
$content['authCanonicalEmails'] = $auths->getAttribute('canonicalEmails', false);
|
||||
$content['authFreeEmails'] = $auths->getAttribute('freeEmails', false);
|
||||
$content['authCorporateEmails'] = $auths->getAttribute('corporateEmails', false);
|
||||
$content['authMockNumbers'] = $auths->getAttribute('mockNumbers', []);
|
||||
$content['authSessionAlerts'] = $auths->getAttribute('sessionAlerts', false);
|
||||
$content['authMembershipsUserName'] = $auths->getAttribute('membershipsUserName', false);
|
||||
|
||||
Reference in new issue
Block a user