1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Thinktomorrow\Chief\App\Http\Controllers\Auth; |
4
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Auth\ResetsPasswords; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
use Illuminate\Support\Facades\Auth; |
8
|
|
|
use Illuminate\Support\Facades\Password; |
9
|
|
|
use Thinktomorrow\Chief\Admin\Authorization\ChiefPasswordBroker; |
10
|
|
|
use Thinktomorrow\Chief\Admin\Authorization\ChiefPasswordBrokerResolver; |
11
|
|
|
use Thinktomorrow\Chief\App\Http\Controllers\Controller; |
12
|
|
|
|
13
|
|
|
class ResetPasswordController extends Controller |
14
|
|
|
{ |
15
|
|
|
/* |
16
|
|
|
|-------------------------------------------------------------------------- |
17
|
|
|
| Password Reset Controller |
18
|
|
|
|-------------------------------------------------------------------------- |
19
|
|
|
| |
20
|
|
|
| This controller is responsible for handling password reset requests |
21
|
|
|
| and uses a simple trait to include this behavior. You're free to |
22
|
|
|
| explore this trait and override any methods you wish to tweak. |
23
|
|
|
| |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
use ResetsPasswords; |
|
|
|
|
27
|
|
|
|
28
|
|
|
public function __construct() |
29
|
|
|
{ |
30
|
|
|
$this->middleware('chief-guest'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function showResetForm(Request $request, $token = null) |
34
|
|
|
{ |
35
|
|
|
return view('chief::admin.auth.passwords.reset')->with(['token' => $token, 'email' => $request->email]); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return \Illuminate\Contracts\Auth\Guard|\Illuminate\Contracts\Auth\StatefulGuard |
40
|
|
|
*/ |
41
|
|
|
protected function guard() |
42
|
|
|
{ |
43
|
|
|
return Auth::guard('chief'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function broker() |
47
|
|
|
{ |
48
|
|
|
return (new ChiefPasswordBrokerResolver(app()))->resolve(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function redirectTo(): string |
52
|
|
|
{ |
53
|
|
|
return route('chief.back.dashboard'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// Override the reset method because chief uses different lang keys and |
57
|
|
|
// laravel internals expects this to be of a specific value. |
58
|
|
|
/** |
59
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
60
|
|
|
*/ |
61
|
|
|
public function reset(Request $request) |
62
|
|
|
{ |
63
|
|
|
$request->validate($this->rules(), $this->validationErrorMessages()); |
64
|
|
|
|
65
|
|
|
// Here we will attempt to reset the user's password. If it is successful we |
66
|
|
|
// will update the password on an actual user model and persist it to the |
67
|
|
|
// database. Otherwise we will parse the error and return the response. |
68
|
|
|
$response = $this->broker()->reset($this->credentials($request), function ($user, $password) { |
69
|
|
|
$this->resetPassword($user, $password); |
70
|
|
|
}); |
71
|
|
|
|
72
|
|
|
// If the password was successfully reset, we will redirect the user back to |
73
|
|
|
// the application's home authenticated view. If there is an error we can |
74
|
|
|
// redirect them back to where they came from with their error message. |
75
|
|
|
return $response == ChiefPasswordBroker::PASSWORD_RESET |
76
|
|
|
? $this->sendResetResponse($request, $response) |
77
|
|
|
: $this->sendResetFailedResponse($request, $response); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|