LoginController.php 2.3 KB

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