You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

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