|
39 | 39 | */ |
40 | 40 | class AuthController extends Controller |
41 | 41 | { |
| 42 | + protected $maxLoginAttempts = 5; |
| 43 | + protected $lockoutTime = 60; |
| 44 | + |
| 45 | + use \Illuminate\Foundation\Auth\ThrottlesLogins; |
42 | 46 | /* to redirect after login */ |
43 | 47 |
|
44 | 48 | // if auth is agent |
@@ -70,6 +74,11 @@ public function __construct() |
70 | 74 | $this->middleware('guest', ['except' => ['getLogout', 'verifyOTP', 'redirectToProvider']]); |
71 | 75 | } |
72 | 76 |
|
| 77 | + public function loginUsername() |
| 78 | + { |
| 79 | + return 'email'; |
| 80 | + } |
| 81 | + |
73 | 82 | public function redirectToProvider($provider, $redirect = '') |
74 | 83 | { |
75 | 84 | if ($redirect !== '') { |
@@ -304,22 +313,20 @@ public function postLogin(LoginRequest $request) |
304 | 313 | try { |
305 | 314 | // dd($request->input()); |
306 | 315 | event('auth.login.event', []); //added 5/5/2016 |
307 | | - // Set login attempts and login time |
308 | | - $value = $_SERVER['REMOTE_ADDR']; |
309 | | - $usernameinput = $request->input('email'); |
310 | | - $password = $request->input('password'); |
311 | | - if ($request->input('referer')) { |
312 | | - $referer = 'form'; |
313 | | - } else { |
314 | | - $referer = '/'; |
| 316 | + |
| 317 | + $throttles = $this->isUsingThrottlesLoginsTrait(); |
| 318 | + |
| 319 | + if ($throttles && $this->hasTooManyLoginAttempts($request)) { |
| 320 | + return $this->sendLockoutResponse($request); |
| 321 | + } |
| 322 | + $credentials = $this->getCredentials($request); |
| 323 | + |
| 324 | + if (Auth::attempt($credentials, $request->has('remember'))) { |
| 325 | + return $this->handleUserWasAuthenticated($request, $throttles); |
315 | 326 | } |
316 | | - $field = filter_var($usernameinput, FILTER_VALIDATE_EMAIL) ? 'email' : 'user_name'; |
317 | | - $result = $this->confirmIPAddress($value, $usernameinput); |
318 | 327 |
|
319 | | - // If attempts > 3 and time < 30 minutes |
320 | | - $security = Security::whereId('1')->first(); |
321 | | - if ($result == 1) { |
322 | | - return redirect()->back()->withErrors('email', 'Incorrect details')->with(['error' => $security->lockout_message, 'referer' => $referer]); |
| 328 | + if ($throttles) { |
| 329 | + $this->incrementLoginAttempts($request); |
323 | 330 | } |
324 | 331 |
|
325 | 332 | $check_active = User::where('email', '=', $request->input('email'))->orwhere('user_name', '=', $request->input('email'))->first(); |
|
0 commit comments