feat: Authentication
- Update User model - Create authentication controller - Update api router
هذا الالتزام موجود في:
@@ -2,31 +2,36 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
'phone',
|
||||
'role',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'profile_image',
|
||||
'birth_date',
|
||||
'id_image',
|
||||
'is_approved',
|
||||
'password', // We'll still use password for authentication
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
@@ -34,15 +39,53 @@ class User extends Authenticatable
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
protected $casts = [
|
||||
'birth_date' => 'date',
|
||||
'is_approved' => 'boolean',
|
||||
'approved_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the user's full name
|
||||
*/
|
||||
public function getFullNameAttribute()
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
return "{$this->first_name} {$this->last_name}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is a tenant
|
||||
*/
|
||||
public function isTenant()
|
||||
{
|
||||
return $this->role === 'tenant';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is an owner
|
||||
*/
|
||||
public function isOwner()
|
||||
{
|
||||
return $this->role === 'owner';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is an admin
|
||||
*/
|
||||
public function isAdmin()
|
||||
{
|
||||
return $this->role === 'admin';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is approved
|
||||
*/
|
||||
public function isApproved()
|
||||
{
|
||||
return $this->is_approved;
|
||||
}
|
||||
}
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم