Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/UsersController.php
Show First 20 Lines • Show All 637 Lines • ▼ Show 20 Lines | ): ?string { | ||||
[$attribute => ['required', new UserEmailLocal(!$domain->isPublic())]] | [$attribute => ['required', new UserEmailLocal(!$domain->isPublic())]] | ||||
); | ); | ||||
if ($v->fails()) { | if ($v->fails()) { | ||||
return $v->errors()->toArray()[$attribute][0]; | return $v->errors()->toArray()[$attribute][0]; | ||||
} | } | ||||
// Check if it is one of domains available to the user | // Check if it is one of domains available to the user | ||||
// TODO: We should have a helper that returns "flat" array with domain names | $domains = \collect($user->domains())->pluck('namespace')->all(); | ||||
// I guess we could use pluck() somehow | |||||
$domains = array_map( | |||||
function ($domain) { | |||||
return $domain->namespace; | |||||
}, | |||||
$user->domains() | |||||
); | |||||
if (!in_array($domain->namespace, $domains)) { | if (!in_array($domain->namespace, $domains)) { | ||||
return \trans('validation.entryexists', ['attribute' => 'domain']); | return \trans('validation.entryexists', ['attribute' => 'domain']); | ||||
} | } | ||||
// Check if a user/alias with specified address already exists | // Check if a user/alias with specified address already exists | ||||
// Allow assigning the same alias to a user in the same group account, | // Allow assigning the same alias to a user in the same group account, | ||||
// but only for non-public domains | // but only for non-public domains | ||||
if ($exists = User::emailExists($email, true, $alias_exists)) { | // Allow an alias in a custom domain to an address that was a user before | ||||
if ($exists = User::emailExists($email, true, $alias_exists, $is_alias && !$domain->isPublic())) { | |||||
if ( | if ( | ||||
!$is_alias | !$is_alias | ||||
|| !$alias_exists | || !$alias_exists | ||||
|| $domain->isPublic() | || $domain->isPublic() | ||||
|| $exists->wallet()->user_id != $user->id | || $exists->wallet()->user_id != $user->id | ||||
) { | ) { | ||||
return \trans('validation.entryexists', ['attribute' => $attribute]); | return \trans('validation.entryexists', ['attribute' => $attribute]); | ||||
} | } | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
} | } |