App\Modules\System\Controllers\Authorize::postReset PHP Method

postReset() public method

Handle a POST request to reset a User's password.
public postReset ( ) : Response
return Response
    public function postReset()
    {
        // Verify the reCAPTCHA
        if (!ReCaptcha::check()) {
            $status = __d('system', 'Invalid reCAPTCHA submitted.');
            return Redirect::back()->withStatus($status, 'danger');
        }
        $credentials = Input::only('email', 'password', 'password_confirmation', 'token');
        // Add to Password Broker a custom validation.
        Password::validator(function ($credentials) {
            $pattern = "/(?=^.{8,}\$)((?=.*\\d)|(?=.*\\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*\$/";
            return preg_match($pattern, $credentials['password']) === 1;
        });
        $response = Password::reset($credentials, function ($user, $password) {
            $user->password = Hash::make($password);
            $user->save();
        });
        // Parse the response.
        switch ($response) {
            case Password::INVALID_PASSWORD:
                $status = __d('system', 'Passwords must be strong enough and match the confirmation.');
                break;
            case Password::INVALID_TOKEN:
                $status = __d('system', 'This password reset token is invalid.');
                break;
            case Password::INVALID_USER:
                $status = __d('system', 'We can\'t find a User with that e-mail address.');
                break;
            case Password::PASSWORD_RESET:
                $status = __d('system', 'You have successfully reset your Password.');
                return Redirect::to('login')->withStatus($status);
        }
        return Redirect::back()->withStatus($status, 'danger');
    }