. */ /** @noinspection PhpDynamicAsStaticMethodCallInspection */ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Auth; use FireflyConfig; use FireflyIII\Http\Controllers\Controller; use FireflyIII\User; use Illuminate\Foundation\Auth\ResetsPasswords; use Illuminate\Http\Request; use Illuminate\Support\Facades\Password; /** * Class ResetPasswordController * * This controller is responsible for handling password reset requests * and uses a simple trait to include this behavior. You're free to * explore this trait and override any methods you wish to tweak. * * @codeCoverageIgnore */ class ResetPasswordController extends Controller { use ResetsPasswords; /** * Where to redirect users after resetting their password. * * @var string */ protected $redirectTo = '/home'; /** * Create a new controller instance. */ public function __construct() { parent::__construct(); $this->middleware('guest'); } /** * Display the password reset view for the given token. * * If no token is present, display the link request form. * * @param Request $request * @param string|null $token * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function showResetForm(Request $request, $token = null) { $loginProvider = env('LOGIN_PROVIDER','eloquent'); if ('eloquent' !== $loginProvider) { $message = sprintf('Cannot reset password when authenticating over "%s".', $loginProvider); return view('error', compact('message')); } // is allowed to register? $singleUserMode = FireflyConfig::get('single_user_mode', config('firefly.configuration.single_user_mode'))->data; $userCount = User::count(); $allowRegistration = true; if (true === $singleUserMode && $userCount > 0) { $allowRegistration = false; } /** @noinspection PhpUndefinedFieldInspection */ return view('auth.passwords.reset')->with( ['token' => $token, 'email' => $request->email, 'allowRegistration' => $allowRegistration] ); } /** * Reset the given user's password. * * @param \Illuminate\Http\Request $request * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse * @throws \Illuminate\Validation\ValidationException */ public function reset(Request $request) { $loginProvider = env('LOGIN_PROVIDER','eloquent'); if ('eloquent' !== $loginProvider) { $message = sprintf('Cannot reset password when authenticating over "%s".', $loginProvider); return view('error', compact('message')); } $this->validate($request, $this->rules(), $this->validationErrorMessages()); // 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. $response = $this->broker()->reset( $this->credentials($request), function ($user, $password) { $this->resetPassword($user, $password); } ); // 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 $response === Password::PASSWORD_RESET ? $this->sendResetResponse($request, $response) : $this->sendResetFailedResponse($request, $response); } }