Changeset View
Changeset View
Standalone View
Standalone View
src/app/User.php
<?php | <?php | ||||
namespace App; | namespace App; | ||||
use App\Entitlement; | use App\Entitlement; | ||||
use App\UserAlias; | use App\UserAlias; | ||||
use App\Traits\UserAliasesTrait; | use App\Traits\UserAliasesTrait; | ||||
use App\Traits\UserSettingsTrait; | use App\Traits\UserSettingsTrait; | ||||
use App\Wallet; | use App\Wallet; | ||||
use Illuminate\Notifications\Notifiable; | use Illuminate\Notifications\Notifiable; | ||||
use Illuminate\Contracts\Auth\MustVerifyEmail; | |||||
use Illuminate\Database\Eloquent\SoftDeletes; | use Illuminate\Database\Eloquent\SoftDeletes; | ||||
use Illuminate\Foundation\Auth\User as Authenticatable; | use Illuminate\Foundation\Auth\User as Authenticatable; | ||||
use Iatstuti\Database\Support\NullableFields; | use Iatstuti\Database\Support\NullableFields; | ||||
use Tymon\JWTAuth\Contracts\JWTSubject; | use Tymon\JWTAuth\Contracts\JWTSubject; | ||||
/** | /** | ||||
* The eloquent definition of a User. | * The eloquent definition of a User. | ||||
* | * | ||||
* @property string $email | * @property string $email | ||||
* @property int $id | * @property int $id | ||||
* @property string $name | |||||
* @property string $password | * @property string $password | ||||
* @property int $status | * @property int $status | ||||
*/ | */ | ||||
class User extends Authenticatable implements JWTSubject | class User extends Authenticatable implements JWTSubject | ||||
{ | { | ||||
use Notifiable; | use Notifiable; | ||||
use NullableFields; | use NullableFields; | ||||
use UserAliasesTrait; | use UserAliasesTrait; | ||||
Show All 19 Lines | class User extends Authenticatable implements JWTSubject | ||||
protected $keyType = 'bigint'; | protected $keyType = 'bigint'; | ||||
/** | /** | ||||
* The attributes that are mass assignable. | * The attributes that are mass assignable. | ||||
* | * | ||||
* @var array | * @var array | ||||
*/ | */ | ||||
protected $fillable = [ | protected $fillable = [ | ||||
'name', | |||||
'email', | 'email', | ||||
'password', | 'password', | ||||
'password_ldap', | 'password_ldap', | ||||
'status' | 'status' | ||||
]; | ]; | ||||
/** | /** | ||||
* The attributes that should be hidden for arrays. | * The attributes that should be hidden for arrays. | ||||
* | * | ||||
* @var array | * @var array | ||||
*/ | */ | ||||
protected $hidden = [ | protected $hidden = [ | ||||
'password', | 'password', | ||||
'password_ldap', | 'password_ldap', | ||||
'remember_token', | |||||
'role' | 'role' | ||||
]; | ]; | ||||
protected $nullable = [ | protected $nullable = [ | ||||
'name', | |||||
'password', | 'password', | ||||
'password_ldap' | 'password_ldap' | ||||
]; | ]; | ||||
/** | /** | ||||
* The attributes that should be cast to native types. | |||||
* | |||||
* @var array | |||||
*/ | |||||
protected $casts = [ | |||||
'email_verified_at' => 'datetime', | |||||
]; | |||||
/** | |||||
* 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 351 Lines • ▼ Show 20 Lines | class User extends Authenticatable implements JWTSubject | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isSuspended(): bool | public function isSuspended(): bool | ||||
{ | { | ||||
return ($this->status & self::STATUS_SUSPENDED) > 0; | return ($this->status & self::STATUS_SUSPENDED) > 0; | ||||
} | } | ||||
/** | /** | ||||
* A shortcut to get the user name. | |||||
* | |||||
* @param bool $fallback Return "<aa.name> User" if there's no name | |||||
* | |||||
* @return string Full user name | |||||
*/ | |||||
public function name(bool $fallback = false): string | |||||
{ | |||||
$firstname = $this->getSetting('first_name'); | |||||
$lastname = $this->getSetting('last_name'); | |||||
$name = trim($firstname . ' ' . $lastname); | |||||
if (empty($name) && $fallback) { | |||||
return \config('app.name') . ' User'; | |||||
} | |||||
return $name; | |||||
} | |||||
/** | |||||
* Any (additional) properties of this user. | * Any (additional) properties of this user. | ||||
* | * | ||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany | * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||||
*/ | */ | ||||
public function settings() | public function settings() | ||||
{ | { | ||||
return $this->hasMany('App\UserSetting', 'user_id'); | return $this->hasMany('App\UserSetting', 'user_id'); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 154 Lines • Show Last 20 Lines |