diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/ClarinAutoRegistrationController.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/ClarinAutoRegistrationController.java index de2dccb9e866..af6c01714fa7 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/ClarinAutoRegistrationController.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/ClarinAutoRegistrationController.java @@ -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; @@ -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(); }