From 30abe4d4c9bc18c2c0cf1038a9829302485112ed Mon Sep 17 00:00:00 2001 From: Aldo Mihasi Date: Tue, 1 Aug 2023 11:23:06 +0300 Subject: [PATCH] #8952 - fix bug when merging two accounts did not have consistent behaviour. --- .../eu/eudat/controllers/EmailMergeConfirmation.java | 10 +++++----- .../logic/managers/MergeEmailConfirmationManager.java | 6 ++++-- .../src/app/core/services/auth/auth.service.ts | 2 +- .../merge-email-confirmation.component.ts | 10 +++++++++- dmp-frontend/src/assets/i18n/de.json | 3 ++- dmp-frontend/src/assets/i18n/en.json | 3 ++- dmp-frontend/src/assets/i18n/es.json | 3 ++- dmp-frontend/src/assets/i18n/gr.json | 3 ++- dmp-frontend/src/assets/i18n/hr.json | 3 ++- dmp-frontend/src/assets/i18n/pl.json | 3 ++- dmp-frontend/src/assets/i18n/pt.json | 3 ++- dmp-frontend/src/assets/i18n/sk.json | 3 ++- dmp-frontend/src/assets/i18n/sr.json | 3 ++- dmp-frontend/src/assets/i18n/tr.json | 3 ++- 14 files changed, 39 insertions(+), 19 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/EmailMergeConfirmation.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/EmailMergeConfirmation.java index d1e89b493..96f959078 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/EmailMergeConfirmation.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/EmailMergeConfirmation.java @@ -32,16 +32,16 @@ public class EmailMergeConfirmation { @Transactional @RequestMapping(method = RequestMethod.GET, value = {"/{emailToken}"}) public @ResponseBody - ResponseEntity emailConfirmation(@PathVariable(value = "emailToken") String token) { + ResponseEntity> emailConfirmation(@PathVariable(value = "emailToken") String token) { try { - this.emailConfirmationManager.confirmEmail(token); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE)); + String emailToBeMerged = this.emailConfirmationManager.confirmEmail(token); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(emailToBeMerged).status(ApiMessageCode.SUCCESS_MESSAGE)); } catch (HasConfirmedEmailException | TokenExpiredException ex) { if (ex instanceof TokenExpiredException) { - 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)); } else { - return ResponseEntity.status(HttpStatus.FOUND).body(new ResponseItem().status(ApiMessageCode.WARN_MESSAGE)); + return ResponseEntity.status(HttpStatus.FOUND).body(new ResponseItem().status(ApiMessageCode.WARN_MESSAGE)); } } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MergeEmailConfirmationManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MergeEmailConfirmationManager.java index 5b9e1bb2c..4a6b0ac56 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MergeEmailConfirmationManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MergeEmailConfirmationManager.java @@ -47,7 +47,7 @@ public class MergeEmailConfirmationManager { } @Transactional - public void confirmEmail(String token) throws TokenExpiredException, HasConfirmedEmailException { + public String confirmEmail(String token) throws TokenExpiredException, HasConfirmedEmailException { EmailConfirmation loginConfirmationEmail = apiContext.getOperationsContext() .getDatabaseRepository().getLoginConfirmationEmailDao().asQueryable() .where((builder, root) -> builder.equal(root.get("token"), UUID.fromString(token))).getSingle(); @@ -57,7 +57,7 @@ public class MergeEmailConfirmationManager { UserInfo userToBeMerged = databaseRepository.getUserInfoDao().asQueryable() .where((builder, root) -> builder.equal(root.get("id"), loginConfirmationEmail.getUserId())).getSingle(); - + String userToBeMergedEmail = userToBeMerged.getEmail(); try { Map map = new ObjectMapper().readValue(loginConfirmationEmail.getData(), HashMap.class); UUID otherUserId = UUID.fromString((String) map.get("userId")); @@ -72,6 +72,8 @@ public class MergeEmailConfirmationManager { } catch (Exception e) { logger.error(e.getMessage(), e); } + + return userToBeMergedEmail; } public void sendConfirmationEmail(String email, Principal principal, UUID userId, Integer provider) throws HasConfirmedEmailException { diff --git a/dmp-frontend/src/app/core/services/auth/auth.service.ts b/dmp-frontend/src/app/core/services/auth/auth.service.ts index b921df883..53355056d 100644 --- a/dmp-frontend/src/app/core/services/auth/auth.service.ts +++ b/dmp-frontend/src/app/core/services/auth/auth.service.ts @@ -38,7 +38,7 @@ export class AuthService extends BaseService { this.headers = this.headers.set('Accept', 'application/json'); } - private clear(): void { + public clear(): void { localStorage.removeItem('principal'); } diff --git a/dmp-frontend/src/app/ui/auth/login/merge-email-confirmation/merge-email-confirmation.component.ts b/dmp-frontend/src/app/ui/auth/login/merge-email-confirmation/merge-email-confirmation.component.ts index e11f9b1d9..dbff4c3d4 100644 --- a/dmp-frontend/src/app/ui/auth/login/merge-email-confirmation/merge-email-confirmation.component.ts +++ b/dmp-frontend/src/app/ui/auth/login/merge-email-confirmation/merge-email-confirmation.component.ts @@ -1,6 +1,7 @@ import { Component, OnInit } from "@angular/core"; import { FormControl } from '@angular/forms'; import { ActivatedRoute, Router } from "@angular/router"; +import { AuthService } from "@app/core/services/auth/auth.service"; import { EmailConfirmationService } from '@app/core/services/email-confirmation/email-confirmation.service'; import { MergeEmailConfirmationService } from '@app/core/services/merge-email-confirmation/merge-email-confirmation.service'; import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service'; @@ -20,6 +21,7 @@ export class MergeEmailConfirmation extends BaseComponent implements OnInit { constructor( private emailConfirmationService: MergeEmailConfirmationService, + private authService: AuthService, private route: ActivatedRoute, private router: Router, private language: TranslateService, @@ -36,7 +38,13 @@ export class MergeEmailConfirmation extends BaseComponent implements OnInit { this.emailConfirmationService.emailConfirmation(token) .pipe(takeUntil(this._destroyed)) .subscribe( - result => this.onCallbackEmailConfirmationSuccess(), + result => { + const principal = this.authService.current(); + if(!principal || !result || (principal.email == result)) + this.authService.clear(); + this.uiNotificationService.snackBarNotification(this.language.instant('USER-PROFILE.MERGING-SUCCESS'), SnackBarNotificationLevel.Success); + this.onCallbackEmailConfirmationSuccess(); + }, error => this.onCallbackError(error) ) } else { diff --git a/dmp-frontend/src/assets/i18n/de.json b/dmp-frontend/src/assets/i18n/de.json index 392e4bf0a..06d9ed19b 100644 --- a/dmp-frontend/src/assets/i18n/de.json +++ b/dmp-frontend/src/assets/i18n/de.json @@ -1687,13 +1687,14 @@ "LOG-OUT": "Abmeldung" }, "USER-PROFILE": { + "MERGING-SUCCESS": "Linking of the two profiles was successful.", "MERGING-EMAILS-DIALOG": { "TITLE": "Verify linked account", "MESSAGE": "An email to verify this action has been sent to you. Once accepted, you will be able to see your accounts merged. The last email account that you merge will be the one containing all of your DMP records and activity in {{ APP_NAME }}." }, "UNLINK-ACCOUNT": { "TITLE": "Verify account to be unlinked", - "MESSAGE": "An email to verify this action has been sent to you. Once accepted, {{accountToBeUnlinked}} will be unlinked." + "MESSAGE": "An email to verify this action has been sent to your main account. Once accepted, {{accountToBeUnlinked}} will be no longer connected to your current ARGOS profile." }, "UNLINK-ACCOUNT-DIALOG": { "MESSAGE": "By clicking \"Confirm\", you accept the transfer of your ARGOS activity performed from this account to your main ARGOS account, which is the one that is listed first. By logging in again with the unlinked account, you will be able to start your ARGOS experience from scratch, in an empty dashboard.", diff --git a/dmp-frontend/src/assets/i18n/en.json b/dmp-frontend/src/assets/i18n/en.json index a608c8ca0..b23e12d74 100644 --- a/dmp-frontend/src/assets/i18n/en.json +++ b/dmp-frontend/src/assets/i18n/en.json @@ -1687,13 +1687,14 @@ "LOG-OUT": "Log Out" }, "USER-PROFILE": { + "MERGING-SUCCESS": "Linking of the two profiles was successful.", "MERGING-EMAILS-DIALOG": { "TITLE": "Verify linked account", "MESSAGE": "An email to verify this action has been sent to you. Once accepted, you will be able to see your accounts merged. The last email account that you merge will be the one containing all of your DMP records and activity in {{ APP_NAME }}." }, "UNLINK-ACCOUNT": { "TITLE": "Verify account to be unlinked", - "MESSAGE": "An email to verify this action has been sent to you. Once accepted, {{accountToBeUnlinked}} will be no longer connected to your current ARGOS profile." + "MESSAGE": "An email to verify this action has been sent to your main account. Once accepted, {{accountToBeUnlinked}} will be no longer connected to your current ARGOS profile." }, "UNLINK-ACCOUNT-DIALOG": { "MESSAGE": "By clicking \"Confirm\", you accept the transfer of your ARGOS activity performed from this account to your main ARGOS account, which is the one that is listed first. By logging in again with the unlinked account, you will be able to start your ARGOS experience from scratch, in an empty dashboard.", diff --git a/dmp-frontend/src/assets/i18n/es.json b/dmp-frontend/src/assets/i18n/es.json index b970ca792..ac0e52f8d 100644 --- a/dmp-frontend/src/assets/i18n/es.json +++ b/dmp-frontend/src/assets/i18n/es.json @@ -1687,13 +1687,14 @@ "LOG-OUT": "Cerrar la sesión" }, "USER-PROFILE": { + "MERGING-SUCCESS": "Linking of the two profiles was successful.", "MERGING-EMAILS-DIALOG": { "TITLE": "Verify linked account", "MESSAGE": "An email to verify this action has been sent to you. Once accepted, you will be able to see your accounts merged. The last email account that you merge will be the one containing all of your DMP records and activity in {{ APP_NAME }}." }, "UNLINK-ACCOUNT": { "TITLE": "Verify account to be unlinked", - "MESSAGE": "An email to verify this action has been sent to you. Once accepted, {{accountToBeUnlinked}} will be unlinked." + "MESSAGE": "An email to verify this action has been sent to your main account. Once accepted, {{accountToBeUnlinked}} will be no longer connected to your current ARGOS profile." }, "UNLINK-ACCOUNT-DIALOG": { "MESSAGE": "By clicking \"Confirm\", you accept the transfer of your ARGOS activity performed from this account to your main ARGOS account, which is the one that is listed first. By logging in again with the unlinked account, you will be able to start your ARGOS experience from scratch, in an empty dashboard.", diff --git a/dmp-frontend/src/assets/i18n/gr.json b/dmp-frontend/src/assets/i18n/gr.json index e1846708d..3eac2f970 100644 --- a/dmp-frontend/src/assets/i18n/gr.json +++ b/dmp-frontend/src/assets/i18n/gr.json @@ -1687,13 +1687,14 @@ "LOG-OUT": "Αποσύνδεση" }, "USER-PROFILE": { + "MERGING-SUCCESS": "Linking of the two profiles was successful.", "MERGING-EMAILS-DIALOG": { "TITLE": "Verify linked account", "MESSAGE": "An email to verify this action has been sent to you. Once accepted, you will be able to see your accounts merged. The last email account that you merge will be the one containing all of your DMP records and activity in {{ APP_NAME }}." }, "UNLINK-ACCOUNT": { "TITLE": "Verify account to be unlinked", - "MESSAGE": "An email to verify this action has been sent to you. Once accepted, {{accountToBeUnlinked}} will be unlinked." + "MESSAGE": "An email to verify this action has been sent to your main account. Once accepted, {{accountToBeUnlinked}} will be no longer connected to your current ARGOS profile." }, "UNLINK-ACCOUNT-DIALOG": { "MESSAGE": "By clicking \"Confirm\", you accept the transfer of your ARGOS activity performed from this account to your main ARGOS account, which is the one that is listed first. By logging in again with the unlinked account, you will be able to start your ARGOS experience from scratch, in an empty dashboard.", diff --git a/dmp-frontend/src/assets/i18n/hr.json b/dmp-frontend/src/assets/i18n/hr.json index 8328c3b4a..f9833d476 100644 --- a/dmp-frontend/src/assets/i18n/hr.json +++ b/dmp-frontend/src/assets/i18n/hr.json @@ -1687,13 +1687,14 @@ "LOG-OUT": "Odjava" }, "USER-PROFILE": { + "MERGING-SUCCESS": "Linking of the two profiles was successful.", "MERGING-EMAILS-DIALOG": { "TITLE": "Potvrdi povezani korisnički račun", "MESSAGE": "Potvrdu za ovu radnju poslali smo Vam putem elektroničke pošte. Kada potvrdite, korisnički računi biti će povezani. Posljednji račun elektroničke pošte koji povežete biti će onaj koji sadrži sve podatke o Planu upravljanja podacima i aktivnostima u {{ APP_NAME }}u." }, "UNLINK-ACCOUNT": { "TITLE": "Verify account to be unlinked", - "MESSAGE": "An email to verify this action has been sent to you. Once accepted, {{accountToBeUnlinked}} will be unlinked." + "MESSAGE": "An email to verify this action has been sent to your main account. Once accepted, {{accountToBeUnlinked}} will be no longer connected to your current ARGOS profile." }, "UNLINK-ACCOUNT-DIALOG": { "MESSAGE": "By clicking \"Confirm\", you accept the transfer of your ARGOS activity performed from this account to your main ARGOS account, which is the one that is listed first. By logging in again with the unlinked account, you will be able to start your ARGOS experience from scratch, in an empty dashboard.", diff --git a/dmp-frontend/src/assets/i18n/pl.json b/dmp-frontend/src/assets/i18n/pl.json index bf8762b7d..5a29a4c1c 100644 --- a/dmp-frontend/src/assets/i18n/pl.json +++ b/dmp-frontend/src/assets/i18n/pl.json @@ -1687,13 +1687,14 @@ "LOG-OUT": "Wyloguj" }, "USER-PROFILE": { + "MERGING-SUCCESS": "Linking of the two profiles was successful.", "MERGING-EMAILS-DIALOG": { "TITLE": "Zweryfikuj połączone konto", "MESSAGE": "Wysłano wiadomość e-mail w celu weryfikacji tej akcji. Po zaakceptowaniu będzie można zobaczyć połączone konta. Ostatnie połączone konto e-mail będzie tym, które zawiera wszystkie twoje rejestry DMP i aktywność w {{ APP_NAME }}." }, "UNLINK-ACCOUNT": { "TITLE": "Verify account to be unlinked", - "MESSAGE": "An email to verify this action has been sent to you. Once accepted, {{accountToBeUnlinked}} will be unlinked." + "MESSAGE": "An email to verify this action has been sent to your main account. Once accepted, {{accountToBeUnlinked}} will be no longer connected to your current ARGOS profile." }, "UNLINK-ACCOUNT-DIALOG": { "MESSAGE": "By clicking \"Confirm\", you accept the transfer of your ARGOS activity performed from this account to your main ARGOS account, which is the one that is listed first. By logging in again with the unlinked account, you will be able to start your ARGOS experience from scratch, in an empty dashboard.", diff --git a/dmp-frontend/src/assets/i18n/pt.json b/dmp-frontend/src/assets/i18n/pt.json index 2373b0288..86ed84324 100644 --- a/dmp-frontend/src/assets/i18n/pt.json +++ b/dmp-frontend/src/assets/i18n/pt.json @@ -1687,13 +1687,14 @@ "LOG-OUT": "Terminar Sessão" }, "USER-PROFILE": { + "MERGING-SUCCESS": "Linking of the two profiles was successful.", "MERGING-EMAILS-DIALOG": { "TITLE": "Verify linked account", "MESSAGE": "An email to verify this action has been sent to you. Once accepted, you will be able to see your accounts merged. The last email account that you merge will be the one containing all of your DMP records and activity in {{ APP_NAME }}." }, "UNLINK-ACCOUNT": { "TITLE": "Verify account to be unlinked", - "MESSAGE": "An email to verify this action has been sent to you. Once accepted, {{accountToBeUnlinked}} will be unlinked." + "MESSAGE": "An email to verify this action has been sent to your main account. Once accepted, {{accountToBeUnlinked}} will be no longer connected to your current ARGOS profile." }, "UNLINK-ACCOUNT-DIALOG": { "MESSAGE": "By clicking \"Confirm\", you accept the transfer of your ARGOS activity performed from this account to your main ARGOS account, which is the one that is listed first. By logging in again with the unlinked account, you will be able to start your ARGOS experience from scratch, in an empty dashboard.", diff --git a/dmp-frontend/src/assets/i18n/sk.json b/dmp-frontend/src/assets/i18n/sk.json index 0c8415251..00f2823f7 100644 --- a/dmp-frontend/src/assets/i18n/sk.json +++ b/dmp-frontend/src/assets/i18n/sk.json @@ -1687,13 +1687,14 @@ "LOG-OUT": "Odhlásiť sa" }, "USER-PROFILE": { + "MERGING-SUCCESS": "Linking of the two profiles was successful.", "MERGING-EMAILS-DIALOG": { "TITLE": "Verify linked account", "MESSAGE": "An email to verify this action has been sent to you. Once accepted, you will be able to see your accounts merged. The last email account that you merge will be the one containing all of your DMP records and activity in {{ APP_NAME }}." }, "UNLINK-ACCOUNT": { "TITLE": "Verify account to be unlinked", - "MESSAGE": "An email to verify this action has been sent to you. Once accepted, {{accountToBeUnlinked}} will be unlinked." + "MESSAGE": "An email to verify this action has been sent to your main account. Once accepted, {{accountToBeUnlinked}} will be no longer connected to your current ARGOS profile." }, "UNLINK-ACCOUNT-DIALOG": { "MESSAGE": "By clicking \"Confirm\", you accept the transfer of your ARGOS activity performed from this account to your main ARGOS account, which is the one that is listed first. By logging in again with the unlinked account, you will be able to start your ARGOS experience from scratch, in an empty dashboard.", diff --git a/dmp-frontend/src/assets/i18n/sr.json b/dmp-frontend/src/assets/i18n/sr.json index 8904496f7..0dc21c855 100644 --- a/dmp-frontend/src/assets/i18n/sr.json +++ b/dmp-frontend/src/assets/i18n/sr.json @@ -1687,13 +1687,14 @@ "LOG-OUT": "Odjavite se" }, "USER-PROFILE": { + "MERGING-SUCCESS": "Linking of the two profiles was successful.", "MERGING-EMAILS-DIALOG": { "TITLE": "Verify linked account", "MESSAGE": "An email to verify this action has been sent to you. Once accepted, you will be able to see your accounts merged. The last email account that you merge will be the one containing all of your DMP records and activity in {{ APP_NAME }}." }, "UNLINK-ACCOUNT": { "TITLE": "Verify account to be unlinked", - "MESSAGE": "An email to verify this action has been sent to you. Once accepted, {{accountToBeUnlinked}} will be unlinked." + "MESSAGE": "An email to verify this action has been sent to your main account. Once accepted, {{accountToBeUnlinked}} will be no longer connected to your current ARGOS profile." }, "UNLINK-ACCOUNT-DIALOG": { "MESSAGE": "By clicking \"Confirm\", you accept the transfer of your ARGOS activity performed from this account to your main ARGOS account, which is the one that is listed first. By logging in again with the unlinked account, you will be able to start your ARGOS experience from scratch, in an empty dashboard.", diff --git a/dmp-frontend/src/assets/i18n/tr.json b/dmp-frontend/src/assets/i18n/tr.json index 6e360736f..955d887e9 100644 --- a/dmp-frontend/src/assets/i18n/tr.json +++ b/dmp-frontend/src/assets/i18n/tr.json @@ -1687,13 +1687,14 @@ "LOG-OUT": "Çıkış Yap" }, "USER-PROFILE": { + "MERGING-SUCCESS": "Linking of the two profiles was successful.", "MERGING-EMAILS-DIALOG": { "TITLE": "Verify linked account", "MESSAGE": "An email to verify this action has been sent to you. Once accepted, you will be able to see your accounts merged. The last email account that you merge will be the one containing all of your DMP records and activity in {{ APP_NAME }}." }, "UNLINK-ACCOUNT": { "TITLE": "Verify account to be unlinked", - "MESSAGE": "An email to verify this action has been sent to you. Once accepted, {{accountToBeUnlinked}} will be unlinked." + "MESSAGE": "An email to verify this action has been sent to your main account. Once accepted, {{accountToBeUnlinked}} will be no longer connected to your current ARGOS profile." }, "UNLINK-ACCOUNT-DIALOG": { "MESSAGE": "By clicking \"Confirm\", you accept the transfer of your ARGOS activity performed from this account to your main ARGOS account, which is the one that is listed first. By logging in again with the unlinked account, you will be able to start your ARGOS experience from scratch, in an empty dashboard.",