userpwd.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace WY\app\controller\agent;
  3. use WY\app\libs\Controller;
  4. if (!defined('WY_ROOT')) {
  5. exit;
  6. }
  7. class userpwd extends CheckUser
  8. {
  9. public function index()
  10. {
  11. $data = array('title' => '修改密码');
  12. $this->put('userpwd.php', $data);
  13. }
  14. public function editsave()
  15. {
  16. $oldpwd = $this->req->post('oldpwd');
  17. $newpwd = $this->req->post('newpwd');
  18. $cirpwd = $this->req->post('cirpwd');
  19. if ($oldpwd == '' || $newpwd == '' || $cirpwd == '') {
  20. echo json_encode(array('status' => 0, 'msg' => '选项填写不完整'));
  21. exit;
  22. }
  23. if (strlen($newpwd) < 6 || strlen($newpwd) > 20) {
  24. echo json_encode(array('status' => 0, 'msg' => '新密码格式长度在6至20位之间'));
  25. exit;
  26. }
  27. if ($newpwd != $cirpwd) {
  28. echo json_encode(array('status' => 0, 'msg' => '两次填写的密码不匹配'));
  29. exit;
  30. }
  31. if (sha1($oldpwd) != $this->userData['userpass']) {
  32. echo json_encode(array('status' => 0, 'msg' => '原密码填写错误'));
  33. exit;
  34. }
  35. $data = array('userpass' => sha1($newpwd));
  36. if ($this->model()->from('users')->updateSet($data)->where(array('fields' => 'id=?', 'values' => array($_SESSION['login_agentid'])))->update()) {
  37. echo json_encode(array('status' => 1, 'msg' => '密码修改成功,请重新登录', 'url' => '/login/logout'));
  38. exit;
  39. }
  40. echo json_encode(array('status' => 0, 'msg' => '保存失败'));
  41. exit;
  42. }
  43. }