/** * Processes logging in a user. * * @param LoginRequest $request * * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse */ public function authenticate(LoginRequest $request) { try { $input = $request->all(); $remember = (bool) array_pull($input, 'remember', false); if ($auth = Sentinel::authenticate($input, $remember)) { $message = 'Successfully logged in.'; return redirect()->intended(route('maintenance.dashboard.index'))->withSuccess($message); } else { if (Corp::auth($input['login'], $input['password'])) { $user = Corp::user($input['login']); $name = explode(',', $user->name); $credentials = ['email' => $user->email, 'username' => $user->username, 'password' => $input['password'], 'first_name' => array_key_exists(1, $name) ? $name[1] : null, 'last_name' => array_key_exists(0, $name) ? $name[0] : null]; return $this->registerAndAuthenticateUser($credentials); } } $errors = 'Invalid login or password.'; } catch (NotActivatedException $e) { $errors = 'Account is not activated!'; } catch (ThrottlingException $e) { $delay = $e->getDelay(); $errors = "Your account is blocked for {$delay} second(s)."; } return redirect()->back()->withErrors($errors); }
/** * @param string $username * * @return mixed */ private function getUser($username) { return Corp::user($username); }