first commit
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Tymon\JWTAuth\Contracts\JWTSubject;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use App\Traits\ModelTrait;
|
||||
|
||||
class Admin extends Authenticatable implements JWTSubject {
|
||||
use Notifiable, ModelTrait;
|
||||
|
||||
protected $table = 'auth_admins';
|
||||
protected $primaryKey = 'uid';
|
||||
protected $fillable = ['username', 'nickname', 'email', 'mobile', 'password', 'department_id', 'status', 'last_login_at', 'last_login_ip'];
|
||||
protected $hidden = ['password', 'deleted_at'];
|
||||
protected $with = ['department', 'roles'];
|
||||
|
||||
// Rest omitted for brevity
|
||||
|
||||
/**
|
||||
* Get the identifier that will be stored in the subject claim of the JWT.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getJWTIdentifier() {
|
||||
return $this->getKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a key value array, containing any custom claims to be added to the JWT.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJWTCustomClaims() {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function password() : Attribute {
|
||||
return new Attribute(
|
||||
set: fn ($value) => Hash::make($value),
|
||||
);
|
||||
}
|
||||
|
||||
public function department(){
|
||||
return $this->belongsTo(Department::class, 'department_id', 'id');
|
||||
}
|
||||
|
||||
public function roles(){
|
||||
return $this->belongsToMany(Role::class, 'auth_admins_roles', 'uid', 'role_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\Auth;
|
||||
|
||||
class Department extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'auth_departments';
|
||||
protected $fillable = ['title', 'name', 'parent_id', 'status', 'sort'];
|
||||
protected $hidden = ['deleted_at'];
|
||||
|
||||
protected function casts(): array {
|
||||
return [
|
||||
'parent_id' => 'integer',
|
||||
'sort' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function members(){
|
||||
return $this->hasMany(Admin::class, 'department_id', 'uid');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class Permission extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'auth_permissions';
|
||||
protected $fillable = ['title', 'name', 'parent_id', 'hiddenBreadcrumb', 'hidden', 'affix', 'color', 'fullpage', 'icon', 'status', 'sort'];
|
||||
protected $hidden = ['deleted_at'];
|
||||
|
||||
public function meta() : Attribute {
|
||||
return Attribute::make(
|
||||
get: fn (mixed $value, array $data) => [
|
||||
'id' => $data['id'],
|
||||
'parent_id' => $data['parent_id'],
|
||||
'title' => $data['title'],
|
||||
'hiddenBreadcrumb' => $data['hiddenBreadcrumb'],
|
||||
'hidden' => $data['hidden'],
|
||||
'affix' => $data['affix'],
|
||||
'color' => $data['color'],
|
||||
'fullpage' => $data['fullpage'],
|
||||
'icon' => isset($data['icon']) && $data['icon'] ? $data['icon'] : 'el-icon-document',
|
||||
// 'icon' => isset($data['icon']) && $data['icon'] ? $data['icon'] : 'AIconFileTextOutlined',
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
public function roles(){
|
||||
return $this->belongsToMany(Role::class, 'auth_roles_permissions', 'permission_id', 'role_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\Auth;
|
||||
|
||||
class Role extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'auth_roles';
|
||||
protected $fillable = ['title', 'name', 'data_range', 'sort', 'status', 'description'];
|
||||
protected $hidden = ['deleted_at'];
|
||||
|
||||
public function admins(){
|
||||
return $this->belongsToMany(Admin::class, 'auth_admins_roles', 'role_id', 'uid');
|
||||
}
|
||||
public function permissions(){
|
||||
return $this->belongsToMany(Permission::class, 'auth_roles_permissions', 'role_id', 'permission_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user