LoginController.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\User;
  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 string $redirectTo = '/order';
  26. /**
  27. * Create a new controller instance.
  28. *
  29. * @return void
  30. */
  31. public function __construct()
  32. {
  33. $this->middleware('guest')->except('logout');
  34. $this->middleware('auth')->only('logout');
  35. }
  36. public function login(Request $request)
  37. {
  38. $this->validateLogin($request);
  39. // If the class is using the ThrottlesLogins trait, we can automatically throttle
  40. // the login attempts for this application. We'll key this by the username and
  41. // the IP address of the client making these requests into this application.
  42. if (method_exists($this, 'hasTooManyLoginAttempts') &&
  43. $this->hasTooManyLoginAttempts($request)) {
  44. $this->fireLockoutEvent($request);
  45. return $this->sendLockoutResponse($request);
  46. }
  47. if ($this->attemptLogin($request)) {
  48. if ($request->hasSession()) {
  49. $request->session()->put('auth.password_confirmed_at', time());
  50. }
  51. if($request->session()->has('token_fcm')) {
  52. User::query()
  53. ->where('email', $request->email)
  54. ->update(['token_fcm' => $request->session()->get('token_fcm')]);
  55. }
  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. }