Fixed issue when trying to retrieve non-existing user during e-mail confirmation and when the e-mail is confirmed it will show proper message on the frontend (ref #233)
This commit is contained in:
parent
8b1d285ff4
commit
6c73ed5131
|
@ -36,7 +36,11 @@ public class EmailConfirmation {
|
|||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||
} catch
|
||||
(HasConfirmedEmailException | TokenExpiredException ex) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE));
|
||||
if (ex instanceof TokenExpiredException) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE));
|
||||
} else {
|
||||
return ResponseEntity.status(HttpStatus.FOUND).body(new ResponseItem().status(ApiMessageCode.WARN_MESSAGE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,6 +52,9 @@ public class EmailConfirmation {
|
|||
this.emailConfirmationManager.sendConfirmationEmail(email, principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||
} catch (Exception ex) {
|
||||
if (ex instanceof HasConfirmedEmailException) {
|
||||
return ResponseEntity.status(HttpStatus.FOUND).body(new ResponseItem().status(ApiMessageCode.WARN_MESSAGE));
|
||||
}
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,20 +34,21 @@ public class EmailConfirmationManager {
|
|||
.getDatabaseRepository().getLoginConfirmationEmailDao().asQueryable()
|
||||
.where((builder, root) -> builder.equal(root.get("token"), UUID.fromString(token))).getSingle();
|
||||
|
||||
if (loginConfirmationEmail.getExpiresAt().compareTo(new Date()) < 0)
|
||||
throw new TokenExpiredException("Token has expired.");
|
||||
|
||||
UserInfo user = databaseRepository.getUserInfoDao().asQueryable()
|
||||
.where((builder, root) -> builder.equal(root.get("id"), loginConfirmationEmail.getUserId())).getSingle();
|
||||
|
||||
if (user.getEmail() != null)
|
||||
throw new HasConfirmedEmailException("User already has confirmed his Email.");
|
||||
|
||||
if (loginConfirmationEmail.getExpiresAt().compareTo(new Date()) < 0)
|
||||
throw new TokenExpiredException("Token has expired.");
|
||||
|
||||
loginConfirmationEmail.setIsConfirmed(true);
|
||||
|
||||
// Checks if mail is used by another user. If it is, merges the new the old.
|
||||
UserInfo oldUser = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).getSingle();
|
||||
if (oldUser != null) {
|
||||
Long existingUsers = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).count();
|
||||
if (existingUsers > 0) {
|
||||
UserInfo oldUser = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).getSingle();
|
||||
mergeNewUserToOld(user, oldUser);
|
||||
expireUserToken(user);
|
||||
databaseRepository.getLoginConfirmationEmailDao().createOrUpdate(loginConfirmationEmail);
|
||||
|
|
|
@ -62,7 +62,12 @@ export class EmailConfirmation extends BaseComponent implements OnInit {
|
|||
}
|
||||
|
||||
onCallbackError(error: any) {
|
||||
if (error.status === 302) {
|
||||
this.uiNotificationService.snackBarNotification(this.language.instant('EMAIL-CONFIRMATION.EMAIL-FOUND'), SnackBarNotificationLevel.Warning);
|
||||
this.router.navigate(['home']);
|
||||
} else {
|
||||
this.uiNotificationService.snackBarNotification(this.language.instant('EMAIL-CONFIRMATION.EXPIRED-EMAIL'), SnackBarNotificationLevel.Error);
|
||||
this.router.navigate(['login']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -146,7 +146,8 @@
|
|||
"REQUEST-EMAIL-HEADER": "We are almost done! Please fill your e-mail.",
|
||||
"REQUEST-EMAIL-TEXT": "You will need to confirm it to use the application.",
|
||||
"SUBMIT": "Submit",
|
||||
"SENT-EMAIL-HEADER": "Email was send!"
|
||||
"SENT-EMAIL-HEADER": "Email was send!",
|
||||
"EMAIL-FOUND": "Email is already confirmed"
|
||||
},
|
||||
"HOME": {
|
||||
"DMPS": "DMPs",
|
||||
|
|
Loading…
Reference in New Issue