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));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||||
} catch
|
} catch
|
||||||
(HasConfirmedEmailException | TokenExpiredException ex) {
|
(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);
|
this.emailConfirmationManager.sendConfirmationEmail(email, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||||
} catch (Exception ex) {
|
} 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));
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,20 +34,21 @@ public class EmailConfirmationManager {
|
||||||
.getDatabaseRepository().getLoginConfirmationEmailDao().asQueryable()
|
.getDatabaseRepository().getLoginConfirmationEmailDao().asQueryable()
|
||||||
.where((builder, root) -> builder.equal(root.get("token"), UUID.fromString(token))).getSingle();
|
.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()
|
UserInfo user = databaseRepository.getUserInfoDao().asQueryable()
|
||||||
.where((builder, root) -> builder.equal(root.get("id"), loginConfirmationEmail.getUserId())).getSingle();
|
.where((builder, root) -> builder.equal(root.get("id"), loginConfirmationEmail.getUserId())).getSingle();
|
||||||
|
|
||||||
if (user.getEmail() != null)
|
if (user.getEmail() != null)
|
||||||
throw new HasConfirmedEmailException("User already has confirmed his Email.");
|
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);
|
loginConfirmationEmail.setIsConfirmed(true);
|
||||||
|
|
||||||
// Checks if mail is used by another user. If it is, merges the new the old.
|
// 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();
|
Long existingUsers = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).count();
|
||||||
if (oldUser != null) {
|
if (existingUsers > 0) {
|
||||||
|
UserInfo oldUser = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).getSingle();
|
||||||
mergeNewUserToOld(user, oldUser);
|
mergeNewUserToOld(user, oldUser);
|
||||||
expireUserToken(user);
|
expireUserToken(user);
|
||||||
databaseRepository.getLoginConfirmationEmailDao().createOrUpdate(loginConfirmationEmail);
|
databaseRepository.getLoginConfirmationEmailDao().createOrUpdate(loginConfirmationEmail);
|
||||||
|
|
|
@ -62,7 +62,12 @@ export class EmailConfirmation extends BaseComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
onCallbackError(error: any) {
|
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.uiNotificationService.snackBarNotification(this.language.instant('EMAIL-CONFIRMATION.EXPIRED-EMAIL'), SnackBarNotificationLevel.Error);
|
||||||
this.router.navigate(['login']);
|
this.router.navigate(['login']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,7 +146,8 @@
|
||||||
"REQUEST-EMAIL-HEADER": "We are almost done! Please fill your e-mail.",
|
"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.",
|
"REQUEST-EMAIL-TEXT": "You will need to confirm it to use the application.",
|
||||||
"SUBMIT": "Submit",
|
"SUBMIT": "Submit",
|
||||||
"SENT-EMAIL-HEADER": "Email was send!"
|
"SENT-EMAIL-HEADER": "Email was send!",
|
||||||
|
"EMAIL-FOUND": "Email is already confirmed"
|
||||||
},
|
},
|
||||||
"HOME": {
|
"HOME": {
|
||||||
"DMPS": "DMPs",
|
"DMPS": "DMPs",
|
||||||
|
|
Loading…
Reference in New Issue