Index.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // | 免费声明 ( https://thinkadmin.top/disclaimer )
  11. // +----------------------------------------------------------------------
  12. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  13. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  14. // +----------------------------------------------------------------------
  15. namespace app\admin\controller;
  16. use think\admin\Controller;
  17. use think\admin\model\SystemUser;
  18. use think\admin\service\AdminService;
  19. use think\admin\service\MenuService;
  20. /**
  21. * 后台界面入口
  22. * Class Index
  23. * @package app\admin\controller
  24. */
  25. class Index extends Controller
  26. {
  27. /**
  28. * 显示后台首页
  29. * @throws \ReflectionException
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\DbException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. */
  34. public function index()
  35. {
  36. /*! 根据运行模式刷新权限 */
  37. AdminService::instance()->apply($this->app->isDebug());
  38. /*! 读取当前用户权限菜单树 */
  39. $this->menus = MenuService::instance()->getTree();
  40. /*! 判断当前用户的登录状态 */
  41. $this->login = AdminService::instance()->isLogin();
  42. /*! 菜单为空且未登录跳转到登录页 */
  43. if (empty($this->menus) && empty($this->login)) {
  44. $this->redirect(sysuri('admin/login/index'));
  45. } else {
  46. $this->title = '系统管理后台';
  47. $this->isSuper = AdminService::instance()->isSuper();
  48. $this->fetch();
  49. }
  50. }
  51. /**
  52. * 修改用户资料
  53. * @login true
  54. * @param mixed $id 用户ID
  55. * @throws \think\db\exception\DataNotFoundException
  56. * @throws \think\db\exception\DbException
  57. * @throws \think\db\exception\ModelNotFoundException
  58. */
  59. public function info($id = 0)
  60. {
  61. $this->_applyFormToken();
  62. if (AdminService::instance()->getUserId() === intval($id)) {
  63. $this->_form('SystemUser', 'admin@user/form', 'id', [], ['id' => $id]);
  64. } else {
  65. $this->error('只能修改自己的资料!');
  66. }
  67. }
  68. /**
  69. * 资料修改后处理
  70. * @param bool $status
  71. */
  72. protected function _info_form_result(bool $status)
  73. {
  74. if ($status) {
  75. $this->success('用户资料修改成功!', 'javascript:location.reload()');
  76. }
  77. }
  78. /**
  79. * 修改当前用户密码
  80. * @login true
  81. * @param mixed $id
  82. * @throws \think\db\exception\DataNotFoundException
  83. * @throws \think\db\exception\DbException
  84. * @throws \think\db\exception\ModelNotFoundException
  85. */
  86. public function pass($id = 0)
  87. {
  88. $this->_applyFormToken();
  89. if (AdminService::instance()->getUserId() !== intval($id)) {
  90. $this->error('只能修改当前用户的密码!');
  91. }
  92. if ($this->app->request->isGet()) {
  93. $this->verify = true;
  94. $this->_form('SystemUser', 'admin@user/pass', 'id', [], ['id' => $id]);
  95. } else {
  96. $data = $this->_vali([
  97. 'password.require' => '登录密码不能为空!',
  98. 'repassword.require' => '重复密码不能为空!',
  99. 'oldpassword.require' => '旧的密码不能为空!',
  100. 'password.confirm:repassword' => '两次输入的密码不一致!',
  101. ]);
  102. $user = SystemUser::mk()->find($id);
  103. if (empty($user)) $this->error('用户不存在!');
  104. if (md5($data['oldpassword']) !== $user['password']) {
  105. $this->error('旧密码验证失败,请重新输入!');
  106. }
  107. if ($user->save(['password' => md5($data['password'])])) {
  108. sysoplog('系统用户管理', "修改用户[{$user['id']}]密码成功");
  109. $this->success('密码修改成功,下次请使用新密码登录!', '');
  110. } else {
  111. $this->error('密码修改失败,请稍候再试!');
  112. }
  113. }
  114. }
  115. }