Skip to content

Commit

Permalink
Added recaptcha token to register endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
soasada committed May 10, 2020
1 parent d223945 commit d9f154e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ public class CustomerRequest {
@NotBlank
@Size(min = 8, max = 255)
String password;
@NotBlank
String recaptchaToken;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.kemenu.kemenu_backend.application.customer.CustomerMapper;
import com.kemenu.kemenu_backend.application.customer.CustomerRequest;
import com.kemenu.kemenu_backend.application.customer.CustomerService;
import com.kemenu.kemenu_backend.application.security.Recaptcha;
import lombok.AllArgsConstructor;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.HttpStatus;
Expand All @@ -12,21 +13,28 @@
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.io.IOException;
import java.util.UUID;

@RestController
@AllArgsConstructor
public class RegisterController {

private final Recaptcha recaptcha;
private final CustomerMapper customerMapper;
private final CustomerService customerService;

@PostMapping("/register")
public ResponseEntity<UUID> create(@RequestBody @Valid CustomerRequest customerRequest) {
try {
return ResponseEntity.ok(UUID.fromString(customerService.create(customerMapper.from(customerRequest))));
if (recaptcha.isValid(customerRequest.getRecaptchaToken())) {
return ResponseEntity.ok(UUID.fromString(customerService.create(customerMapper.from(customerRequest))));
}
return ResponseEntity.status(HttpStatus.TOO_MANY_REQUESTS).body(null);
} catch (DuplicateKeyException e) {
return ResponseEntity.status(HttpStatus.CONFLICT).body(null);
} catch (IOException e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
}

0 comments on commit d9f154e

Please sign in to comment.