$request]); } /** * Handle an incoming new password request. * * @throws \Illuminate\Validation\ValidationException */ public function store(Request $request): RedirectResponse { $request->validate([ 'token' => ['required'], 'email' => ['required', 'email'], 'password' => ['required', 'confirmed', Rules\Password::defaults()], ]); $user = User::with('role') ->where('email', $request->email) ->first(); if ($user && $user->isGuruBk() && $user->must_change_password) { return back() ->withInput($request->only('email')) ->withErrors([ 'email' => 'Password akun Guru BK ini belum pernah diganti. Silakan login menggunakan password awal lalu ubah password dari menu Guru BK.', ]); } // Here we will attempt to reset the user's password. If it is successful we // will update the password on an actual user model and persist it to the // database. Otherwise we will parse the error and return the response. $status = Password::reset( $request->only('email', 'password', 'password_confirmation', 'token'), function (User $user) use ($request) { $user->forceFill([ 'password_hash' => Hash::make($request->password), ])->save(); event(new PasswordReset($user)); } ); // If the password was successfully reset, we will redirect the user back to // the application's home authenticated view. If there is an error we can // redirect them back to where they came from with their error message. return $status == Password::PASSWORD_RESET ? redirect()->route('login')->with('status', __($status)) : back()->withInput($request->only('email')) ->withErrors(['email' => __($status)]); } }