Csmadminpassword.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace app\admin\controller\csmadmin;
  3. use addons\csmadmin\library\CsmBackend;
  4. use addons\csmadmin\library\service\CsmAdminService;
  5. use app\admin\model\Admin;
  6. use fast\Random;
  7. use think\Session;
  8. use think\Validate;
  9. /**
  10. * Tables
  11. * http://127.0.0.1/fastadmin_plugin_csmmeet/public/q3HJDu2RgE.php/csmadmin/csmadminpassword/index
  12. * 密码变更相关
  13. */
  14. class Csmadminpassword extends CsmBackend
  15. {
  16. protected $noNeedRight = [
  17. 'modifypasswordafterlogin'
  18. ];
  19. /*
  20. * 登录后修改Miami
  21. * http://127.0.0.1/fastadmin_plugin_csmmeet/public/q3HJDu2RgE.php/csmadmin/csmadminpassword/modifypasswordafterlogin
  22. */
  23. public function modifypasswordafterlogin()
  24. {
  25. $tourl = $this->request->get('tourl', 'index/index');
  26. $admin = Admin::get($this->auth->id);
  27. if ($this->request->isPost()) {
  28. $oldpassword = $this->csmreq("oldpassword", true);
  29. $newpassword = $this->csmreq("newpassword", true);
  30. if ($admin->password != md5(md5($oldpassword) . $admin->salt)) {
  31. $this->error("当前登录密码错误,请重新输入!");
  32. } else {
  33. $params = [
  34. 'password' => $newpassword
  35. ];
  36. $params['salt'] = Random::alnum();
  37. $params['password'] = md5(md5($params['password']) . $params['salt']);
  38. $admin->save($params);
  39. $param = [
  40. 'faadmin_id' => $this->auth->id,
  41. 'updatepsdtime' => time()
  42. ];
  43. $service = new CsmAdminService();
  44. $service->insertOrUpdateByByAdminId($param, $this->auth->id);
  45. $this->success('', '', array(
  46. 'tourl' => $tourl
  47. ));
  48. }
  49. }
  50. // 获取最近一次密码修改时间
  51. $dao = new \app\admin\model\csmadmin\Admin();
  52. $row = $dao->where('status', '=', 'normal')
  53. ->where('faadmin_id', '=', $this->auth->id)
  54. ->find();
  55. // 是否第一次登录;如果否,计算上次密码修改时间
  56. $lastupdatpsdtime = $admin->createtime;
  57. $isfirst = '0';
  58. $lastupdatepsdd = 0;
  59. $lastlogintime = Session::get("csmadmin_lastlogintime");
  60. if ($lastlogintime == null) {
  61. $isfirst = '1';
  62. } else {
  63. // 如果没有密码修改时间,则以创建时间为准
  64. if ($row != null && ($row->updatepsdtime != null || $row->updatepsdtime != 0)) {
  65. $lastupdatpsdtime = $row->updatepsdtime;
  66. }
  67. // 如果0天算1天
  68. $lastupdatepsdd = (time() - $lastupdatpsdtime) / 7200;
  69. $lastupdatepsdd = (int) $lastupdatepsdd;
  70. $lastupdatepsdd = ($lastupdatepsdd == 0) ? 1 : $lastupdatepsdd;
  71. }
  72. $this->view->assign('title', "设置密码");
  73. $this->view->assign('tourl', $tourl);
  74. $this->view->assign('admin', $admin);
  75. $this->view->assign('csmadmin', $row ? $row : []);
  76. $this->view->assign('isfirst', $isfirst); // 是否首次登录:1、0
  77. $this->view->assign('lastupdatepsdd', $lastupdatepsdd); // 距离上次修改密码的时间(天)
  78. $this->view->assign('lastupdatpsdtime', $lastupdatpsdtime);//上级密码修改时间
  79. return $this->view->fetch();
  80. }
  81. }