+ * Get the needed authorization credentials from the request.
+ */
+ protected function credentials(Request $request)
+ {
+ return $request->only('username', 'email', 'password');
+ }
+
+ /**
+ * Show the application login form.
+ */
+ public function getLogin(Request $request)
+ {
+ $socialDrivers = $this->socialAuthService->getActiveDrivers();
+ $authMethod = config('auth.method');
+ $preventInitiation = $request->get('prevent_auto_init') === 'true';
+
+ if ($request->has('email')) {
+ session()->flashInput([
+ 'email' => $request->get('email'),
+ 'password' => (config('app.env') === 'demo') ? $request->get('password', '') : '',
+ ]);
+ }
+
+ // Store the previous location for redirect after login
+ $this->updateIntendedFromPrevious();
+
+ if (!$preventInitiation && $this->shouldAutoInitiate()) {
+ return view('auth.login-initiate', [
+ 'authMethod' => $authMethod,
+ ]);
+ }
+
+ return view('auth.login', [
+ 'socialDrivers' => $socialDrivers,
+ 'authMethod' => $authMethod,
+ ]);
+ }
+
+ /**
+ * Handle a login request to the application.
+ *
+ * @param \Illuminate\Http\Request $request
+ *
+ * @throws \Illuminate\Validation\ValidationException
+ *
+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Http\JsonResponse
+ */
+ public function login(Request $request)
+ {
+ $this->validateLogin($request);
+ $username = $request->get($this->username());
+
+ // If the class is using the ThrottlesLogins trait, we can automatically throttle
+ // the login attempts for this application. We'll key this by the username and
+ // the IP address of the client making these requests into this application.
+ if (method_exists($this, 'hasTooManyLoginAttempts') &&
+ $this->hasTooManyLoginAttempts($request)) {
+ $this->fireLockoutEvent($request);
+
+ Activity::logFailedLogin($username);
+
+ return $this->sendLockoutResponse($request);
+ }
+
+ try {
+ if ($this->attemptLogin($request)) {
+ return $this->sendLoginResponse($request);
+ }
+ } catch (LoginAttemptException $exception) {
+ Activity::logFailedLogin($username);
+
+ return $this->sendLoginAttemptExceptionResponse($exception, $request);
+ }
+
+ // If the login attempt was unsuccessful we will increment the number of attempts
+ // to login and redirect the user back to the login form. Of course, when this
+ // user surpasses their maximum number of attempts they will get locked out.
+ $this->incrementLoginAttempts($request);
+
+ Activity::logFailedLogin($username);
+
+ return $this->sendFailedLoginResponse($request);
+ }
+
+ /**
+ * Attempt to log the user into the application.
+ *
+ * @param \Illuminate\Http\Request $request
+ *
+ * @return bool
+ */
+ protected function attemptLogin(Request $request)
+ {
+ return $this->loginService->attempt(
+ $this->credentials($request),
+ auth()->getDefaultDriver(),
+ $request->filled('remember')
+ );
+ }
+
+ /**
+ * The user has been authenticated.
+ *
+ * @param \Illuminate\Http\Request $request
+ * @param mixed $user
+ *
+ * @return mixed