新增修改密码功能和重置密码功能
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user