Changeset View
Changeset View
Standalone View
Standalone View
src/app/User.php
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | class User extends Authenticatable | ||||
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; | ||||
// a restricted user | // a restricted user | ||||
public const STATUS_RESTRICTED = 1 << 7; | public const STATUS_RESTRICTED = 1 << 7; | ||||
/** @var int The allowed states for this object used in StatusPropertyTrait */ | |||||
private int $allowed_states = self::STATUS_NEW | | |||||
self::STATUS_ACTIVE | | |||||
self::STATUS_SUSPENDED | | |||||
self::STATUS_DELETED | | |||||
self::STATUS_LDAP_READY | | |||||
self::STATUS_IMAP_READY | | |||||
self::STATUS_DEGRADED | | |||||
self::STATUS_RESTRICTED; | |||||
/** @var array<int, string> The attributes that are mass assignable */ | /** @var array<int, string> The attributes that are mass assignable */ | ||||
protected $fillable = [ | protected $fillable = [ | ||||
'id', | 'id', | ||||
'email', | 'email', | ||||
'password', | 'password', | ||||
'password_ldap', | 'password_ldap', | ||||
'status', | 'status', | ||||
]; | ]; | ||||
▲ Show 20 Lines • Show All 470 Lines • ▼ Show 20 Lines | public function undegrade(): void | ||||
$this->status ^= User::STATUS_DEGRADED; | $this->status ^= User::STATUS_DEGRADED; | ||||
$this->save(); | $this->save(); | ||||
} | } | ||||
/** | /** | ||||
* Un-restrict this user. | * Un-restrict this user. | ||||
* | * | ||||
* @param bool $deep Unrestrinct also all users in the account | * @param bool $deep Unrestrict also all users in the account | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function unrestrict(bool $deep = false): void | public function unrestrict(bool $deep = false): void | ||||
{ | { | ||||
if ($this->isRestricted()) { | if ($this->isRestricted()) { | ||||
$this->status ^= User::STATUS_RESTRICTED; | $this->status ^= User::STATUS_RESTRICTED; | ||||
$this->save(); | $this->save(); | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | class User extends Authenticatable | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function setPasswordLdapAttribute($password) | public function setPasswordLdapAttribute($password) | ||||
{ | { | ||||
$this->setPasswordAttribute($password); | $this->setPasswordAttribute($password); | ||||
} | } | ||||
/** | /** | ||||
* User status mutator | |||||
* | |||||
* @throws \Exception | |||||
*/ | |||||
public function setStatusAttribute($status) | |||||
{ | |||||
$new_status = 0; | |||||
$allowed_values = [ | |||||
self::STATUS_NEW, | |||||
self::STATUS_ACTIVE, | |||||
self::STATUS_SUSPENDED, | |||||
self::STATUS_DELETED, | |||||
self::STATUS_LDAP_READY, | |||||
self::STATUS_IMAP_READY, | |||||
self::STATUS_DEGRADED, | |||||
self::STATUS_RESTRICTED, | |||||
]; | |||||
foreach ($allowed_values as $value) { | |||||
if ($status & $value) { | |||||
$new_status |= $value; | |||||
$status ^= $value; | |||||
} | |||||
} | |||||
if ($status > 0) { | |||||
throw new \Exception("Invalid user status: {$status}"); | |||||
} | |||||
$this->attributes['status'] = $new_status; | |||||
} | |||||
/** | |||||
* Validate the user credentials | * Validate the user credentials | ||||
* | * | ||||
* @param string $username The username. | * @param string $username The username. | ||||
* @param string $password The password in plain text. | * @param string $password The password in plain text. | ||||
* @param bool $updatePassword Store the password if currently empty | * @param bool $updatePassword Store the password if currently empty | ||||
* | * | ||||
* @return bool true on success | * @return bool true on success | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 184 Lines • Show Last 20 Lines |