|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Api\V1\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
6
|
|
|
use Illuminate\Support\Facades\Password; |
|
7
|
|
|
use App\Api\V1\Requests\ResetPasswordRequest; |
|
8
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException; |
|
9
|
|
|
|
|
10
|
|
|
class ResetPasswordController extends Controller |
|
11
|
|
|
{ |
|
12
|
|
|
public function resetPassword(ResetPasswordRequest $request) |
|
13
|
|
|
{ |
|
14
|
|
|
$response = $this->broker()->reset( |
|
15
|
|
|
$this->credentials($request), function ($user, $password) { |
|
16
|
|
|
$this->reset($user, $password); |
|
17
|
|
|
} |
|
18
|
|
|
); |
|
19
|
|
|
|
|
20
|
|
|
if (Password::PASSWORD_RESET !== $response) { |
|
21
|
|
|
throw new HttpException(500); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
return response()->json([ |
|
25
|
|
|
'status' => 'ok', |
|
26
|
|
|
]); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Get the broker to be used during password reset. |
|
31
|
|
|
* |
|
32
|
|
|
* @return \Illuminate\Contracts\Auth\PasswordBroker |
|
33
|
|
|
*/ |
|
34
|
|
|
public function broker() |
|
35
|
|
|
{ |
|
36
|
|
|
return Password::broker(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Get the password reset credentials from the request. |
|
41
|
|
|
* |
|
42
|
|
|
* @param ResetPasswordRequest $request |
|
43
|
|
|
* |
|
44
|
|
|
* @return array |
|
45
|
|
|
*/ |
|
46
|
|
|
protected function credentials(ResetPasswordRequest $request) |
|
47
|
|
|
{ |
|
48
|
|
|
return $request->only( |
|
49
|
|
|
'email', 'password', 'password_confirmation', 'token' |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Reset the given user's password. |
|
55
|
|
|
* |
|
56
|
|
|
* @param \Illuminate\Contracts\Auth\CanResetPassword $user |
|
57
|
|
|
* @param string $password |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function reset($user, $password) |
|
60
|
|
|
{ |
|
61
|
|
|
$user->password = $password; |
|
|
|
|
|
|
62
|
|
|
$user->save(); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|