User.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 珣
  5. * Date: 2016/7/30
  6. * Time: 16:13
  7. */
  8. namespace app\edit\controller;
  9. use think\Controller;
  10. class User extends Controller{
  11. public function login(){
  12. if(request()->isPost()){
  13. $user_mobile=input('post.user_mobile');
  14. $user_password=input('post.user_password');
  15. $verify=input('post.verify');
  16. $remember=input('post.remember');
  17. $data=[
  18. 'user_mobile' => $user_mobile,
  19. 'user_password' => $user_password,
  20. 'verify' => $verify,
  21. ];
  22. $result=$this->validate($data,'AdminUser.login');
  23. // if($result!==true){
  24. // $this->error($result);
  25. // }else{
  26. $model=model('common/AdminUser');
  27. $uid=$model->login($user_mobile,$user_password,$type = 1,$remember);
  28. if (0 < $uid) { // UC登录成功
  29. /* 登录用户 */
  30. return $this->success('登陆成功!','Index/index');
  31. } else { // 登录失败
  32. switch ($uid) {
  33. case - 1 :
  34. $error = '用户不存在或被禁用!';
  35. break; // 系统级别禁用
  36. case - 2 :
  37. $error = '密码错误!';
  38. break;
  39. default :
  40. $error = '未知错误!';
  41. break; // 0-接口参数错误(调试阶段使用)
  42. }
  43. $this->error ( $error );
  44. }
  45. // }
  46. }else{
  47. return $this->fetch('login');
  48. }
  49. }
  50. public function logout(){
  51. $model=model('common/AdminUser');
  52. $model->logout();
  53. return $this->success('退出成功','index/index/index');
  54. }
  55. public function register(){
  56. if(request()->isAjax()){
  57. $data=input('param.');
  58. $result=$this->validate($data,'SayUser.add');
  59. if(true !== $result){
  60. // 验证失败 输出错误信息
  61. json_send([],$result,0);
  62. }
  63. verify(input('param.verify'),input('param.user_mobile'),1,60*5);
  64. $user_model=model('common/SayUser');
  65. $add_data=[
  66. 'user_name' => input('param.user_mobile'),
  67. 'user_mobile' =>input('param.user_mobile'),
  68. 'user_password' =>input('param.user_password'),
  69. ];
  70. if($user_model->data($add_data)->save()){
  71. clear_verify(input('param.user_mobile'),1);
  72. json_send();
  73. }else{
  74. json_send([],40023,0);
  75. }
  76. }else{
  77. return $this->fetch('register');
  78. }
  79. }
  80. public function forget_password(){
  81. if(request()->isAjax()){
  82. $data=input('param.');
  83. $result=$this->validate($data,'SayUser.add');
  84. if(true !== $result){
  85. // 验证失败 输出错误信息
  86. json_send([],$result,0);
  87. }
  88. verify(input('param.verify'),input('param.user_mobile'),2,60*5);
  89. $user_model=model('common/SayUser');
  90. $update_data=[
  91. 'user_password' =>input('param.user_password'),
  92. ];
  93. if($user_model->save($update_data,['user_mobile'=>input('param.user_mobile')])){
  94. clear_verify(input('param.user_mobile'),2);
  95. json_send();
  96. }else{
  97. json_send([],40023,0);
  98. }
  99. }else{
  100. return $this->fetch('forget_password');
  101. }
  102. }
  103. }