Changeset View
Changeset View
Standalone View
Standalone View
src/app/User.php
<?php | <?php | ||||
namespace App; | namespace App; | ||||
use App\Traits\AliasesTrait; | use App\Traits\AliasesTrait; | ||||
use App\Traits\BelongsToTenantTrait; | use App\Traits\BelongsToTenantTrait; | ||||
use App\Traits\EntitleableTrait; | use App\Traits\EntitleableTrait; | ||||
use App\Traits\EmailPropertyTrait; | use App\Traits\EmailPropertyTrait; | ||||
use App\Traits\UserConfigTrait; | use App\Traits\UserConfigTrait; | ||||
use App\Traits\UuidIntKeyTrait; | use App\Traits\UuidIntKeyTrait; | ||||
use App\Traits\SettingsTrait; | use App\Traits\SettingsTrait; | ||||
use App\Traits\StatusPropertyTrait; | use App\Traits\StatusPropertyTrait; | ||||
use Illuminate\Database\Eloquent\SoftDeletes; | use Illuminate\Database\Eloquent\SoftDeletes; | ||||
use Illuminate\Support\Facades\DB; | use Illuminate\Support\Facades\DB; | ||||
use Illuminate\Support\Facades\Hash; | use Illuminate\Support\Facades\Hash; | ||||
use Illuminate\Foundation\Auth\User as Authenticatable; | use Illuminate\Foundation\Auth\User as Authenticatable; | ||||
use Iatstuti\Database\Support\NullableFields; | use Dyrynda\Database\Support\NullableFields; | ||||
use Laravel\Passport\HasApiTokens; | use Laravel\Passport\HasApiTokens; | ||||
use League\OAuth2\Server\Exception\OAuthServerException; | use League\OAuth2\Server\Exception\OAuthServerException; | ||||
/** | /** | ||||
* The eloquent definition of a User. | * The eloquent definition of a User. | ||||
* | * | ||||
* @property string $email | * @property string $email | ||||
* @property int $id | * @property int $id | ||||
Show All 26 Lines | class User extends Authenticatable | ||||
public const STATUS_DELETED = 1 << 3; | public const STATUS_DELETED = 1 << 3; | ||||
// user has been created in LDAP | // user has been created in LDAP | ||||
public const STATUS_LDAP_READY = 1 << 4; | public const STATUS_LDAP_READY = 1 << 4; | ||||
// user mailbox has been created in IMAP | // user mailbox has been created in IMAP | ||||
public const STATUS_IMAP_READY = 1 << 5; | public const STATUS_IMAP_READY = 1 << 5; | ||||
// user in "limited feature-set" state | // user in "limited feature-set" state | ||||
public const STATUS_DEGRADED = 1 << 6; | public const STATUS_DEGRADED = 1 << 6; | ||||
/** | /** @var array<int, string> The attributes that are mass assignable */ | ||||
* The attributes that are mass assignable. | |||||
* | |||||
* @var array | |||||
*/ | |||||
protected $fillable = [ | protected $fillable = [ | ||||
'id', | 'id', | ||||
'email', | 'email', | ||||
'password', | 'password', | ||||
'password_ldap', | 'password_ldap', | ||||
'status', | 'status', | ||||
]; | ]; | ||||
/** | /** @var array<int, string> The attributes that should be hidden for arrays */ | ||||
* The attributes that should be hidden for arrays. | |||||
* | |||||
* @var array | |||||
*/ | |||||
protected $hidden = [ | protected $hidden = [ | ||||
'password', | 'password', | ||||
'password_ldap', | 'password_ldap', | ||||
'role' | 'role' | ||||
]; | ]; | ||||
/** @var array<int, string> The attributes that can be null */ | |||||
protected $nullable = [ | protected $nullable = [ | ||||
'password', | 'password', | ||||
'password_ldap' | 'password_ldap' | ||||
]; | ]; | ||||
/** @var array<string, string> The attributes that should be cast */ | |||||
protected $casts = [ | |||||
'created_at' => 'datetime:Y-m-d H:i:s', | |||||
'deleted_at' => 'datetime:Y-m-d H:i:s', | |||||
'updated_at' => 'datetime:Y-m-d H:i:s', | |||||
]; | |||||
/** | /** | ||||
* Any wallets on which this user is a controller. | * Any wallets on which this user is a controller. | ||||
* | * | ||||
* This does not include wallets owned by the user. | * This does not include wallets owned by the user. | ||||
* | * | ||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | ||||
*/ | */ | ||||
public function accounts() | public function accounts() | ||||
▲ Show 20 Lines • Show All 235 Lines • ▼ Show 20 Lines | public static function findByEmail(string $email, bool $external = false): ?User | ||||
$email = \strtolower($email); | $email = \strtolower($email); | ||||
$user = self::where('email', $email)->first(); | $user = self::where('email', $email)->first(); | ||||
if ($user) { | if ($user) { | ||||
return $user; | return $user; | ||||
} | } | ||||
$aliases = \App\UserAlias::where('alias', $email)->get(); | $aliases = UserAlias::where('alias', $email)->get(); | ||||
if (count($aliases) == 1) { | if (count($aliases) == 1) { | ||||
return $aliases->first()->user; | return $aliases->first()->user; | ||||
} | } | ||||
// TODO: External email | // TODO: External email | ||||
return null; | return null; | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | class User extends Authenticatable | ||||
*/ | */ | ||||
public function name(bool $fallback = false): string | public function name(bool $fallback = false): string | ||||
{ | { | ||||
$settings = $this->getSettings(['first_name', 'last_name']); | $settings = $this->getSettings(['first_name', 'last_name']); | ||||
$name = trim($settings['first_name'] . ' ' . $settings['last_name']); | $name = trim($settings['first_name'] . ' ' . $settings['last_name']); | ||||
if (empty($name) && $fallback) { | if (empty($name) && $fallback) { | ||||
return trim(\trans('app.siteuser', ['site' => \App\Tenant::getConfig($this->tenant_id, 'app.name')])); | return trim(\trans('app.siteuser', ['site' => Tenant::getConfig($this->tenant_id, 'app.name')])); | ||||
} | } | ||||
return $name; | return $name; | ||||
} | } | ||||
/** | /** | ||||
* Old passwords for this user. | * Old passwords for this user. | ||||
* | * | ||||
Show All 9 Lines | class User extends Authenticatable | ||||
* | * | ||||
* @param bool $with_accounts Include resources assigned to wallets | * @param bool $with_accounts Include resources assigned to wallets | ||||
* the current user controls but not owns. | * the current user controls but not owns. | ||||
* | * | ||||
* @return \Illuminate\Database\Eloquent\Builder Query builder | * @return \Illuminate\Database\Eloquent\Builder Query builder | ||||
*/ | */ | ||||
public function resources($with_accounts = true) | public function resources($with_accounts = true) | ||||
{ | { | ||||
return $this->entitleables(\App\Resource::class, $with_accounts); | return $this->entitleables(Resource::class, $with_accounts); | ||||
} | } | ||||
/** | /** | ||||
* Return shared folders controlled by the current user. | * Return shared folders controlled by the current user. | ||||
* | * | ||||
* @param bool $with_accounts Include folders assigned to wallets | * @param bool $with_accounts Include folders assigned to wallets | ||||
* the current user controls but not owns. | * the current user controls but not owns. | ||||
* | * | ||||
* @return \Illuminate\Database\Eloquent\Builder Query builder | * @return \Illuminate\Database\Eloquent\Builder Query builder | ||||
*/ | */ | ||||
public function sharedFolders($with_accounts = true) | public function sharedFolders($with_accounts = true) | ||||
{ | { | ||||
return $this->entitleables(\App\SharedFolder::class, $with_accounts); | return $this->entitleables(SharedFolder::class, $with_accounts); | ||||
} | } | ||||
public function senderPolicyFrameworkWhitelist($clientName) | public function senderPolicyFrameworkWhitelist($clientName) | ||||
{ | { | ||||
$setting = $this->getSetting('spf_whitelist'); | $setting = $this->getSetting('spf_whitelist'); | ||||
if (!$setting) { | if (!$setting) { | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 264 Lines • Show Last 20 Lines |