Updatepwd.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\user\controller;
  3. use think\Controller;
  4. use think\Lang;
  5. use think\Validate;
  6. class Updatepwd extends UserControl
  7. {
  8. public function _initialize()
  9. {
  10. parent::_initialize();
  11. Lang::load(APP_PATH . 'admin/lang/' . config('default_lang') . '/login.lang.php');
  12. }
  13. /**
  14. * 修改密码
  15. * @return mixed
  16. */
  17. public function index()
  18. {
  19. $user_info = $this->getAdminInfo();
  20. $user = db('user')->where('user_id',$user_info['user_id'])->find();
  21. if (request()->isPost()) {
  22. $password = input('post.password');
  23. $new_password = input('post.new_password');
  24. $confirm_password = input('post.confirm_password');
  25. // 原密码 验证
  26. if(md5($password) != $user['user_password']){
  27. //验证失败
  28. $this->error('原密码输入不正确');
  29. }
  30. // 新密码 验证
  31. if($new_password != $confirm_password){
  32. //验证失败
  33. $this->error('新密码不一致');
  34. }
  35. $update_info = array(
  36. 'user_password' => md5($new_password)
  37. );
  38. $res = db('user')->where('user_id', $user_info['user_id'])->update($update_info);
  39. if($res == 1){
  40. return $this->redirect('User/Member/index');
  41. }
  42. }else{
  43. $user_info = $this->getAdminInfo();
  44. $user = db('user')->where('user_id',$user_info['user_id'])->find();
  45. return $this->fetch();
  46. }
  47. }
  48. /**
  49. * 修改用户名
  50. * @return mixed
  51. */
  52. public function username()
  53. {
  54. return $this->fetch();
  55. }
  56. /**
  57. * 修改电话
  58. * @return mixed
  59. */
  60. public function phone()
  61. {
  62. $user_info = $this->getAdminInfo();
  63. $user = db('user')->where('user_id',$user_info['user_id'])->find();
  64. $this->assign('user', $user);
  65. return $this->fetch();
  66. }
  67. }
  68. ?>