Skip to content

Commit

Permalink
Show verification code on success
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Oct 6, 2024
1 parent 972ba70 commit 808a220
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class VerifyController extends VonageController {
VERIFY_START_TEMPLATE = "verify_start",
VERIFY_RESULT_TEMPLATE = "verify_result";

private final Collection<UUID> successfulVerifications = new LinkedHashSet<>();
private final Map<UUID, String> successfulVerifications = new LinkedHashMap<>();

protected Verify2Client getVerifyClient() {
return getVonageClient().getVerify2Client();
Expand Down Expand Up @@ -103,17 +103,19 @@ public String checkVerificationRequest(@ModelAttribute VerifyParams verifyParams
try {
String result = "Code matched. Verification successful.";
if (verifyParams.codeless || verifyParams.checkUrl != null || verifyParams.getUserCode() == null) {
if (!successfulVerifications.contains(verifyParams.requestId)) synchronized (successfulVerifications) {
String code = successfulVerifications.remove(verifyParams.requestId);
if (code == null) synchronized (successfulVerifications) {
try {
successfulVerifications.wait(2000);
if (!successfulVerifications.remove(verifyParams.requestId)) {
if ((code = successfulVerifications.remove(verifyParams.requestId)) == null) {
result = "Verification failed.";
}
}
catch (InterruptedException ie) {
// Continue
}
}
verifyParams.userCode = code;
}
else {
try {
Expand All @@ -125,6 +127,7 @@ public String checkVerificationRequest(@ModelAttribute VerifyParams verifyParams
}
}
model.addAttribute("result", result);
model.addAttribute("verifyParams", verifyParams);
return VERIFY_RESULT_TEMPLATE;
}
catch (Exception ex) {
Expand Down Expand Up @@ -194,7 +197,7 @@ public String completeRegistrationInternal(
var check = getVerifyClient().checkVerificationCode(requestId, code);
var status = check.getStatus();
if (status == VerificationStatus.COMPLETED) synchronized (successfulVerifications) {
successfulVerifications.add(requestId);
successfulVerifications.put(requestId, code);
successfulVerifications.notify();
return "<h1>Registration successful!</h1>";
}
Expand Down

0 comments on commit 808a220

Please sign in to comment.