mirror of
				https://gitee.com/zoujingli/ThinkAdmin.git
				synced 2025-11-04 21:52:10 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			110 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			110 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						||
 | 
						||
// +----------------------------------------------------------------------
 | 
						||
// | ThinkAdmin
 | 
						||
// +----------------------------------------------------------------------
 | 
						||
// | 版权所有 2014~2020 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 | 
						||
// +----------------------------------------------------------------------
 | 
						||
// | 官方网站: https://thinkadmin.top
 | 
						||
// +----------------------------------------------------------------------
 | 
						||
// | 开源协议 ( https://mit-license.org )
 | 
						||
// +----------------------------------------------------------------------
 | 
						||
// | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
 | 
						||
// | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
 | 
						||
// +----------------------------------------------------------------------
 | 
						||
 | 
						||
namespace app\admin\controller;
 | 
						||
 | 
						||
use think\admin\Controller;
 | 
						||
use think\admin\service\AdminService;
 | 
						||
use think\admin\service\MenuService;
 | 
						||
 | 
						||
/**
 | 
						||
 * 后台界面入口
 | 
						||
 * Class Index
 | 
						||
 * @package app\admin\controller
 | 
						||
 */
 | 
						||
class Index extends Controller
 | 
						||
{
 | 
						||
 | 
						||
    /**
 | 
						||
     * 显示后台首页
 | 
						||
     * @throws \ReflectionException
 | 
						||
     * @throws \think\db\exception\DataNotFoundException
 | 
						||
     * @throws \think\db\exception\DbException
 | 
						||
     * @throws \think\db\exception\ModelNotFoundException
 | 
						||
     */
 | 
						||
    public function index()
 | 
						||
    {
 | 
						||
        /*! 根据运行模式刷新权限 */
 | 
						||
        $clear = $this->app->isDebug();
 | 
						||
        AdminService::instance()->apply($clear);
 | 
						||
        /*! 读取当前权限菜单树 */
 | 
						||
        $this->menus = MenuService::instance()->getTree();
 | 
						||
        /*! 判断用户是否已经登录 */
 | 
						||
        $this->login = AdminService::instance()->isLogin();
 | 
						||
        /*! 菜单为空并且未登录跳转到登录页 */
 | 
						||
        if (empty($this->menus) && empty($this->login)) {
 | 
						||
            $this->redirect(sysuri('admin/login/index'));
 | 
						||
        } else {
 | 
						||
            $this->title = '系统管理后台';
 | 
						||
            $this->fetch();
 | 
						||
        }
 | 
						||
    }
 | 
						||
 | 
						||
    /**
 | 
						||
     * 修改用户资料
 | 
						||
     * @login true
 | 
						||
     * @param integer $id 会员ID
 | 
						||
     * @throws \think\db\exception\DataNotFoundException
 | 
						||
     * @throws \think\db\exception\DbException
 | 
						||
     * @throws \think\db\exception\ModelNotFoundException
 | 
						||
     */
 | 
						||
    public function info($id = 0)
 | 
						||
    {
 | 
						||
        $this->_applyFormToken();
 | 
						||
        if (AdminService::instance()->getUserId() === intval($id)) {
 | 
						||
            $this->_form('SystemUser', 'admin@user/form', 'id', [], ['id' => $id]);
 | 
						||
        } else {
 | 
						||
            $this->error('只能修改登录用户的资料!');
 | 
						||
        }
 | 
						||
    }
 | 
						||
 | 
						||
    /**
 | 
						||
     * 修改当前用户密码
 | 
						||
     * @login true
 | 
						||
     * @param integer $id
 | 
						||
     * @throws \think\db\exception\DataNotFoundException
 | 
						||
     * @throws \think\db\exception\DbException
 | 
						||
     * @throws \think\db\exception\ModelNotFoundException
 | 
						||
     */
 | 
						||
    public function pass($id = 0)
 | 
						||
    {
 | 
						||
        $this->_applyFormToken();
 | 
						||
        if (AdminService::instance()->getUserId() !== intval($id)) {
 | 
						||
            $this->error('只能修改当前用户的密码!');
 | 
						||
        }
 | 
						||
        if ($this->app->request->isGet()) {
 | 
						||
            $this->verify = true;
 | 
						||
            $this->_form('SystemUser', 'admin@user/pass', 'id', [], ['id' => $id]);
 | 
						||
        } else {
 | 
						||
            $data = $this->_vali([
 | 
						||
                'password.require'            => '登录密码不能为空!',
 | 
						||
                'repassword.require'          => '重复密码不能为空!',
 | 
						||
                'oldpassword.require'         => '旧的密码不能为空!',
 | 
						||
                'password.confirm:repassword' => '两次输入的密码不一致!',
 | 
						||
            ]);
 | 
						||
            $user = $this->app->db->name('SystemUser')->where(['id' => $id])->find();
 | 
						||
            if (md5($data['oldpassword']) !== $user['password']) {
 | 
						||
                $this->error('旧密码验证失败,请重新输入!');
 | 
						||
            }
 | 
						||
            if (data_save('SystemUser', ['id' => $user['id'], 'password' => md5($data['password'])])) {
 | 
						||
                $this->success('密码修改成功,下次请使用新密码登录!', '');
 | 
						||
            } else {
 | 
						||
                $this->error('密码修改失败,请稍候再试!');
 | 
						||
            }
 | 
						||
        }
 | 
						||
    }
 | 
						||
 | 
						||
}
 |