LoginController.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  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. use AuthenticatesUsers;
  9. /**
  10. * Where to redirect users after login.
  11. *
  12. * @var string
  13. */
  14. protected $redirectTo = '/admin';
  15. /**
  16. * Shows the admin login form
  17. *
  18. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  19. */
  20. public function showLoginForm()
  21. {
  22. if (auth()->guard('employee')->check()) {
  23. return redirect()->route('admin.dashboard');
  24. }
  25. return view('auth.admin.login');
  26. }
  27. /**
  28. * Login the employee
  29. *
  30. * @param LoginRequest $request
  31. *
  32. * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
  33. * @throws \Illuminate\Validation\ValidationException
  34. */
  35. public function login(LoginRequest $request)
  36. {
  37. $this->validateLogin($request);
  38. // If the class is using the ThrottlesLogins trait, we can automatically throttle
  39. // the login attempts for this application. We'll key this by the username and
  40. // the IP address of the client making these requests into this application.
  41. if ($this->hasTooManyLoginAttempts($request)) {
  42. $this->fireLockoutEvent($request);
  43. return $this->sendLockoutResponse($request);
  44. }
  45. $details = $request->only('email', 'password');
  46. $details['status'] = 1;
  47. if (auth()->guard('employee')->attempt($details)) {
  48. return $this->sendLoginResponse($request);
  49. }
  50. // If the login attempt was unsuccessful we will increment the number of attempts
  51. // to login and redirect the user back to the login form. Of course, when this
  52. // user surpasses their maximum number of attempts they will get locked out.
  53. $this->incrementLoginAttempts($request);
  54. return $this->sendFailedLoginResponse($request);
  55. }
  56. }