3 namespace App\Http\Controllers\Auth;
5 use App\Http\Controllers\Controller;
6 use Illuminate\Auth\Events\PasswordReset;
7 use Illuminate\Http\Request;
8 use Illuminate\Support\Facades\Hash;
9 use Illuminate\Support\Facades\Password;
10 use Illuminate\Support\Str;
11 use Illuminate\Validation\Rules;
13 class NewPasswordController extends Controller
16 * Display the password reset view.
18 * @param \Illuminate\Http\Request $request
19 * @return \Illuminate\View\View
21 public function create(Request $request)
23 return view('auth.reset-password', ['request' => $request]);
27 * Handle an incoming new password request.
29 * @param \Illuminate\Http\Request $request
30 * @return \Illuminate\Http\RedirectResponse
32 * @throws \Illuminate\Validation\ValidationException
34 public function store(Request $request)
37 'token' => ['required'],
38 'email' => ['required', 'email'],
39 'password' => ['required', 'confirmed', Rules\Password::defaults()],
42 // Here we will attempt to reset the user's password. If it is successful we
43 // will update the password on an actual user model and persist it to the
44 // database. Otherwise we will parse the error and return the response.
45 $status = Password::reset(
46 $request->only('email', 'password', 'password_confirmation', 'token'),
47 function ($user) use ($request) {
49 'password' => Hash::make($request->password),
50 'remember_token' => Str::random(60),
53 event(new PasswordReset($user));
57 // If the password was successfully reset, we will redirect the user back to
58 // the application's home authenticated view. If there is an error we can
59 // redirect them back to where they came from with their error message.
60 return $status == Password::PASSWORD_RESET
61 ? redirect()->route('login')->with('status', __($status))
62 : back()->withInput($request->only('email'))
63 ->withErrors(['email' => __($status)]);