userpwd.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace WY\app\controller\member;
  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. $where = array('fields' => 'id=?', 'values' => array($_SESSION['login_userid']));
  14. $users = $this->model()->select()->from('users')->where($where)->fetchRow();
  15. $where = array('fields' => 'userid=?', 'values' => array($_SESSION['login_userid']));
  16. $userinfo = $this->model()->select()->from('userinfo')->where($where)->fetchRow();
  17. }
  18. public function editsave()
  19. {
  20. $oldpwd = $this->req->post('oldpwd');
  21. $newpwd = $this->req->post('newpwd');
  22. $cirpwd = $this->req->post('cirpwd');
  23. if ($oldpwd == '' || $newpwd == '' || $cirpwd == '') {
  24. echo json_encode(array('status' => 0, 'msg' => '选项填写不完整'));
  25. exit;
  26. }
  27. if (strlen($newpwd) < 6 || strlen($newpwd) > 20) {
  28. echo json_encode(array('status' => 0, 'msg' => '新密码格式长度在6至20位之间'));
  29. exit;
  30. }
  31. if ($newpwd != $cirpwd) {
  32. echo json_encode(array('status' => 0, 'msg' => '两次填写的密码不匹配'));
  33. exit;
  34. }
  35. if (sha1($oldpwd) != $this->userData['userpass']) {
  36. echo json_encode(array('status' => 0, 'msg' => '原密码填写错误'));
  37. exit;
  38. }
  39. $data = array('userpass' => sha1($newpwd));
  40. if ($this->model()->from('users')->updateSet($data)->where(array('fields' => 'id=?', 'values' => array($_SESSION['login_userid'])))->update()) {
  41. echo json_encode(array('status' => 1, 'msg' => '密码修改成功,请重新登录', 'url' => '/login/logout'));
  42. exit;
  43. }
  44. echo json_encode(array('status' => 0, 'msg' => '保存失败'));
  45. exit;
  46. }
  47. }