Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/UsersController.php
<?php | <?php | ||||
namespace App\Http\Controllers\API\V4; | namespace App\Http\Controllers\API\V4; | ||||
use App\Http\Controllers\Controller; | use App\Http\Controllers\Controller; | ||||
use App\Domain; | use App\Domain; | ||||
use App\Group; | |||||
use App\Rules\UserEmailDomain; | use App\Rules\UserEmailDomain; | ||||
use App\Rules\UserEmailLocal; | use App\Rules\UserEmailLocal; | ||||
use App\Sku; | use App\Sku; | ||||
use App\User; | use App\User; | ||||
use Carbon\Carbon; | use Carbon\Carbon; | ||||
use Illuminate\Http\Request; | use Illuminate\Http\Request; | ||||
use Illuminate\Support\Facades\Auth; | use Illuminate\Support\Facades\Auth; | ||||
use Illuminate\Support\Facades\DB; | use Illuminate\Support\Facades\DB; | ||||
Show All 10 Lines | public const USER_SETTINGS = [ | ||||
'external_email', | 'external_email', | ||||
'first_name', | 'first_name', | ||||
'last_name', | 'last_name', | ||||
'organization', | 'organization', | ||||
'phone', | 'phone', | ||||
]; | ]; | ||||
/** | /** | ||||
* On user create it is filled with a user object to force-delete | * On user create it is filled with a user or group object to force-delete | ||||
* before the creation of a new user record is possible. | * before the creation of a new user record is possible. | ||||
* | * | ||||
* @var \App\User|null | * @var \App\User|\App\Group|null | ||||
*/ | */ | ||||
protected $deleteBeforeCreate; | protected $deleteBeforeCreate; | ||||
/** | /** | ||||
* Delete a user. | * Delete a user. | ||||
* | * | ||||
* @param int $id User identifier | * @param int $id User identifier | ||||
▲ Show 20 Lines • Show All 623 Lines • ▼ Show 20 Lines | public static function execProcessStep(User $user, string $step): ?bool | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* Email address validation for use as a user mailbox (login). | * Email address validation for use as a user mailbox (login). | ||||
* | * | ||||
* @param string $email Email address | * @param string $email Email address | ||||
* @param \App\User $user The account owner | * @param \App\User $user The account owner | ||||
* @param ?\App\User $deleted Filled with an instance of a deleted user with | * @param null|\App\User|\App\Group $deleted Filled with an instance of a deleted user or group | ||||
* the specified email address, if exists | * with the specified email address, if exists | ||||
* | * | ||||
* @return ?string Error message on validation error | * @return ?string Error message on validation error | ||||
*/ | */ | ||||
public static function validateEmail(string $email, \App\User $user, &$deleted = null): ?string | public static function validateEmail(string $email, \App\User $user, &$deleted = null): ?string | ||||
{ | { | ||||
$deleted = null; | $deleted = null; | ||||
if (strpos($email, '@') === false) { | if (strpos($email, '@') === false) { | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | public static function validateEmail(string $email, \App\User $user, &$deleted = null): ?string | ||||
} | } | ||||
} | } | ||||
// Check if an alias with specified address already exists. | // Check if an alias with specified address already exists. | ||||
if (User::aliasExists($email)) { | if (User::aliasExists($email)) { | ||||
return \trans('validation.entryexists', ['attribute' => 'email']); | return \trans('validation.entryexists', ['attribute' => 'email']); | ||||
} | } | ||||
// Check if a group with specified address already exists | |||||
if ($existing_group = Group::emailExists($email, true)) { | |||||
// If this is a deleted group in the same custom domain | |||||
// we'll force delete it before | |||||
if (!$domain->isPublic() && $existing_group->trashed()) { | |||||
$deleted = $existing_group; | |||||
} else { | |||||
return \trans('validation.entryexists', ['attribute' => 'email']); | |||||
} | |||||
} | |||||
return null; | return null; | ||||
} | } | ||||
/** | /** | ||||
* Email address validation for use as an alias. | * Email address validation for use as an alias. | ||||
* | * | ||||
* @param string $email Email address | * @param string $email Email address | ||||
* @param \App\User $user The account owner | * @param \App\User $user The account owner | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | public static function validateAlias(string $email, \App\User $user): ?string | ||||
if (User::aliasExists($email)) { | if (User::aliasExists($email)) { | ||||
// 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 ($domain->isPublic()) { | if ($domain->isPublic()) { | ||||
return \trans('validation.entryexists', ['attribute' => 'alias']); | return \trans('validation.entryexists', ['attribute' => 'alias']); | ||||
} | } | ||||
} | } | ||||
// Check if a group with specified address already exists | |||||
if (Group::emailExists($email)) { | |||||
return \trans('validation.entryexists', ['attribute' => 'alias']); | |||||
} | |||||
return null; | return null; | ||||
} | } | ||||
} | } |