Commit 545724b3 authored by Matija Obreza's avatar Matija Obreza
Browse files

Add more error messages to /registration

parent 4ec450be
......@@ -27,6 +27,7 @@ import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.EMailVerificationService;
import org.genesys2.server.service.OrganizationService;
import org.genesys2.server.service.PasswordPolicy.PasswordPolicyException;
import org.genesys2.server.service.StatisticsService;
import org.genesys2.server.service.UserService;
import org.genesys2.server.servlet.filter.LocaleURLFilter;
......@@ -38,12 +39,12 @@ import org.springframework.security.access.AccessDeniedException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.Validator;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
/**
* Controller which simply handles *.html requests
......@@ -127,7 +128,7 @@ public class HtmlController extends BaseController {
@RequestMapping(value = "new-user")
public String addUser(@ModelAttribute User user, BindingResult bindingResult, HttpServletRequest req,
@RequestParam(value = "g-recaptcha-response", required = false) String response) throws IOException {
@RequestParam(value = "g-recaptcha-response", required = false) String response, RedirectAttributes redirectAttributes) throws IOException {
user.getRoles().add(UserRole.USER);
validator.validate(user, bindingResult);
......@@ -135,9 +136,8 @@ public class HtmlController extends BaseController {
// Validate the reCAPTCHA
if (!ReCaptchaUtil.isValid(response, req.getRemoteAddr(), captchaPrivateKey)) {
_logger.warn("Invalid captcha.");
final FieldError fieldError = new FieldError("comment", "captcha", response, false, new String[] { "errors.badCaptcha" }, null,
"Please try again.");
bindingResult.addError(fieldError);
redirectAttributes.addFlashAttribute("error", "errors.badCaptcha");
return "redirect:/registration.html";
}
try {
......@@ -149,17 +149,21 @@ public class HtmlController extends BaseController {
return "redirect:/content/account-created";
} else {
return "redirect:/registration.html?exist=true";
redirectAttributes.addFlashAttribute("error", "registration.user-exists");
}
} else {
redirectAttributes.addFlashAttribute("error", "New account form has errors: " + bindingResult.getErrorCount());
_logger.warn("New account form has errors: " + bindingResult.getErrorCount());
}
} catch (final PasswordPolicyException e) {
redirectAttributes.addFlashAttribute("error", e.getMessage());
} catch (final Exception e) {
_logger.error(e.getMessage(), e);
// simpleExceptionHandler(e);
redirectAttributes.addFlashAttribute("error", e.getMessage());
}
return "redirect:/registration.html?error=true";
return "redirect:/registration.html";
}
@RequestMapping("/access-denied")
......
......@@ -18,12 +18,10 @@
<%@include file="/WEB-INF/jsp/content/include/blurp-display.jsp"%>
<c:if test="${param['error'] ne null}">
<div class="alert alert-error">
<spring:message code="registration.invalid-credentials" />
</div>
<c:if test="${not empty error}">
<div class="alert alert-danger"><spring:message code="${error}" /></div>
</c:if>
<c:if test="${param['exist'] ne null}">
<div class="alert alert-error">
<spring:message code="registration.user-exists" />
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment