Updatepwd.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. // $this->success('密码修改成功');
  41. // }else{
  42. // $this->success('密码修改失败');
  43. // }
  44. return $this->redirect('User/Accountsafe/index');
  45. }else{
  46. $user_info = $this->getAdminInfo();
  47. $user = db('user')->where('user_id',$user_info['user_id'])->find();
  48. return $this->fetch();
  49. }
  50. }
  51. /**
  52. * 修改用户名
  53. * @return mixed
  54. */
  55. public function username()
  56. {
  57. $user_info = $this->getAdminInfo();
  58. $user = db('user')->where('user_id',$user_info['user_id'])->find();
  59. if (request()->isPost()) {
  60. $new_user_email = input('post.new_user_email');
  61. $confirm_user_email = input('post.confirm_user_email');
  62. // 新用户名 验证
  63. if($new_user_email != $confirm_user_email){
  64. //验证失败
  65. $this->error('新用户名不一致');
  66. }
  67. $useremail = db('user')->where('user_email',$new_user_email)->find();
  68. if(!empty($useremail)){
  69. //验证失败
  70. $this->error('用户名已存在');
  71. }
  72. $update_info = array(
  73. 'user_email' => $new_user_email
  74. );
  75. $res = db('user')->where('user_id', $user_info['user_id'])->update($update_info);
  76. // if($res == 1){
  77. // $this->success('用户名修改成功');
  78. // }else{
  79. // $this->success('用户名修改失败');
  80. // }
  81. return $this->redirect('User/Accountsafe/index');
  82. }else{
  83. $user_info = $this->getAdminInfo();
  84. $user = db('user')->where('user_id',$user_info['user_id'])->find();
  85. $this->assign('user', $user);
  86. return $this->fetch();
  87. }
  88. }
  89. /**
  90. * 修改电话
  91. * @return mixed
  92. */
  93. public function phone()
  94. {
  95. $user_info = $this->getAdminInfo();
  96. $user = db('user')->where('user_id',$user_info['user_id'])->find();
  97. if (request()->isPost()) {
  98. $new_phone = input('post.new_phone');
  99. $confirm_phone = input('post.confirm_phone');
  100. // 新电话号码 验证
  101. if($new_phone != $confirm_phone){
  102. //验证失败
  103. $this->error('新电话号码不一致');
  104. }
  105. $update_info = array(
  106. 'user_phone' => $new_phone
  107. );
  108. $res = db('user')->where('user_id', $user_info['user_id'])->update($update_info);
  109. // if($res == 1){
  110. // $this->success('电话号码修改成功');
  111. // }else{
  112. // $this->success('电话号码修改失败');
  113. // }
  114. return $this->redirect('User/Accountsafe/index');
  115. }else{
  116. $user_info = $this->getAdminInfo();
  117. $user = db('user')->where('user_id',$user_info['user_id'])->find();
  118. $this->assign('user', $user);
  119. return $this->fetch();
  120. }
  121. }
  122. }
  123. ?>