|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BeyondCode\EmailConfirmation\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use Illuminate\Support\Facades\Password; |
|
7
|
|
|
|
|
8
|
|
|
trait ResetsPasswords |
|
9
|
|
|
{ |
|
10
|
|
|
use \Illuminate\Foundation\Auth\ResetsPasswords; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Reset the given user's password. |
|
14
|
|
|
* |
|
15
|
|
|
* @param \Illuminate\Http\Request $request |
|
16
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse |
|
17
|
|
|
*/ |
|
18
|
|
|
public function reset(Request $request) |
|
19
|
|
|
{ |
|
20
|
|
|
$this->validate($request, $this->rules(), $this->validationErrorMessages()); |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
$user = $this->broker()->getUser($this->credentials($request)); |
|
23
|
|
|
|
|
24
|
|
|
// If the user hasn't confirmed their email address, |
|
25
|
|
|
// we will redirect them back with their error message. |
|
26
|
|
|
if (is_null($user->confirmed_at)) { |
|
27
|
|
|
|
|
28
|
|
|
session(['confirmation_user_id' => $user->getKey()]); |
|
29
|
|
|
|
|
30
|
|
|
return redirect()->back()->with( |
|
31
|
|
|
'confirmation', __('confirmation::confirmation.not_confirmed', [ |
|
32
|
|
|
'resend_link' => route('auth.resend_confirmation') |
|
33
|
|
|
]) |
|
34
|
|
|
); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
// Here we will attempt to reset the user's password. If it is successful we |
|
38
|
|
|
// will update the password on an actual user model and persist it to the |
|
39
|
|
|
// database. Otherwise we will parse the error and return the response. |
|
40
|
|
|
$response = $this->broker()->reset( |
|
41
|
|
|
$this->credentials($request), function ($user, $password) { |
|
42
|
|
|
$this->resetPassword($user, $password); |
|
43
|
|
|
} |
|
44
|
|
|
); |
|
45
|
|
|
|
|
46
|
|
|
// If the password was successfully reset, we will redirect the user back to |
|
47
|
|
|
// the application's home authenticated view. If there is an error we can |
|
48
|
|
|
// redirect them back to where they came from with their error message. |
|
49
|
|
|
return $response == Password::PASSWORD_RESET |
|
50
|
|
|
? $this->sendResetResponse($response) |
|
51
|
|
|
: $this->sendResetFailedResponse($request, $response); |
|
52
|
|
|
} |
|
53
|
|
|
} |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.