Login.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\hander\HelpHander;
  4. use think\Controller;
  5. use think\Db;
  6. class Login extends Controller
  7. {
  8. public function check(){
  9. $account = input('account','','trim');
  10. $password = input('password','','trim');
  11. if(!$account){
  12. HelpHander::error('请输入账号');
  13. }
  14. if(!$password){
  15. HelpHander::error('请输入密码');
  16. }
  17. $ret = model('User')->login($account,$password);
  18. HelpHander::success($ret);
  19. }
  20. public function smsLogin(){
  21. $phone = input('accountName','','trim');
  22. $code = input('code','','trim');
  23. if(!check_mobile($phone)){
  24. HelpHander::error('手机号格式不正确');
  25. }
  26. $user = Db::name('user')->where('phone',$phone)->where('del',0)->find();
  27. if(!$user){
  28. HelpHander::error('该手机号未注册');
  29. }
  30. $res = model('SmsRecord')->checkCode($phone,$code);
  31. if(!$res){
  32. HelpHander::error('验证码不正确或已失效');
  33. }
  34. $token = model('Token')->updateToken($user['id']);
  35. if(!$token){
  36. HelpHander::error('登录失败');
  37. }
  38. $orgs = model('User')->getUserOrgs($user['id']);
  39. $data = ['org_info' => $orgs, 'token_info' => $token];
  40. HelpHander::success($data,'登录成功');
  41. }
  42. public function updatePwd(){
  43. $phone = input('mobile','','trim');
  44. $password = input('newPassword','','trim');
  45. $code = input('code','','trim');
  46. model('User')->forgetPassword($phone,$password,$code);
  47. HelpHander::success([],'修改成功');
  48. }
  49. }