LoginController.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. $validationRules = [
  38. $this->username() => 'required|string',
  39. 'password' => 'required|string',
  40. ];
  41. if (config('SETTINGS::RECAPTCHA:ENABLED') == 'true') {
  42. $validationRules['g-recaptcha-response'] = ['required', 'recaptcha'];
  43. }
  44. $request->validate($validationRules);
  45. // If the class is using the ThrottlesLogins trait, we can automatically throttle
  46. // the login attempts for this application. We'll key this by the username and
  47. // the IP address of the client making these requests into this application.
  48. if (
  49. method_exists($this, 'hasTooManyLoginAttempts') &&
  50. $this->hasTooManyLoginAttempts($request)
  51. ) {
  52. $this->fireLockoutEvent($request);
  53. return $this->sendLockoutResponse($request);
  54. }
  55. if ($this->attemptLogin($request)) {
  56. return $this->sendLoginResponse($request);
  57. }
  58. // If the login attempt was unsuccessful we will increment the number of attempts
  59. // to login and redirect the user back to the login form. Of course, when this
  60. // user surpasses their maximum number of attempts they will get locked out.
  61. $this->incrementLoginAttempts($request);
  62. return $this->sendFailedLoginResponse($request);
  63. }
  64. }