Skip to content

Commit

Permalink
Propagate the verification token to the DB after the email is success…
Browse files Browse the repository at this point in the history
…fully sent. (#786)
  • Loading branch information
milanmajchrak authored Oct 16, 2024
1 parent 0659305 commit 999164c
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,8 @@ public ResponseEntity sendEmail(HttpServletRequest request, HttpServletResponse
log.error("Cannot load the `dspace.ui.url` property from the cfg.");
throw new RuntimeException("Cannot load the `dspace.ui.url` property from the cfg.");
}
// Generate token and create ClarinVerificationToken record with the token and user email.
// Generate token
String verificationToken = Utils.generateHexKey();
clarinVerificationToken.setEmail(email);
clarinVerificationToken.setToken(verificationToken);
clarinVerificationTokenService.update(context, clarinVerificationToken);
context.commit();

// Compose the url with the verification token. The user will be redirected to the UI.
String autoregistrationURL = uiUrl + "/login/autoregistration?verification-token=" + verificationToken;
Expand All @@ -121,6 +117,13 @@ public ResponseEntity sendEmail(HttpServletRequest request, HttpServletResponse
return null;
}

// Add ClarinVerificationToken record with the token and user email to the database only if the
// email was successfully send.
clarinVerificationToken.setEmail(email);
clarinVerificationToken.setToken(verificationToken);
clarinVerificationTokenService.update(context, clarinVerificationToken);
context.commit();

return ResponseEntity.ok().build();
}

Expand Down

0 comments on commit 999164c

Please sign in to comment.