123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- namespace app\admin\controller;
- use think\admin\Controller;
- use think\admin\service\AdminService;
- use think\admin\service\MenuService;
- class Index extends Controller
- {
-
- public function index()
- {
-
- AdminService::instance()->apply($this->app->isDebug());
-
- $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->isSuper = AdminService::instance()->isSuper();
- $this->fetch();
- }
- }
-
- 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('只能修改自己的资料!');
- }
- }
-
- protected function _info_form_result(bool $status)
- {
- if ($status) {
- $this->success('用户资料修改成功!', 'javascript:location.reload()');
- }
- }
-
- 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'])])) {
- sysoplog('系统用户管理', "修改用户[{$user['id']}]密码成功");
- $this->success('密码修改成功,下次请使用新密码登录!', '');
- } else {
- $this->error('密码修改失败,请稍候再试!');
- }
- }
- }
- }
|