Index.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\admin\controller;
  15. use think\admin\Controller;
  16. use think\admin\service\AuthService;
  17. use think\admin\service\MenuService;
  18. /**
  19. * 后台界面入口
  20. * Class Index
  21. * @package app\admin\controller
  22. */
  23. class Index extends Controller
  24. {
  25. /**
  26. * 显示后台首页
  27. * @throws \ReflectionException
  28. * @throws \think\db\exception\DataNotFoundException
  29. * @throws \think\db\exception\DbException
  30. * @throws \think\db\exception\ModelNotFoundException
  31. */
  32. public function index()
  33. {
  34. $this->title = '系统管理后台';
  35. $auth = AuthService::instance()->apply(true);
  36. $this->menus = MenuService::instance()->getTree();
  37. if (empty($this->menus) && !$auth->isLogin()) {
  38. $this->redirect(url('@admin/login'));
  39. } else {
  40. $this->fetch();
  41. }
  42. }
  43. /**
  44. * 后台环境信息
  45. */
  46. public function main()
  47. {
  48. $this->think_ver = $this->app->version();
  49. $this->mysql_ver = $this->app->db->query('select version() as ver')[0]['ver'];
  50. $this->fetch();
  51. }
  52. /**
  53. * 修改用户资料
  54. * @login true
  55. * @param integer $id 会员ID
  56. * @throws \think\db\exception\DataNotFoundException
  57. * @throws \think\db\exception\DbException
  58. * @throws \think\db\exception\ModelNotFoundException
  59. */
  60. public function info($id = 0)
  61. {
  62. $this->_applyFormToken();
  63. if (intval($this->app->session->get('user.id')) === intval($id)) {
  64. $this->_form('SystemUser', 'admin@user/form', 'id', [], ['id' => $id]);
  65. } else {
  66. $this->error('只能修改登录用户的资料!');
  67. }
  68. }
  69. /**
  70. * 修改当前用户密码
  71. * @login true
  72. * @param integer $id
  73. * @throws \think\db\exception\DataNotFoundException
  74. * @throws \think\db\exception\DbException
  75. * @throws \think\db\exception\ModelNotFoundException
  76. */
  77. public function pass($id = 0)
  78. {
  79. $this->_applyFormToken();
  80. if (intval($this->app->session->get('user.id')) !== intval($id)) {
  81. $this->error('只能修改当前用户的密码!');
  82. }
  83. if ($this->app->request->isGet()) {
  84. $this->verify = true;
  85. $this->_form('SystemUser', 'admin@user/pass', 'id', [], ['id' => $id]);
  86. } else {
  87. $data = [
  88. 'password' => $this->app->request->post('password'),
  89. 'repassword' => $this->app->request->post('repassword'),
  90. 'oldpassword' => $this->app->request->post('oldpassword'),
  91. ];
  92. if (empty($data['password'])) $this->error('登录密码不能为空!');
  93. if (empty($data['oldpassword'])) $this->error('旧密码不能为空!');
  94. if ($data['repassword'] !== $data['password']) {
  95. $this->error('重复密码与登录密码不匹配,请重新输入!');
  96. }
  97. $user = $this->app->db->name('SystemUser')->where(['id' => $id])->find();
  98. if (md5($data['oldpassword']) !== $user['password']) {
  99. $this->error('旧密码验证失败,请重新输入!');
  100. }
  101. if (data_save('SystemUser', ['id' => $user['id'], 'password' => md5($data['password'])])) {
  102. $this->success('密码修改成功,下次请使用新密码登录!', '');
  103. } else {
  104. $this->error('密码修改失败,请稍候再试!');
  105. }
  106. }
  107. }
  108. }