/
ResetPasswordController.php
70 lines (58 loc) · 1.89 KB
/
ResetPasswordController.php
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
70
<?php
namespace Statamic\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Password;
use Statamic\Auth\Passwords\PasswordReset;
use Statamic\Auth\ResetsPasswords;
use Statamic\Contracts\Auth\User;
use Statamic\Http\Middleware\RedirectIfAuthenticated;
class ResetPasswordController extends Controller
{
use ResetsPasswords;
public function __construct()
{
$this->middleware(RedirectIfAuthenticated::class);
}
public function showResetForm(Request $request, $token = null)
{
return view('statamic::auth.passwords.reset')->with([
'token' => $token,
'email' => $request->email,
'action' => $this->resetFormAction(),
'title' => $this->resetFormTitle(),
]);
}
protected function resetFormAction()
{
return route('statamic.password.reset.action');
}
protected function resetFormTitle()
{
return __('Reset Password');
}
public function redirectPath()
{
return request('redirect') ?? route('statamic.site');
}
protected function setUserPassword($user, $password)
{
// The Statamic user class has a password method that will hash a given plain
// text password. If we're using the "statamic" user provider, we'll get a
// Statamic user. Otherwise (i.e. using the "eloquent" provider), we'd
// just a User model, which requires the password to be pre-hashed.
if ($user instanceof User) {
$user->password($password);
} else {
$user->password = Hash::make($password);
}
}
public function broker()
{
$broker = config('statamic.users.passwords.'.PasswordReset::BROKER_RESETS);
if (is_array($broker)) {
$broker = $broker['web'];
}
return Password::broker($broker);
}
}