123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- <?php
- namespace App\Http\Controllers\Mobile\Auth;
- use Aix\Sms\Contracts\Smser;
- use App\Http\Controllers\Mobile\MobileBaseController;
- use App\Services\Auth\AuthService;
- use App\Services\Common\GeetestService;
- use App\Services\Common\SmsService;
- use App\Services\CommonService;
- use App\Validators\AuthValidatorRequest;
- use Closure;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Cache;
- class LoginController extends MobileBaseController
- {
- /**
- * @var AuthService
- */
- protected $authService;
- /**
- * @var SmsService
- */
- protected $smsService;
- /**
- * @var GeetestService
- */
- protected $geetestService;
- protected $sub_site = '';
- /**
- * LoginController constructor.
- * @param AuthService $authService
- * @param SmsService $smsService
- * @param GeetestService $geetestService
- */
- public function __construct(
- AuthService $authService,
- SmsService $smsService,
- GeetestService $geetestService
- )
- {
- $this->authService = $authService;
- $this->smsService = $smsService;
- $this->geetestService = $geetestService;
- /*$this->middleware(function ($request, Closure $next) {
- if (strpos($request->route()->getName(), 'mobile.logout') === false) {
- if (Auth::guard('web-member')->check() || Auth::guard('web-company')->check()) {
- return redirect(route('mobile.home'));
- }
- }
- return $next($request);
- });*/
- if (get_subsite_id() > 0) {
- $this->sub_site = 'jkq.';
- }
- }
- public function showLoginForm()
- {
- if (request()->has('redirect_url')) {
- session(['url.intended' => urldecode(request()->get('redirect_url'))]);
- }
- return view('mobile.app.auth.login', ['wap_title' => "个人登录"]);
- }
- public function showLoginMobileForm()
- {
- if (request()->has('redirect_url')) {
- session(['url.intended' => urldecode(request()->get('redirect_url'))]);
- }
- return view('mobile.app.auth.login_mobile', ['wap_title' => "个人登录"]);
- }
- public function showLoginCompanyForm()
- {
- if (request()->has('redirect_url')) {
- session(['url.intended' => urldecode(request()->get('redirect_url'))]);
- }
- return view('mobile.app.auth.login_company', ['wap_title' => "企业登录"]);
- }
- public function loginByAccount(AuthValidatorRequest $request)
- {
- // if (!$this->geetestService->checkGeetest(config('aix.system.site_safety.site_vo_code.members_login'))) {
- // return $this->sendErrorResponse("验证码不通过,请重新验证", ['is_need_geetest' => 1]);
- // }
- if (!$member = $this->authService->loginByAccount($request->account, $request->password, $request->autoLogin)) {
- $data['is_need_geetest'] = $this->geetestService->isNeedGeetest(
- config('aix.system.site_safety.site_vo_code.members_login')
- );
- $redis = Cache::getRedis();
- $value = $redis->get('user_' . $request->account);
- //dd($value);
- if (!$value) {
- $value = 0;
- }
- if ($value >= 5) {
- $redis->expire('user_' . $request->account, 900);
- return $this->sendErrorResponse("连续登录失败5次,请15分钟后再尝试!", $data);
- }
- $redis->set('user_' . $request->account, ++$value);
- return $this->sendErrorResponse("账号或密码错误或密码已超过90天未修改,请使用找回密码功能", $data);
- }
- if ($member->status == 0) {
- Auth::guard('web-member')->logout();
- return $this->sendErrorResponse("你的账号处于封禁状态, 请联系管理员");
- }
- $token = CommonService::createToken(1, $member->id);
- return $this->sendSuccessResponse([
- 'redirect_url' => url($request->session()
- ->pull('url.intended', route($this->sub_site . 'mobile.person.index'))),
- 'token' => $token,
- ]);
- }
- public function loginBySms(AuthValidatorRequest $request)
- {
- // if (!$this->geetestService->checkGeetest(config('aix.system.site_safety.site_vo_code.members_login'))) {
- // return $this->sendErrorResponse("验证码不通过,请重新验证", ['is_need_geetest' => 1]);
- // }
- if (!$this->smsService->checkAuthSms(
- $request->mobile,
- Smser::TEMPLATE_AUTH_LOGIN,
- $request->code
- )) {
- $data['is_need_geetest'] = $this->geetestService->isNeedGeetest(
- config('aix.system.site_safety.site_vo_code.members_login')
- );
- return $this->sendErrorResponse("短信验证码不对", $data);
- }
- if (!$member = $this->authService->loginByAccount($request->mobile, '', $request->autoLogin)) {
- $data['is_need_geetest'] = $this->geetestService->isNeedGeetest(
- config('aix.system.site_safety.site_vo_code.members_login')
- );
- return $this->sendErrorResponse("用户不存在,请先注册账号", $data);
- }
- if ($member->status == 0) {
- Auth::guard('web-member')->logout();
- return $this->sendErrorResponse("你的账号处于封禁状态, 请联系管理员");
- }
- $token = CommonService::createToken(1, $member->id);
- return $this->sendSuccessResponse([
- 'redirect_url' => url($request->session()
- ->pull('url.intended', route($this->sub_site . 'mobile.person.index'))),
- 'token' => $token,
- ]);
- }
- public function loginByCompany(AuthValidatorRequest $request)
- {
- // if (!$this->geetestService->checkGeetest(config('aix.system.site_safety.site_vo_code.members_login'))) {
- // return $this->sendErrorResponse("验证码不通过,请重新验证", ['is_need_geetest' => 1]);
- // }
- if (!$company = $this->authService->loginByCompany(
- $request->company_account,
- $request->company_password,
- $request->autoLogin
- )) {
- // $data['is_need_geetest'] = $this->geetestService->isNeedGeetest(
- // config('aix.system.site_safety.site_vo_code.members_login')
- // );
- $redis = Cache::getRedis();
- $value = $redis->get('user_' . $request->company_account);
- if (!$value) {
- $value = 0;
- }
- if ($value >= 5) {
- $redis->expire('user_' . $request->company_account, 900);
- return $this->sendErrorResponse("连续登录失败5次,请15分钟后再尝试!");
- }
- $redis->set('user_' . $request->company_account, ++$value);
- return $this->sendErrorResponse("账号或密码错误或密码已超过90天未修改,请使用找回密码功能");
- }
- if ($company->user_status == 0) {
- Auth::guard('web-company')->logout();
- return $this->sendErrorResponse("你的账号处于封禁状态, 请联系管理员");
- }
- $token = CommonService::createToken(2, $company->id);
- return $this->sendSuccessResponse([
- 'redirect_url' => url($request->session()->pull('url.intended', route($this->sub_site . 'mobile.firm.index'))),
- 'token' => $token,
- ]);
- }
- public function logout()
- {
- $this->authService->logout();
- return redirect(route($this->sub_site . 'mobile.home'));
- }
- public function loginMZT(){
- return view('mobile.app.auth.mzt', ['wap_title' => "闽政通快捷登录"]);
- }
- }
|