first commit
This commit is contained in:
168
app/adminapi/validate/auth/AdminValidate.php
Normal file
168
app/adminapi/validate/auth/AdminValidate.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\adminapi\validate\auth;
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
use app\common\model\auth\Admin;
|
||||
|
||||
/**
|
||||
* 管理员验证
|
||||
* Class AdminValidate
|
||||
* @package app\adminapi\validate\auth
|
||||
*/
|
||||
class AdminValidate extends BaseValidate
|
||||
{
|
||||
protected $rule = [
|
||||
'id' => 'require|checkAdmin',
|
||||
'account' => 'require|length:1,32|unique:'.Admin::class,
|
||||
'name' => 'require|length:1,16|unique:'.Admin::class,
|
||||
'password' => 'require|length:6,32|edit',
|
||||
'password_confirm' => 'requireWith:password|confirm',
|
||||
'role_id' => 'require',
|
||||
'disable' => 'require|in:0,1|checkAbleDisable',
|
||||
'multipoint_login' => 'require|in:0,1',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '管理员id不能为空',
|
||||
'account.require' => '账号不能为空',
|
||||
'account.length' => '账号长度须在1-32位字符',
|
||||
'account.unique' => '账号已存在',
|
||||
'password.require' => '密码不能为空',
|
||||
'password.length' => '密码长度须在6-32位字符',
|
||||
'password_confirm.requireWith' => '确认密码不能为空',
|
||||
'password_confirm.confirm' => '两次输入的密码不一致',
|
||||
'name.require' => '名称不能为空',
|
||||
'name.length' => '名称须在1-16位字符',
|
||||
'name.unique' => '名称已存在',
|
||||
'role_id.require' => '请选择角色',
|
||||
'disable.require' => '请选择状态',
|
||||
'disable.in' => '状态值错误',
|
||||
'multipoint_login.require' => '请选择是否支持多处登录',
|
||||
'multipoint_login.in' => '多处登录状态值为误',
|
||||
];
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return AdminValidate
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 15:46
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->remove(['password', 'edit'])
|
||||
->remove('id', 'require|checkAdmin')
|
||||
->remove('disable', 'checkAbleDisable');
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return AdminValidate
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 15:46
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return AdminValidate
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 15:47
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->remove('password', 'require|length')
|
||||
->append('id', 'require|checkAdmin');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return AdminValidate
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 15:47
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑情况下,检查是否填密码
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 10:19
|
||||
*/
|
||||
public function edit($value, $rule, $data)
|
||||
{
|
||||
if (empty($data['password']) && empty($data['password_confirm'])) {
|
||||
return true;
|
||||
}
|
||||
$len = strlen($value);
|
||||
if ($len < 6 || $len > 32) {
|
||||
return '密码长度须在6-32位字符';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 检查指定管理员是否存在
|
||||
* @param $value
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 10:19
|
||||
*/
|
||||
public function checkAdmin($value)
|
||||
{
|
||||
$admin = Admin::findOrEmpty($value);
|
||||
if ($admin->isEmpty()) {
|
||||
return '管理员不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 禁用校验
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2022/8/11 9:59
|
||||
*/
|
||||
public function checkAbleDisable($value, $rule, $data)
|
||||
{
|
||||
$admin = Admin::findOrEmpty($data['id']);
|
||||
if ($admin->isEmpty()) {
|
||||
return '管理员不存在';
|
||||
}
|
||||
|
||||
if ($value && $admin['root']) {
|
||||
return '超级管理员不允许被禁用';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
206
app/adminapi/validate/auth/MenuValidate.php
Normal file
206
app/adminapi/validate/auth/MenuValidate.php
Normal file
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\adminapi\validate\auth;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
use app\common\model\auth\{SystemRole,SystemMenu};
|
||||
|
||||
|
||||
/**
|
||||
* 系统菜单
|
||||
* Class SystemMenuValidate
|
||||
* @package app\adminapi\validate\auth
|
||||
*/
|
||||
class MenuValidate extends BaseValidate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'pid' => 'require|checkPid',
|
||||
'type' => 'require|in:M,C,A',
|
||||
'name' => 'require|length:1,30|checkUniqueName',
|
||||
'icon' => 'max:100',
|
||||
'sort' => 'require|egt:0',
|
||||
'perms' => 'max:100',
|
||||
'paths' => 'max:200',
|
||||
'component' => 'max:200',
|
||||
'selected' => 'max:200',
|
||||
'params' => 'max:200',
|
||||
'is_cache' => 'require|in:0,1',
|
||||
'is_show' => 'require|in:0,1',
|
||||
'is_disable' => 'require|in:0,1',
|
||||
];
|
||||
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '参数缺失',
|
||||
'pid.require' => '请选择上级菜单',
|
||||
'type.require' => '请选择菜单类型',
|
||||
'type.in' => '菜单类型参数值错误',
|
||||
'name.require' => '请填写菜单名称',
|
||||
'name.length' => '菜单名称长度需为1~30个字符',
|
||||
'icon.max' => '图标名称不能超过100个字符',
|
||||
'sort.require' => '请填写排序',
|
||||
'sort.egt' => '排序值需大于或等于0',
|
||||
'perms.max' => '权限字符不能超过100个字符',
|
||||
'paths.max' => '路由地址不能超过200个字符',
|
||||
'component.max' => '组件路径不能超过200个字符',
|
||||
'selected.max' => '选中菜单路径不能超过200个字符',
|
||||
'params.max' => '路由参数不能超过200个字符',
|
||||
'is_cache.require' => '请选择缓存状态',
|
||||
'is_cache.in' => '缓存状态参数值错误',
|
||||
'is_show.require' => '请选择显示状态',
|
||||
'is_show.in' => '显示状态参数值错误',
|
||||
'is_disable.require' => '请选择菜单状态',
|
||||
'is_disable.in' => '菜单状态参数值错误',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return MenuValidate
|
||||
* @author 段誉
|
||||
* @date 2022/6/29 18:26
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->remove('id', true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return MenuValidate
|
||||
* @author 段誉
|
||||
* @date 2022/6/29 18:27
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return MenuValidate
|
||||
* @author 段誉
|
||||
* @date 2022/6/29 18:27
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id'])
|
||||
->append('id', 'checkAbleDelete');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 更新状态场景
|
||||
* @return MenuValidate
|
||||
* @author 段誉
|
||||
* @date 2022/7/6 17:04
|
||||
*/
|
||||
public function sceneStatus()
|
||||
{
|
||||
return $this->only(['id', 'is_disable']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 更新排序场景
|
||||
* @return MenuValidate
|
||||
* @author 段誉
|
||||
* @date 2022/7/6 17:04
|
||||
*/
|
||||
public function sceneSort()
|
||||
{
|
||||
return $this->only(['id', 'sort']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 校验菜单名称是否已存在
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2022/6/29 18:24
|
||||
*/
|
||||
protected function checkUniqueName($value, $rule, $data)
|
||||
{
|
||||
if ($data['type'] != 'M') {
|
||||
return true;
|
||||
}
|
||||
$where[] = ['type', '=', $data['type']];
|
||||
$where[] = ['name', '=', $data['name']];
|
||||
|
||||
if (!empty($data['id'])) {
|
||||
$where[] = ['id', '<>', $data['id']];
|
||||
}
|
||||
|
||||
$check = SystemMenu::where($where)->findOrEmpty();
|
||||
|
||||
if (!$check->isEmpty()) {
|
||||
return '菜单名称已存在';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 是否有子级菜单
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2022/6/30 9:40
|
||||
*/
|
||||
protected function checkAbleDelete($value, $rule, $data)
|
||||
{
|
||||
$hasChild = SystemMenu::where(['pid' => $value])->findOrEmpty();
|
||||
if (!$hasChild->isEmpty()) {
|
||||
return '存在子菜单,不允许删除';
|
||||
}
|
||||
|
||||
// 已绑定角色菜单不可以删除
|
||||
$isBindRole = SystemRole::hasWhere('roleMenuIndex', ['menu_id' => $value])->findOrEmpty();
|
||||
if (!$isBindRole->isEmpty()) {
|
||||
return '已分配菜单不可删除';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 校验上级
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2022/6/30 9:51
|
||||
*/
|
||||
protected function checkPid($value, $rule, $data)
|
||||
{
|
||||
if (!empty($data['id']) && $data['id'] == $value) {
|
||||
return '上级菜单不能选择自己';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
119
app/adminapi/validate/auth/RoleValidate.php
Normal file
119
app/adminapi/validate/auth/RoleValidate.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\adminapi\validate\auth;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
use app\common\model\auth\{AdminRole, SystemRole, Admin};
|
||||
|
||||
/**
|
||||
* 角色验证器
|
||||
* Class RoleValidate
|
||||
* @package app\adminapi\validate\auth
|
||||
*/
|
||||
class RoleValidate extends BaseValidate
|
||||
{
|
||||
protected $rule = [
|
||||
'id' => 'require|checkRole',
|
||||
'name' => 'require|max:64|unique:' . SystemRole::class . ',name',
|
||||
'menu_id' => 'array',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '请选择角色',
|
||||
'name.require' => '请输入角色名称',
|
||||
'name.max' => '角色名称最长为16个字符',
|
||||
'name.unique' => '角色名称已存在',
|
||||
'menu_id.array' => '权限格式错误'
|
||||
];
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return RoleValidate
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 15:47
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->only(['name', 'menu_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return RoleValidate
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 15:47
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return RoleValidate
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 15:48
|
||||
*/
|
||||
public function sceneDel()
|
||||
{
|
||||
return $this->only(['id'])
|
||||
->append('id', 'checkAdmin');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 验证角色是否存在
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 15:48
|
||||
*/
|
||||
public function checkRole($value, $rule, $data)
|
||||
{
|
||||
if (!SystemRole::find($value)) {
|
||||
return '角色不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @notes 验证角色是否被使用
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 15:49
|
||||
*/
|
||||
public function checkAdmin($value, $rule, $data)
|
||||
{
|
||||
if (AdminRole::where(['role_id' => $value])->find()) {
|
||||
return '有管理员在使用该角色,不允许删除';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
74
app/adminapi/validate/auth/editSelfValidate.php
Normal file
74
app/adminapi/validate/auth/editSelfValidate.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\adminapi\validate\auth;
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
use app\common\model\auth\Admin;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* 编辑超级管理员验证
|
||||
* Class editSelfValidate
|
||||
* @package app\adminapi\validate\auth
|
||||
*/
|
||||
class editSelfValidate extends BaseValidate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'name' => 'require|length:1,16',
|
||||
'avatar' => 'require',
|
||||
'password_old' => 'length:6,32',
|
||||
'password' => 'length:6,32|checkPassword',
|
||||
'password_confirm' => 'requireWith:password|confirm',
|
||||
];
|
||||
|
||||
|
||||
protected $message = [
|
||||
'name.require' => '请填写名称',
|
||||
'name.length' => '名称须在1-16位字符',
|
||||
'avatar.require' => '请选择头像',
|
||||
'password_now.length' => '密码长度须在6-32位字符',
|
||||
'password_confirm.requireWith' => '确认密码不能为空',
|
||||
'password_confirm.confirm' => '两次输入的密码不一致',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 校验密码
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2022/4/8 17:40
|
||||
*/
|
||||
public function checkPassword($value, $rule, $data)
|
||||
{
|
||||
if (empty($data['password_old'])) {
|
||||
return '请填写当前密码';
|
||||
}
|
||||
|
||||
$admin = Admin::findOrEmpty($data['admin_id']);
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
$oldPassword = create_password($data['password_old'], $passwordSalt);
|
||||
|
||||
if ($admin['password'] != $oldPassword) {
|
||||
return '当前密码错误';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user