Нема описа
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.

NewPasswordController.php 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Auth\Events\PasswordReset;
  5. use Illuminate\Http\RedirectResponse;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Hash;
  8. use Illuminate\Support\Facades\Password;
  9. use Illuminate\Support\Str;
  10. use Illuminate\Validation\Rules;
  11. use Illuminate\View\View;
  12. class NewPasswordController extends Controller
  13. {
  14. /**
  15. * Display the password reset view.
  16. */
  17. public function create(Request $request): View
  18. {
  19. return view('auth.reset-password', ['request' => $request]);
  20. }
  21. /**
  22. * Handle an incoming new password request.
  23. *
  24. * @throws \Illuminate\Validation\ValidationException
  25. */
  26. public function store(Request $request): RedirectResponse
  27. {
  28. $request->validate([
  29. 'token' => ['required'],
  30. 'email' => ['required', 'email'],
  31. 'password' => ['required', 'confirmed', Rules\Password::defaults()],
  32. ]);
  33. // Here we will attempt to reset the user's password. If it is successful we
  34. // will update the password on an actual user model and persist it to the
  35. // database. Otherwise we will parse the error and return the response.
  36. $status = Password::reset(
  37. $request->only('email', 'password', 'password_confirmation', 'token'),
  38. function ($user) use ($request) {
  39. $user->forceFill([
  40. 'password' => Hash::make($request->password),
  41. 'remember_token' => Str::random(60),
  42. ])->save();
  43. event(new PasswordReset($user));
  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 $status == Password::PASSWORD_RESET
  50. ? redirect()->route('login')->with('status', __($status))
  51. : back()->withInput($request->only('email'))
  52. ->withErrors(['email' => __($status)]);
  53. }
  54. }