-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathAuthController.php
More file actions
69 lines (56 loc) · 1.9 KB
/
AuthController.php
File metadata and controls
69 lines (56 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace App\Http\Controllers\Account;
use App\Http\Controllers\Controller;
use App\Http\Requests\LoginRequest;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
class AuthController extends Controller
{
public function login()
{
return view('account.auth.login');
}
public function logout()
{
auth()->logout();
session()->regenerateToken();
return redirect()->route('account.login');
}
/**
* Process the login request.
*
* @TODO Implement additional brute-force protection with custom blocked IPs model.
*
* @param LoginRequest $request
* @throws \Illuminate\Validation\ValidationException
* @return \Illuminate\Http\RedirectResponse
*/
public function processLogin(LoginRequest $request)
{
$credentials = $request->only('email', 'password');
$key = 'login-attempt:' . $request->ip();
$attemptsPerHour = 5;
if (\RateLimiter::tooManyAttempts($key, $attemptsPerHour)) {
$blockedUntil = Carbon::now()
->addSeconds(\RateLimiter::availableIn($key))
->diffInMinutes(Carbon::now());
return back()
->withInput($request->only(['email', 'remember']))
->withErrors([
'email' => 'Too many login attempts. Please try again in '
. $blockedUntil . ' minutes.',
]);
}
if (auth()->attempt($credentials, $request->boolean('remember'))) {
session()->regenerate();
\RateLimiter::clear($key);
return redirect()->intended('/account');
}
\RateLimiter::increment($key, 3600);
return back()
->withInput($request->only('email'))
->withErrors([
'email' => 'The provided credentials do not match our records.',
]);
}
}