Index.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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\extend\DataExtend;
  17. use think\admin\service\AuthService;
  18. use think\admin\service\MenuService;
  19. /**
  20. * 后台界面入口
  21. * Class Index
  22. * @package app\admin\controller
  23. */
  24. class Index extends Controller
  25. {
  26. /**
  27. * 显示后台首页
  28. * @throws \ReflectionException
  29. * @throws \think\db\exception\DataNotFoundException
  30. * @throws \think\db\exception\DbException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. */
  33. public function index()
  34. {
  35. $this->title = '系统管理后台';
  36. AuthService::instance($this->app)->apply(true);
  37. $this->menus = MenuService::instance($this->app)->getTree();
  38. if (empty($this->menus) && !AuthService::instance($this->app)->isLogin()) {
  39. $this->redirect(url('@admin/login'));
  40. } else {
  41. $this->fetch();
  42. }
  43. }
  44. /**
  45. * 后台环境信息
  46. */
  47. public function main()
  48. {
  49. $this->think_ver = $this->app->version();
  50. $this->mysql_ver = $this->app->db->query('select version() as ver')[0]['ver'];
  51. $this->fetch();
  52. }
  53. /**
  54. * 修改用户资料
  55. * @login true
  56. * @param integer $id 会员ID
  57. * @throws \think\db\exception\DataNotFoundException
  58. * @throws \think\db\exception\DbException
  59. * @throws \think\db\exception\ModelNotFoundException
  60. */
  61. public function info($id = 0)
  62. {
  63. $this->_applyFormToken();
  64. if (intval($this->app->session->get('user.id')) === intval($id)) {
  65. $this->_form('SystemUser', 'admin@user/form', 'id', [], ['id' => $id]);
  66. } else {
  67. $this->error('只能修改登录用户的资料!');
  68. }
  69. }
  70. /**
  71. * 修改当前用户密码
  72. * @login true
  73. * @param integer $id
  74. * @throws \think\db\exception\DataNotFoundException
  75. * @throws \think\db\exception\DbException
  76. * @throws \think\db\exception\ModelNotFoundException
  77. */
  78. public function pass($id = 0)
  79. {
  80. $this->_applyFormToken();
  81. if (intval($this->app->session->get('user.id')) !== intval($id)) {
  82. $this->error('只能修改当前用户的密码!');
  83. }
  84. if ($this->app->request->isGet()) {
  85. $this->verify = true;
  86. $this->_form('SystemUser', 'admin@user/pass', 'id', [], ['id' => $id]);
  87. } else {
  88. $data = [
  89. 'password' => $this->app->request->post('password'),
  90. 'repassword' => $this->app->request->post('repassword'),
  91. 'oldpassword' => $this->app->request->post('oldpassword'),
  92. ];
  93. if (empty($data['password'])) $this->error('登录密码不能为空!');
  94. if (empty($data['oldpassword'])) $this->error('旧密码不能为空!');
  95. if ($data['repassword'] !== $data['password']) {
  96. $this->error('重复密码与登录密码不匹配,请重新输入!');
  97. }
  98. $user = $this->app->db->name('SystemUser')->where(['id' => $id])->find();
  99. if (md5($data['oldpassword']) !== $user['password']) {
  100. $this->error('旧密码验证失败,请重新输入!');
  101. }
  102. if (DataExtend::save('SystemUser', ['id' => $user['id'], 'password' => md5($data['password'])])) {
  103. $this->success('密码修改成功,下次请使用新密码登录!', '');
  104. } else {
  105. $this->error('密码修改失败,请稍候再试!');
  106. }
  107. }
  108. }
  109. }