Skip to content

Commit

Permalink
Merge pull request #556 from AudiovisualMetadataPlatform/AMP-2852_url
Browse files Browse the repository at this point in the history
AMP-2852: fix email activation url
  • Loading branch information
yingfeng-iu authored Aug 21, 2023
2 parents 87d4df9 + 0e78aea commit babddde
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,12 @@ public AuthResponse accountAction(Long userId, String action){
String notice = "";

// for account approval
if (action.equalsIgnoreCase("approve")){
if (action.equalsIgnoreCase("approve")) {
status = Status.ACCEPTED;
notice = "account approval";
}
// for account rejection
else if (action.equalsIgnoreCase("reject")){
else if (action.equalsIgnoreCase("reject")) {
status = Status.REJECTED;
notice = "account rejection";
}
Expand All @@ -281,10 +281,18 @@ else if (action.equalsIgnoreCase("reject")){

// for valid action, continue account action
try {
// update user account status and send email notification to user
// update user account status
user.setStatus(status);
ampUserRepository.updateStatus(userId, status);
mailSender.send(constructEmailAttributes(uiUrl, user, notice));
ampUserRepository.updateStatus(userId, status);

// send email notification to user
if (action.equalsIgnoreCase("approve")) {
mailSender.send(constructTokenEmail(uiUrl, user, notice));
}
else {
mailSender.send(constructEmailAttributes(uiUrl, user, notice));
}

response.setSuccess(true);
log.info("Successfully " + action + "ed account registration for useer " + userId);
}
Expand Down Expand Up @@ -381,7 +389,7 @@ public AuthResponse activateAccount(String token)
AmpUser user = ampUserRepository.findById(passToken.getUser().getId()).orElseThrow(() -> new RuntimeException("User not found: " + passToken.getId()));
if(user!= null) {
if(user.getStatus() == AmpUser.Status.ACCEPTED){
log.info("Corresponding amp user was found.");
log.debug("Corresponding amp user was approved for activation.");
try {
ampUserRepository.updateStatus(user.getId(), AmpUser.Status.ACTIVATED);
response.setSuccess(true);
Expand Down Expand Up @@ -417,12 +425,12 @@ private SimpleMailMessage constructTokenEmail(String contextPath, AmpUser user,
if (type.equalsIgnoreCase("reset password")) {
String token = createTimedToken(user, amppdPropertyConfig.getResetPasswordMinutes());
url = contextPath + "/account/reset-password/" + token;
log.info("Constructed reset token url, constructing email attributes");
log.debug("Constructed reset token url, constructing email attributes");
}
else if (type.equalsIgnoreCase("account approval")) {
String token = createTimedToken(user, amppdPropertyConfig.getActivateAccountDays() * 24);
url = contextPath + "/account/activate/" + token;
log.info("Constructed activation token url, constructing email attributes");
log.debug("Constructed activation token url, constructing email attributes");
}
return constructEmailAttributes(url, user, type);
}
Expand Down Expand Up @@ -462,7 +470,7 @@ else if (type.equalsIgnoreCase("account approval")){
subject = "Activate your account";
emailTo = user.getEmail();
}
log.debug("Sending " + type + " email from " + adminEmail + " to " + emailTo);
log.info("Sending " + type + " email from " + adminEmail + " to " + emailTo);
return constructEmail(subject, message + " \r\n" + url, emailTo);
}

Expand Down

0 comments on commit babddde

Please sign in to comment.