use of io.gravitee.am.common.exception.authentication.AccountStatusException in project gravitee-access-management by gravitee-io.
the class ForgotPasswordSubmissionEndpoint method handle.
@Override
public void handle(RoutingContext context) {
final String email = context.request().getParam(ConstantKeys.EMAIL_PARAM_KEY);
final String username = context.request().getParam(ConstantKeys.USERNAME_PARAM_KEY);
final Client client = context.get(ConstantKeys.CLIENT_CONTEXT_KEY);
MultiMap queryParams = RequestUtils.getCleanedQueryParams(context.request());
AccountSettings settings = AccountSettings.getInstance(domain, client);
final ForgotPasswordParameters parameters = new ForgotPasswordParameters(email, username, settings != null && settings.isResetPasswordCustomForm(), settings != null && settings.isResetPasswordConfirmIdentity());
userService.forgotPassword(parameters, client, getAuthenticatedUser(context)).subscribe(() -> {
queryParams.set(ConstantKeys.SUCCESS_PARAM_KEY, "forgot_password_completed");
redirectToPage(context, queryParams);
}, error -> {
// the actual error continue to be stored in the audit logs
if (error instanceof UserNotFoundException || error instanceof AccountStatusException) {
queryParams.set(ConstantKeys.SUCCESS_PARAM_KEY, "forgot_password_completed");
redirectToPage(context, queryParams);
} else if (error instanceof EnforceUserIdentityException) {
if (settings.isResetPasswordConfirmIdentity()) {
queryParams.set(ConstantKeys.WARNING_PARAM_KEY, FORGOT_PASSWORD_CONFIRM);
} else {
queryParams.set(ConstantKeys.SUCCESS_PARAM_KEY, "forgot_password_completed");
}
redirectToPage(context, queryParams);
} else {
queryParams.set(ConstantKeys.ERROR_PARAM_KEY, "forgot_password_failed");
redirectToPage(context, queryParams, error);
}
});
}
Aggregations