AuthController.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace admin\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. httpUtil::getSourceId();die;
  19. $get = Yii::$app->request->get();
  20. $mobile = isset($get['mobile']) ? $get['mobile'] : 0;
  21. if (stringUtil::isMobieNumber($mobile) == false) {
  22. util::fail('请填写正常的手机号');
  23. }
  24. $password = isset($get['password']) && !empty($get['password']) ? $get['password'] : '';
  25. if (empty($password)) {
  26. util::fail('请输入密码');
  27. }
  28. $admin = AdminService::getByCondition(['mobile' => $mobile]);
  29. if ($admin['password'] != md5($password)) {
  30. util::fail('密码错误');
  31. }
  32. $adminId = $admin['id'];
  33. //获取token
  34. $token = jwt::getNewToken($adminId);
  35. util::success(['token' => $token]);
  36. }
  37. }