Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
78.57% |
11 / 14 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| PasswordResetLinkController | |
78.57% |
11 / 14 |
|
50.00% |
1 / 2 |
3.09 | |
0.00% |
0 / 1 |
| create | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| store | |
72.73% |
8 / 11 |
|
0.00% |
0 / 1 |
2.08 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers\Auth; |
| 4 | |
| 5 | use App\Http\Controllers\Controller; |
| 6 | use Illuminate\Http\RedirectResponse; |
| 7 | use Illuminate\Http\Request; |
| 8 | use Illuminate\Support\Facades\Password; |
| 9 | use Illuminate\Validation\ValidationException; |
| 10 | use Inertia\Inertia; |
| 11 | use Inertia\Response; |
| 12 | |
| 13 | class PasswordResetLinkController extends Controller |
| 14 | { |
| 15 | /** |
| 16 | * Display the password reset link request view. |
| 17 | */ |
| 18 | public function create(): Response |
| 19 | { |
| 20 | return Inertia::render('Auth/ForgotPassword', [ |
| 21 | 'status' => session('status'), |
| 22 | ]); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Handle an incoming password reset link request. |
| 27 | * |
| 28 | * @throws \Illuminate\Validation\ValidationException |
| 29 | */ |
| 30 | public function store(Request $request): RedirectResponse |
| 31 | { |
| 32 | $request->validate([ |
| 33 | 'email' => 'required|email', |
| 34 | ]); |
| 35 | |
| 36 | // We will send the password reset link to this user. Once we have attempted |
| 37 | // to send the link, we will examine the response then see the message we |
| 38 | // need to show to the user. Finally, we'll send out a proper response. |
| 39 | $status = Password::sendResetLink( |
| 40 | $request->only('email') |
| 41 | ); |
| 42 | |
| 43 | if ($status == Password::RESET_LINK_SENT) { |
| 44 | return back()->with('status', __($status)); |
| 45 | } |
| 46 | |
| 47 | throw ValidationException::withMessages([ |
| 48 | 'email' => [trans($status)], |
| 49 | ]); |
| 50 | } |
| 51 | } |