|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\app\Http\Controllers\Auth; |
|
4
|
|
|
|
|
5
|
|
|
use Backpack\CRUD\app\Library\Auth\ResetsPasswords; |
|
6
|
|
|
use Illuminate\Http\Request; |
|
7
|
|
|
use Illuminate\Routing\Controller; |
|
8
|
|
|
use Illuminate\Support\Facades\Password; |
|
9
|
|
|
|
|
10
|
|
|
class ResetPasswordController extends Controller |
|
11
|
|
|
{ |
|
12
|
|
|
protected $data = []; // the information we send to the view |
|
13
|
|
|
|
|
14
|
|
|
/* |
|
15
|
|
|
|-------------------------------------------------------------------------- |
|
16
|
|
|
| Password Reset Controller |
|
17
|
|
|
|-------------------------------------------------------------------------- |
|
18
|
|
|
| |
|
19
|
|
|
| This controller is responsible for handling password reset requests |
|
20
|
|
|
| and uses a simple trait to include this behavior. You're free to |
|
21
|
|
|
| explore this trait and override any methods you wish to tweak. |
|
22
|
|
|
| |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
use ResetsPasswords; |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Get the path the user should be redirected to after password reset. |
|
29
|
|
|
* |
|
30
|
|
|
* @param \Illuminate\Http\Request $request |
|
31
|
|
|
* @return string |
|
32
|
|
|
*/ |
|
33
|
|
|
public function redirectTo() |
|
34
|
|
|
{ |
|
35
|
|
|
return backpack_url(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Create a new controller instance. |
|
40
|
|
|
* |
|
41
|
|
|
* @return void |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct() |
|
44
|
|
|
{ |
|
45
|
|
|
$guard = backpack_guard_name(); |
|
46
|
|
|
|
|
47
|
|
|
$this->middleware("guest:$guard"); |
|
48
|
|
|
|
|
49
|
|
|
if (! backpack_users_have_email()) { |
|
50
|
|
|
abort(501, trans('backpack::base.no_email_column')); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
// where to redirect after password was reset |
|
54
|
|
|
$this->redirectTo = property_exists($this, 'redirectTo') ? $this->redirectTo : backpack_url('dashboard'); |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
// ------------------------------------------------------- |
|
58
|
|
|
// Laravel overwrites for loading backpack views |
|
59
|
|
|
// ------------------------------------------------------- |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Display the password reset view for the given token. |
|
63
|
|
|
* |
|
64
|
|
|
* If no token is present, display the link request form. |
|
65
|
|
|
* |
|
66
|
|
|
* @param \Illuminate\Http\Request $request |
|
67
|
|
|
* @param string|null $token |
|
68
|
|
|
* @return \Illuminate\Http\Response |
|
69
|
|
|
*/ |
|
70
|
|
|
public function showResetForm(Request $request, $token = null) |
|
71
|
|
|
{ |
|
72
|
|
|
$this->data['title'] = trans('backpack::base.reset_password'); // set the page title |
|
73
|
|
|
|
|
74
|
|
|
return view(backpack_view('auth.passwords.reset'), $this->data)->with( |
|
|
|
|
|
|
75
|
|
|
['token' => $token, 'email' => $request->email] |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Reset the given user's password. |
|
81
|
|
|
* |
|
82
|
|
|
* @param \Illuminate\Http\Request $request |
|
83
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse |
|
84
|
|
|
*/ |
|
85
|
|
|
public function reset(Request $request) |
|
86
|
|
|
{ |
|
87
|
|
|
$request->validate($this->rules(), $this->validationErrorMessages()); |
|
88
|
|
|
|
|
89
|
|
|
// Here we will attempt to reset the user's password. If it is successful we |
|
90
|
|
|
// will update the password on an actual user model and persist it to the |
|
91
|
|
|
// database. Otherwise we will parse the error and return the response. |
|
92
|
|
|
$response = $this->broker()->reset( |
|
93
|
|
|
$this->credentials($request), function ($user, $password) { |
|
94
|
|
|
$this->resetPassword($user, $password); |
|
95
|
|
|
} |
|
96
|
|
|
); |
|
97
|
|
|
|
|
98
|
|
|
// We should attempt to log out all other devices, which will change the |
|
99
|
|
|
// password_hash for this user, in case Backpack's AuthenticateSession |
|
100
|
|
|
// middleware is being used. |
|
101
|
|
|
backpack_auth()->logoutOtherDevices($request->input('password')); |
|
102
|
|
|
|
|
103
|
|
|
// If the password was successfully reset, we will redirect the user back to |
|
104
|
|
|
// the application's home authenticated view. If there is an error we can |
|
105
|
|
|
// redirect them back to where they came from with their error message. |
|
106
|
|
|
return $response == Password::PASSWORD_RESET |
|
107
|
|
|
? $this->sendResetResponse($request, $response) |
|
108
|
|
|
: $this->sendResetFailedResponse($request, $response); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Get the broker to be used during password reset. |
|
113
|
|
|
* |
|
114
|
|
|
* @return \Illuminate\Contracts\Auth\PasswordBroker |
|
115
|
|
|
*/ |
|
116
|
|
|
public function broker() |
|
117
|
|
|
{ |
|
118
|
|
|
$passwords = config('backpack.base.passwords', config('auth.defaults.passwords')); |
|
119
|
|
|
|
|
120
|
|
|
return Password::broker($passwords); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Get the guard to be used during password reset. |
|
125
|
|
|
* |
|
126
|
|
|
* @return \Illuminate\Contracts\Auth\StatefulGuard |
|
127
|
|
|
*/ |
|
128
|
|
|
protected function guard() |
|
129
|
|
|
{ |
|
130
|
|
|
return backpack_auth(); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|