AuthController.php 1020 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace business\controllers;
  3. use biz\admin\services\AdminService;
  4. use common\components\httpUtil;
  5. use common\components\jwt;
  6. use common\components\util;
  7. use Yii;
  8. use yii\web\Controller;
  9. use common\components\stringUtil;
  10. /**
  11. * 用户登陆
  12. */
  13. class AuthController extends PublicController
  14. {
  15. //登陆并拿到token shish 2019.11.23
  16. public function actionLogin()
  17. {
  18. $get = Yii::$app->request->get();
  19. $mobile = isset($get['mobile']) ? $get['mobile'] : 0;
  20. if (stringUtil::isMobieNumber($mobile) == false) {
  21. util::fail('请填写正常的手机号');
  22. }
  23. $password = isset($get['password']) && !empty($get['password']) ? $get['password'] : '';
  24. if (empty($password)) {
  25. util::fail('请输入密码');
  26. }
  27. $admin = AdminService::getByCondition(['mobile' => $mobile]);
  28. if(password_verify($password , $admin['password']) == false){
  29. util::fail('密码错误');
  30. }
  31. $adminId = $admin['id'];
  32. //获取token
  33. $token = jwt::getNewToken($adminId);
  34. util::success(['token' => $token]);
  35. }
  36. }