Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/UsersController.php
Show First 20 Lines • Show All 677 Lines • ▼ Show 20 Line(s) | |||||
list($login, $domain) = explode('@', Str::lower($email)); | list($login, $domain) = explode('@', Str::lower($email)); | ||||
if (strlen($login) === 0 || strlen($domain) === 0) { | if (strlen($login) === 0 || strlen($domain) === 0) { | ||||
return \trans('validation.entryinvalid', ['attribute' => 'email']); | return \trans('validation.entryinvalid', ['attribute' => 'email']); | ||||
} | } | ||||
// Check if domain exists | // Check if domain exists | ||||
$domain = Domain::withEnvTenantContext()->where('namespace', $domain)->first(); | $domain = Domain::withObjectTenantContext($user)->where('namespace', $domain)->first(); | ||||
if (empty($domain)) { | if (empty($domain)) { | ||||
return \trans('validation.domaininvalid'); | return \trans('validation.domaininvalid'); | ||||
} | } | ||||
// Validate login part alone | // Validate login part alone | ||||
$v = Validator::make( | $v = Validator::make( | ||||
['email' => $login], | ['email' => $login], | ||||
['email' => ['required', new UserEmailLocal(!$domain->isPublic())]] | ['email' => ['required', new UserEmailLocal(!$domain->isPublic())]] | ||||
); | ); | ||||
if ($v->fails()) { | if ($v->fails()) { | ||||
return $v->errors()->toArray()['email'][0]; | return $v->errors()->toArray()['email'][0]; | ||||
} | } | ||||
// Check if it is one of domains available to the user | // Check if it is one of domains available to the user | ||||
$domains = \collect($user->domains())->pluck('namespace')->all(); | if (!$user->domains()->where('namespace', $domain->namespace)->exists()) { | ||||
if (!in_array($domain->namespace, $domains)) { | |||||
return \trans('validation.entryexists', ['attribute' => 'domain']); | return \trans('validation.entryexists', ['attribute' => 'domain']); | ||||
} | } | ||||
// Check if a user with specified address already exists | // Check if a user with specified address already exists | ||||
if ($existing_user = User::emailExists($email, true)) { | if ($existing_user = User::emailExists($email, true)) { | ||||
// If this is a deleted user in the same custom domain | // If this is a deleted user in the same custom domain | ||||
// we'll force delete him before | // we'll force delete him before | ||||
if (!$domain->isPublic() && $existing_user->trashed()) { | if (!$domain->isPublic() && $existing_user->trashed()) { | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
list($login, $domain) = explode('@', Str::lower($email)); | list($login, $domain) = explode('@', Str::lower($email)); | ||||
if (strlen($login) === 0 || strlen($domain) === 0) { | if (strlen($login) === 0 || strlen($domain) === 0) { | ||||
return \trans('validation.entryinvalid', ['attribute' => 'alias']); | return \trans('validation.entryinvalid', ['attribute' => 'alias']); | ||||
} | } | ||||
// Check if domain exists | // Check if domain exists | ||||
$domain = Domain::withEnvTenantContext()->where('namespace', $domain)->first(); | $domain = Domain::withObjectTenantContext($user)->where('namespace', $domain)->first(); | ||||
if (empty($domain)) { | if (empty($domain)) { | ||||
return \trans('validation.domaininvalid'); | return \trans('validation.domaininvalid'); | ||||
} | } | ||||
// Validate login part alone | // Validate login part alone | ||||
$v = Validator::make( | $v = Validator::make( | ||||
['alias' => $login], | ['alias' => $login], | ||||
['alias' => ['required', new UserEmailLocal(!$domain->isPublic())]] | ['alias' => ['required', new UserEmailLocal(!$domain->isPublic())]] | ||||
); | ); | ||||
if ($v->fails()) { | if ($v->fails()) { | ||||
return $v->errors()->toArray()['alias'][0]; | return $v->errors()->toArray()['alias'][0]; | ||||
} | } | ||||
// Check if it is one of domains available to the user | // Check if it is one of domains available to the user | ||||
$domains = \collect($user->domains())->pluck('namespace')->all(); | if (!$user->domains()->where('namespace', $domain->namespace)->exists()) { | ||||
if (!in_array($domain->namespace, $domains)) { | |||||
return \trans('validation.entryexists', ['attribute' => 'domain']); | return \trans('validation.entryexists', ['attribute' => 'domain']); | ||||
} | } | ||||
// Check if a user with specified address already exists | // Check if a user with specified address already exists | ||||
if ($existing_user = User::emailExists($email, true)) { | if ($existing_user = User::emailExists($email, true)) { | ||||
// Allow an alias in a custom domain to an address that was a user before | // Allow an alias in a custom domain to an address that was a user before | ||||
if ($domain->isPublic() || !$existing_user->trashed()) { | if ($domain->isPublic() || !$existing_user->trashed()) { | ||||
return \trans('validation.entryexists', ['attribute' => 'alias']); | return \trans('validation.entryexists', ['attribute' => 'alias']); | ||||
Show All 20 Lines |