LoginController.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\Http\Controllers\Controller;
  4. use App\Providers\RouteServiceProvider;
  5. use Illuminate\Foundation\Auth\AuthenticatesUsers;
  6. use Illuminate\Http\Request;
  7. class LoginController extends Controller
  8. {
  9. /*
  10. |--------------------------------------------------------------------------
  11. | Login Controller
  12. |--------------------------------------------------------------------------
  13. |
  14. | This controller handles authenticating users for the application and
  15. | redirecting them to your home screen. The controller uses a trait
  16. | to conveniently provide its functionality to your applications.
  17. |
  18. */
  19. use AuthenticatesUsers;
  20. /**
  21. * Where to redirect users after login.
  22. *
  23. * @var string
  24. */
  25. protected $redirectTo = RouteServiceProvider::HOME;
  26. /**
  27. * Create a new controller instance.
  28. *
  29. * @return void
  30. */
  31. public function __construct()
  32. {
  33. $this->middleware('guest')->except('logout');
  34. }
  35. public function login(Request $request)
  36. {
  37. $request->validate([
  38. $this->username() => 'required|string',
  39. 'password' => 'required|string',
  40. 'g-recaptcha-response' => ['required','recaptcha'],
  41. ]);
  42. // If the class is using the ThrottlesLogins trait, we can automatically throttle
  43. // the login attempts for this application. We'll key this by the username and
  44. // the IP address of the client making these requests into this application.
  45. if (method_exists($this, 'hasTooManyLoginAttempts') &&
  46. $this->hasTooManyLoginAttempts($request)) {
  47. $this->fireLockoutEvent($request);
  48. return $this->sendLockoutResponse($request);
  49. }
  50. if ($this->attemptLogin($request)) {
  51. return $this->sendLoginResponse($request);
  52. }
  53. // If the login attempt was unsuccessful we will increment the number of attempts
  54. // to login and redirect the user back to the login form. Of course, when this
  55. // user surpasses their maximum number of attempts they will get locked out.
  56. $this->incrementLoginAttempts($request);
  57. return $this->sendFailedLoginResponse($request);
  58. }
  59. }