新增修改密码功能和重置密码功能
This commit is contained in:
parent
0f8d226c7b
commit
f879d27fac
11
README.md
11
README.md
@ -14,6 +14,17 @@
|
||||
## 二、安装教程
|
||||
|
||||
- [根据 Thinkphp6 安装](https://www.kancloud.cn/manual/thinkphp6_0/1037479)
|
||||
- 伪静态
|
||||
```
|
||||
location ~* (runtime|application)/{
|
||||
return 403;
|
||||
}
|
||||
location / {
|
||||
if (!-e $request_filename){
|
||||
rewrite ^(.*)$ /index.php?s=$1 last; break;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 三、使用说明
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@ use app\admin\model\YzAdminConfig;
|
||||
|
||||
class Login
|
||||
{
|
||||
// 登录页面
|
||||
public function index()
|
||||
{
|
||||
# 获取配置
|
||||
@ -23,6 +24,8 @@ class Login
|
||||
]);
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
// 登录
|
||||
public function login()
|
||||
{
|
||||
if (Request::isPost()) {
|
||||
@ -69,12 +72,16 @@ class Login
|
||||
$this->returnCode(0, [], '登陆成功');
|
||||
}
|
||||
}
|
||||
|
||||
// 退出
|
||||
public function logout()
|
||||
{
|
||||
Cookie::delete('admin_id');
|
||||
Cookie::delete('admin_name');
|
||||
$this->returnCode(0, [], '退出成功');
|
||||
}
|
||||
|
||||
// 返回代码
|
||||
protected function returnCode($code, $data = [], $msg = '')
|
||||
{
|
||||
header('Content-type:application/json');
|
||||
@ -101,4 +108,46 @@ class Login
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// 密码重置页面
|
||||
public function resetpwdindex()
|
||||
{
|
||||
return View::fetch('resetpwd');
|
||||
}
|
||||
|
||||
//管理员密码重置
|
||||
public function resetpwd()
|
||||
{
|
||||
$account = trim(input('post.account'));
|
||||
if (empty($account)) {
|
||||
$this->returnCode(1, '账号不能为空');
|
||||
}
|
||||
|
||||
$user = Db::table('yz_admin_user')->where('account', $account)->find();
|
||||
|
||||
if (!$user) {
|
||||
$this->returnCode(1, '未找到该用户名');
|
||||
}
|
||||
|
||||
// 使用md5进行密码加密处理
|
||||
$password = md5('123456');
|
||||
|
||||
try {
|
||||
$res = Db::table('yz_admin_user')
|
||||
->where('account', $account)
|
||||
->update(['password' => $password]);
|
||||
|
||||
if ($res === false) {
|
||||
$this->returnCode(1, '数据库更新失败');
|
||||
}
|
||||
|
||||
if ($res === 0) {
|
||||
$this->returnCode(1, '密码未发生变化');
|
||||
}
|
||||
|
||||
$this->returnCode(0, [], '密码重置成功');
|
||||
} catch (\Exception $e) {
|
||||
$this->returnCode(1, '系统错误:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,6 +6,7 @@ use think\facade\View;
|
||||
use think\facade\Request;
|
||||
|
||||
class Yunzeradmin extends Base{
|
||||
// 角色列表
|
||||
public function groupinfo(){
|
||||
$group = Db::table('yz_admin_user_group')->select();
|
||||
View::assign([
|
||||
@ -13,11 +14,13 @@ class Yunzeradmin extends Base{
|
||||
]);
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
// 角色添加
|
||||
public function groupadd(){
|
||||
if(Request::isPost()){
|
||||
$data['group_name'] = trim(input('post.group_name'));
|
||||
if(!$data['group_name']){
|
||||
$this->returnCode('90000008');
|
||||
$this->returnCode(1, '角色名称不能为空');
|
||||
}
|
||||
$data['status'] = (int)trim(input('post.status'));
|
||||
$data['create_time'] = time();
|
||||
@ -27,7 +30,7 @@ class Yunzeradmin extends Base{
|
||||
}
|
||||
$res = Db::table('yz_admin_user_group')->insert($data);
|
||||
if(!$res){
|
||||
$this->returnCode('91000001');
|
||||
$this->returnCode(1, '添加角色失败');
|
||||
}
|
||||
$this->returnCode(0);
|
||||
}else{
|
||||
@ -55,12 +58,14 @@ class Yunzeradmin extends Base{
|
||||
return View::fetch();
|
||||
}
|
||||
}
|
||||
|
||||
// 角色编辑
|
||||
public function groupedit(){
|
||||
if(Request::isPost()){
|
||||
$group_id = (int)trim(input('post.group_id'));
|
||||
$data['group_name'] = trim(input('post.group_name'));
|
||||
if(!$data['group_name']){
|
||||
$this->returnCode('90000008');
|
||||
$this->returnCode(1, '角色名称不能为空');
|
||||
}
|
||||
$data['status'] = (int)trim(input('post.status'));
|
||||
$menus = input('post.menu/a');
|
||||
@ -71,7 +76,7 @@ class Yunzeradmin extends Base{
|
||||
}
|
||||
$res = Db::table('yz_admin_user_group')->where('group_id',$group_id)->update($data);
|
||||
if(!$res){
|
||||
$this->returnCode('91000002');
|
||||
$this->returnCode(1, '更新角色失败');
|
||||
}
|
||||
$this->returnCode(0);
|
||||
}else{
|
||||
@ -106,14 +111,18 @@ class Yunzeradmin extends Base{
|
||||
return View::fetch();
|
||||
}
|
||||
}
|
||||
|
||||
// 角色删除
|
||||
public function groupdel(){
|
||||
$group_id = (int)input('post.group_id');
|
||||
$res = Db::table('yz_admin_user_group')->where('group_id',$group_id)->delete();
|
||||
if(empty($res)){
|
||||
$this->returnCode('91000003');
|
||||
$this->returnCode(1, '删除角色失败');
|
||||
}
|
||||
$this->returnCode(0);
|
||||
}
|
||||
|
||||
// 管理员列表
|
||||
public function userinfo(){
|
||||
$lists = Db::table('yz_admin_user')->select();
|
||||
$group = [];
|
||||
@ -127,19 +136,21 @@ class Yunzeradmin extends Base{
|
||||
]);
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
// 管理员添加
|
||||
public function useradd(){
|
||||
if(Request::isPost()){
|
||||
$data['account'] = trim(input('post.account'));
|
||||
if(empty($data['account'])){
|
||||
$this->returnCode('90000001');
|
||||
$this->returnCode(1, '账号不能为空');
|
||||
}
|
||||
$pattern = "/^([0-9A-Za-z-_.]+)@([0-9a-z]+.[a-z]{2,3}(.[a-z]{2})?)$/i";
|
||||
if(!preg_match($pattern,$data['account'])){
|
||||
$this->returnCode('90000006');
|
||||
$this->returnCode(1, '邮箱格式不正确');
|
||||
}
|
||||
$item = Db::table('yz_admin_user')->where('account',$data['account'])->find();
|
||||
if($item){
|
||||
$this->returnCode('90000007');
|
||||
$this->returnCode(1, '该账号已存在');
|
||||
}
|
||||
$data['name'] = trim(input('post.name'));
|
||||
$data['phone'] = trim(input('post.phone'));
|
||||
@ -149,16 +160,16 @@ class Yunzeradmin extends Base{
|
||||
$data['status'] = (int)(input('post.status'));
|
||||
$password = trim(input('post.password'));
|
||||
if(empty($data['name'])){
|
||||
$this->returnCode('90000002');
|
||||
$this->returnCode(1, '姓名不能为空');
|
||||
}
|
||||
if(empty($data['phone'])){
|
||||
$this->returnCode('90000003');
|
||||
$this->returnCode(1, '手机号不能为空');
|
||||
}
|
||||
if(empty($data['group_id'])){
|
||||
$this->returnCode('90000004');
|
||||
$this->returnCode(1, '请选择角色');
|
||||
}
|
||||
if(empty($password)){
|
||||
$this->returnCode('90000005');
|
||||
$this->returnCode(1, '密码不能为空');
|
||||
}else{
|
||||
$data['password'] = md5($password);
|
||||
}
|
||||
@ -166,7 +177,7 @@ class Yunzeradmin extends Base{
|
||||
$data['update_time'] = time();
|
||||
$res = Db::table('yz_admin_user')->insert($data);
|
||||
if(!$res){
|
||||
$this->returnCode('91000001');
|
||||
$this->returnCode(1, '添加管理员失败');
|
||||
}
|
||||
$this->returnCode(0);
|
||||
}else{
|
||||
@ -181,7 +192,8 @@ class Yunzeradmin extends Base{
|
||||
return View::fetch();
|
||||
}
|
||||
}
|
||||
# 修改管理员
|
||||
|
||||
// 管理员编辑
|
||||
public function useredit(){
|
||||
if(Request::isPost()){
|
||||
$uid = (int)trim(input('post.uid'));
|
||||
@ -192,18 +204,18 @@ class Yunzeradmin extends Base{
|
||||
$data['sex'] = (int)(input('post.sex'));
|
||||
$data['status'] = (int)(input('post.status'));
|
||||
if(empty($data['name'])){
|
||||
$this->returnCode('90000002');
|
||||
$this->returnCode(1, '姓名不能为空');
|
||||
}
|
||||
if(empty($data['phone'])){
|
||||
$this->returnCode('90000003');
|
||||
$this->returnCode(1, '手机号不能为空');
|
||||
}
|
||||
if(empty($data['group_id'])){
|
||||
$this->returnCode('90000004');
|
||||
$this->returnCode(1, '请选择角色');
|
||||
}
|
||||
// 保存用户
|
||||
$res = Db::table('yz_admin_user')->where('uid',$uid)->update($data);
|
||||
if(!$res){
|
||||
$this->returnCode('91000002');
|
||||
$this->returnCode(1, '更新管理员信息失败');
|
||||
}
|
||||
$this->returnCode(0);
|
||||
}else{
|
||||
@ -223,16 +235,18 @@ class Yunzeradmin extends Base{
|
||||
return View::fetch();
|
||||
}
|
||||
}
|
||||
# 删除管理员
|
||||
|
||||
// 管理员删除
|
||||
public function userdel(){
|
||||
$uid = (int)input('post.uid');
|
||||
$res = Db::table('yz_admin_user')->where('uid',$uid)->delete();
|
||||
if(empty($res)){
|
||||
$this->returnCode('91000003');
|
||||
$this->returnCode(1, '删除管理员失败');
|
||||
}
|
||||
$this->returnCode(0);
|
||||
}
|
||||
# 管理员信息
|
||||
|
||||
// 管理员信息
|
||||
public function admininfo(){
|
||||
if(Request::isPost()){
|
||||
$find = Db::table('yz_admin_user')->where('uid',$this->adminId)->find();
|
||||
@ -244,19 +258,31 @@ class Yunzeradmin extends Base{
|
||||
$data['qq'] = (int)trim(input('post.qq'));
|
||||
$data['sex'] = (int)(input('post.sex'));
|
||||
if(empty($data['name'])){
|
||||
$this->returnCode('90000002');
|
||||
$this->returnCode(1, '姓名不能为空');
|
||||
}
|
||||
if(empty($data['phone'])){
|
||||
$this->returnCode('90000003');
|
||||
$this->returnCode(1, '手机号不能为空');
|
||||
}
|
||||
|
||||
// 处理密码修改
|
||||
$old_pw = trim(input('post.old_pw'));
|
||||
$new_pw = trim(input('post.new_pw'));
|
||||
if(!empty($old_pw) && !empty($new_pw)){
|
||||
if(md5($old_pw) != $find['password']){
|
||||
$this->returnCode(1, '原密码错误');
|
||||
}
|
||||
$data['password'] = md5($new_pw);
|
||||
}
|
||||
|
||||
// 保存用户
|
||||
$res = Db::table('yz_admin_user')->where('uid',$this->adminId)->update($data);
|
||||
if(!$res){
|
||||
$this->returnCode('91000002');
|
||||
$this->returnCode(1, '更新管理员信息失败');
|
||||
}
|
||||
$this->returnCode(0);
|
||||
}else{
|
||||
return View::fetch();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
79
app/admin/view/login/resetpwd.php
Normal file
79
app/admin/view/login/resetpwd.php
Normal file
@ -0,0 +1,79 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>重置密码</title>
|
||||
<meta name="renderer" content="yz">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css">
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/login.css">
|
||||
<script type="text/javascript" src="/static/layui/layui.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login">
|
||||
<div class="layadmin-user-login-main">
|
||||
<div class="layadmin-user-login-box layadmin-user-login-header">
|
||||
<h2>重置密码</h2>
|
||||
</div>
|
||||
<div class="layadmin-user-login-box layadmin-user-login-body layui-form">
|
||||
<div class="layui-form-item">
|
||||
<label class="layadmin-user-login-icon layui-icon layui-icon-username"
|
||||
for="LAY-user-login-username"></label>
|
||||
<input type="text" name="account" id="LAY-user-login-username" lay-verify="required"
|
||||
placeholder="用户名" class="layui-input">
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<button class="layui-btn layui-btn-fluid" lay-submit
|
||||
lay-filter="LAY-user-reset-submit">确认重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/layui/layui.js"></script>
|
||||
<script>
|
||||
layui.use(['form', 'layer'], function () {
|
||||
var $ = layui.$
|
||||
, form = layui.form
|
||||
, layer = layui.layer;
|
||||
|
||||
form.on('submit(LAY-user-reset-submit)', function (obj) {
|
||||
var field = obj.field;
|
||||
|
||||
//请求重置密码
|
||||
$.ajax({
|
||||
url: '/admin/login/resetpwd'
|
||||
, type: 'post'
|
||||
, data: {
|
||||
account: field.account
|
||||
}
|
||||
, success: function (res) {
|
||||
if (res.code === 0) {
|
||||
layer.msg('密码重置成功', {
|
||||
offset: '15px'
|
||||
, icon: 1
|
||||
, time: 1000
|
||||
}, function () {
|
||||
location.href = '/admin/login/index';
|
||||
});
|
||||
} else {
|
||||
layer.msg(res.msg, {
|
||||
offset: '15px'
|
||||
, icon: 2
|
||||
, time: 1000
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@ -1,4 +1,4 @@
|
||||
<?php /*a:3:{s:61:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\index\welcome.php";i:1745569331;s:61:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\header.php";i:1745564348;s:59:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\tail.php";i:1745482530;}*/ ?>
|
||||
<?php /*a:3:{s:61:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\index\welcome.php";i:1746709977;s:61:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\header.php";i:1746709977;s:59:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\tail.php";i:1746709977;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<?php /*a:1:{s:59:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\index\index.php";i:1746003853;}*/ ?>
|
||||
<?php /*a:1:{s:59:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\index\index.php";i:1746709977;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
|
||||
80
runtime/admin/temp/b2c576f05dfebea99c813402f4da2e92.php
Normal file
80
runtime/admin/temp/b2c576f05dfebea99c813402f4da2e92.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php /*a:1:{s:62:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\login\resetpwd.php";i:1746753630;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>重置密码</title>
|
||||
<meta name="renderer" content="yz">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css">
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/login.css">
|
||||
<script type="text/javascript" src="/static/layui/layui.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login">
|
||||
<div class="layadmin-user-login-main">
|
||||
<div class="layadmin-user-login-box layadmin-user-login-header">
|
||||
<h2>重置密码</h2>
|
||||
</div>
|
||||
<div class="layadmin-user-login-box layadmin-user-login-body layui-form">
|
||||
<div class="layui-form-item">
|
||||
<label class="layadmin-user-login-icon layui-icon layui-icon-username"
|
||||
for="LAY-user-login-username"></label>
|
||||
<input type="text" name="account" id="LAY-user-login-username" lay-verify="required"
|
||||
placeholder="用户名" class="layui-input">
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<button class="layui-btn layui-btn-fluid" lay-submit
|
||||
lay-filter="LAY-user-reset-submit">确认重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/layui/layui.js"></script>
|
||||
<script>
|
||||
layui.use(['form', 'layer'], function () {
|
||||
var $ = layui.$
|
||||
, form = layui.form
|
||||
, layer = layui.layer;
|
||||
|
||||
form.on('submit(LAY-user-reset-submit)', function (obj) {
|
||||
var field = obj.field;
|
||||
|
||||
//请求重置密码
|
||||
$.ajax({
|
||||
url: '/admin/login/resetpwd'
|
||||
, type: 'post'
|
||||
, data: {
|
||||
account: field.account
|
||||
}
|
||||
, success: function (res) {
|
||||
if (res.code === 0) {
|
||||
layer.msg('密码重置成功', {
|
||||
offset: '15px'
|
||||
, icon: 1
|
||||
, time: 1000
|
||||
}, function () {
|
||||
location.href = '/admin/login/index';
|
||||
});
|
||||
} else {
|
||||
layer.msg(res.msg, {
|
||||
offset: '15px'
|
||||
, icon: 2
|
||||
, time: 1000
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@ -1,4 +1,4 @@
|
||||
<?php /*a:3:{s:69:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\yunzeradmin\admininfo.php";i:1745568477;s:61:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\header.php";i:1745564348;s:59:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\tail.php";i:1745482530;}*/ ?>
|
||||
<?php /*a:3:{s:69:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\yunzeradmin\admininfo.php";i:1746709977;s:61:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\header.php";i:1746709977;s:59:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\tail.php";i:1746709977;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<?php /*a:1:{s:59:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\login\index.php";i:1745549657;}*/ ?>
|
||||
<?php /*a:1:{s:59:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\login\index.php";i:1746709977;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<?php /*a:4:{s:59:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\index\index.php";i:1746503955;s:64:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\header.php";i:1746516246;s:62:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\main.php";i:1746522874;s:64:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\footer.php";i:1746515097;}*/ ?>
|
||||
<?php /*a:4:{s:59:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\index\index.php";i:1746709977;s:64:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\header.php";i:1746709977;s:62:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\main.php";i:1746709977;s:64:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\footer.php";i:1746709977;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user