first commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string|null $capital
|
||||
* @property string|null $citizenship
|
||||
* @property string $country_code
|
||||
* @property string|null $currency
|
||||
* @property string|null $currency_code
|
||||
* @property string|null $currency_sub_unit
|
||||
* @property string|null $currency_symbol
|
||||
* @property string|null $full_name
|
||||
* @property string $iso_3166_2
|
||||
* @property string $iso_3166_3
|
||||
* @property string $name
|
||||
* @property string $region_code
|
||||
* @property string $sub_region_code
|
||||
* @property int $eea
|
||||
* @property string|null $calling_code
|
||||
* @property string|null $flag
|
||||
*/
|
||||
class Country extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'countries';
|
||||
|
||||
public $timestamps = false;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $display_name
|
||||
* @property string $description
|
||||
* @property bool $removable
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $deleted_at
|
||||
*/
|
||||
class Permission extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'permissions';
|
||||
|
||||
protected $fillable = ['name', 'display_name', 'description'];
|
||||
|
||||
protected $casts = [
|
||||
'removable' => 'boolean',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Support\Authorization\AuthorizationRoleTrait;
|
||||
use Database\Factories\RoleFactory;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $display_name
|
||||
* @property string $description
|
||||
* @property bool $removable
|
||||
* @property Collection<User> $users
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $deleted_at
|
||||
*/
|
||||
class Role extends Model
|
||||
{
|
||||
use AuthorizationRoleTrait, HasFactory;
|
||||
|
||||
public const DEFAULT_USER_ROLE = 'User';
|
||||
|
||||
public const DEFAULT_ADMIN_ROLE = 'Admin';
|
||||
|
||||
protected $table = 'roles';
|
||||
|
||||
protected $casts = [
|
||||
'removable' => 'boolean',
|
||||
];
|
||||
|
||||
protected $fillable = ['name', 'display_name', 'description'];
|
||||
|
||||
public function users(): HasMany
|
||||
{
|
||||
return $this->hasMany(User::class, 'role_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new factory instance for the model.
|
||||
*/
|
||||
protected static function newFactory(): Factory
|
||||
{
|
||||
return new RoleFactory;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Events\User\RequestedPasswordResetEmail;
|
||||
use App\Mail\ResetPassword;
|
||||
use App\Presenters\Traits\Presentable;
|
||||
use App\Presenters\UserPresenter;
|
||||
use App\Support\Authorization\AuthorizationUserTrait;
|
||||
use App\Support\CanImpersonateUsers;
|
||||
use App\Support\Enum\UserStatus;
|
||||
use Illuminate\Auth\Passwords\CanResetPassword;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Laravel\Fortify\TwoFactorAuthenticatable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Mail;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $first_name
|
||||
* @property string $last_name
|
||||
* @property string $email
|
||||
* @property string $username
|
||||
* @property string $phone
|
||||
* @property string|null $avatar
|
||||
* @property string|null $address
|
||||
* @property int|null $country_id
|
||||
* @property Carbon $last_login
|
||||
* @property Carbon $birthday
|
||||
* @property UserStatus $status
|
||||
* @property string|null $confirmation_token
|
||||
* @property string|null $remember_token
|
||||
* @property int $role_id
|
||||
* @property Carbon|null $email_verified_at
|
||||
* @property string $two_factor_country_code
|
||||
* @property string $two_factor_phone
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $deleted_at
|
||||
*/
|
||||
class User extends Authenticatable implements MustVerifyEmail
|
||||
{
|
||||
use AuthorizationUserTrait,
|
||||
CanImpersonateUsers,
|
||||
CanResetPassword,
|
||||
HasApiTokens,
|
||||
HasFactory,
|
||||
Notifiable,
|
||||
Presentable,
|
||||
TwoFactorAuthenticatable;
|
||||
|
||||
protected string $presenter = UserPresenter::class;
|
||||
|
||||
/**
|
||||
* The database table used by the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'users';
|
||||
|
||||
protected $casts = [
|
||||
'last_login' => 'datetime',
|
||||
'birthday' => 'date',
|
||||
'status' => UserStatus::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'email', 'password', 'username', 'first_name', 'last_name', 'phone', 'avatar',
|
||||
'address', 'country_id', 'birthday', 'last_login', 'confirmation_token', 'status',
|
||||
'remember_token', 'role_id', 'email_verified_at', 'force_password_change',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = ['password', 'remember_token'];
|
||||
|
||||
/**
|
||||
* Always encrypt password when it is updated.
|
||||
*/
|
||||
public function setPasswordAttribute(string $value): void
|
||||
{
|
||||
$this->attributes['password'] = bcrypt($value);
|
||||
}
|
||||
|
||||
public function setBirthdayAttribute($value): void
|
||||
{
|
||||
$this->attributes['birthday'] = trim($value) ?: null;
|
||||
}
|
||||
|
||||
public function gravatar(): string
|
||||
{
|
||||
$hash = hash('md5', strtolower(trim($this->attributes['email'])));
|
||||
|
||||
return sprintf('https://www.gravatar.com/avatar/%s?size=150', $hash);
|
||||
}
|
||||
|
||||
public function isUnconfirmed(): bool
|
||||
{
|
||||
return $this->status == UserStatus::UNCONFIRMED;
|
||||
}
|
||||
|
||||
public function isActive(): bool
|
||||
{
|
||||
return $this->status == UserStatus::ACTIVE;
|
||||
}
|
||||
|
||||
public function isBanned(): bool
|
||||
{
|
||||
return $this->status == UserStatus::BANNED;
|
||||
}
|
||||
|
||||
public function isWaitingApproval(): bool
|
||||
{
|
||||
return $this->status == UserStatus::WAITING_APPROVAL;
|
||||
}
|
||||
|
||||
public function country(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Country::class, 'country_id');
|
||||
}
|
||||
|
||||
public function sendPasswordResetNotification($token): void
|
||||
{
|
||||
Mail::to($this)->send(new ResetPassword($token));
|
||||
|
||||
event(new RequestedPasswordResetEmail($this));
|
||||
}
|
||||
|
||||
public function twoFactorEnabled(): bool
|
||||
{
|
||||
return (bool) $this->two_factor_confirmed_at && (bool) $this->two_factor_secret;
|
||||
}
|
||||
|
||||
public function needsTwoFactorVerification(): bool
|
||||
{
|
||||
return ! $this->two_factor_confirmed_at && (bool) $this->two_factor_secret;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user