|
|
@ -64,13 +64,17 @@ public class RegistrationController { |
|
|
|
log.warn("Registration input has errors!"); |
|
|
|
return "redirect:registration?error"; |
|
|
|
} |
|
|
|
if (userService.getUser(userRegistrationDTO.getUserName()).isPresent()) { |
|
|
|
if (userService.getUser(userRegistrationDTO.getUserName()) |
|
|
|
.isPresent()) { |
|
|
|
return "redirect:registration?error&duplicate=true"; |
|
|
|
} |
|
|
|
|
|
|
|
log.debug("Captcha text from user input = {}", userRegistrationDTO.getCaptchaInput()); |
|
|
|
log.debug("Captcha text from captcha map = {}", captchaMap.get(userRegistrationDTO.getCaptchaID())); |
|
|
|
if (userRegistrationDTO.getCaptchaInput().equals(captchaMap.get(userRegistrationDTO.getCaptchaID()))) { |
|
|
|
log.debug("Captcha text from user input = {}", |
|
|
|
userRegistrationDTO.getCaptchaInput()); |
|
|
|
log.debug("Captcha text from captcha map = {}", |
|
|
|
captchaMap.get(userRegistrationDTO.getCaptchaID())); |
|
|
|
if (userRegistrationDTO.getCaptchaInput() |
|
|
|
.equals(captchaMap.get(userRegistrationDTO.getCaptchaID()))) { |
|
|
|
log.info("Registration captcha equal success"); |
|
|
|
userService.createUser(userRegistrationDTO); |
|
|
|
return "redirect:registration?success"; |
|
|
@ -81,12 +85,14 @@ public class RegistrationController { |
|
|
|
} |
|
|
|
|
|
|
|
@GetMapping(value = "/img/captcha/{image_id}", produces = MediaType.IMAGE_PNG_VALUE) |
|
|
|
public ResponseEntity<byte[]> getImage(@PathVariable("image_id") Long imageId) throws IOException { |
|
|
|
public ResponseEntity<byte[]> getImage( |
|
|
|
@PathVariable("image_id") Long imageId) throws IOException { |
|
|
|
|
|
|
|
final String captchaText = captchaMap.get(imageId); |
|
|
|
final HttpHeaders headers = new HttpHeaders(); |
|
|
|
headers.setContentType(MediaType.IMAGE_PNG); |
|
|
|
BufferedImage captchaBufferedImage = captchaService.createCaptchaImage(captchaText); |
|
|
|
BufferedImage captchaBufferedImage = captchaService |
|
|
|
.createCaptchaImage(captchaText); |
|
|
|
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
|
|
ImageIO.write(captchaBufferedImage, "png", baos); |
|
|
|