diff --git a/backend/core/src/main/java/org/opencdmp/service/user/UserServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/user/UserServiceImpl.java index 839310d47..c863e0409 100644 --- a/backend/core/src/main/java/org/opencdmp/service/user/UserServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/user/UserServiceImpl.java @@ -1058,6 +1058,10 @@ public class UserServiceImpl implements UserService { if (userInviteToTenantRequest == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{action.getId(), UserInviteToTenantRequestEntity.class.getSimpleName()}, LocaleContextHolder.getLocale())); + UserContactInfoEntity contactInfoEntity = this.queryFactory.query(UserContactInfoQuery.class).disableTracking().userIds(this.userScope.getUserId()).values(userInviteToTenantRequest.getEmail()).types(ContactInfoType.Email).first(); + if (contactInfoEntity == null){ + throw new MyValidationException(this.errors.getAnotherUserToken().getCode(), this.errors.getAnotherUserToken().getMessage()); + } TenantEntity tenantEntity = null; if (!userInviteToTenantRequest.getTenantCode().equals(this.tenantScope.getTenantCode())) { tenantEntity = this.queryFactory.query(TenantQuery.class).disableTracking().authorize(AuthorizationFlags.AllExceptPublic).codes(userInviteToTenantRequest.getTenantCode()).isActive(IsActive.Active).first(); diff --git a/frontend/src/app/ui/auth/login/user-invite-confirmation/user-invite-confirmation.component.ts b/frontend/src/app/ui/auth/login/user-invite-confirmation/user-invite-confirmation.component.ts index a57f65932..5c9236928 100644 --- a/frontend/src/app/ui/auth/login/user-invite-confirmation/user-invite-confirmation.component.ts +++ b/frontend/src/app/ui/auth/login/user-invite-confirmation/user-invite-confirmation.component.ts @@ -1,6 +1,7 @@ import { HttpErrorResponse } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; +import { AuthService } from '@app/core/services/auth/auth.service'; import { SnackBarNotificationLevel } from '@app/core/services/notification/ui-notification-service'; import { RouterUtilsService } from '@app/core/services/router/router-utils.service'; import { UserService } from '@app/core/services/user/user.service'; @@ -28,6 +29,7 @@ export class UserInviteConfirmation extends BaseComponent implements OnInit { private router: Router, private language: TranslateService, private routerUtils: RouterUtilsService, + private authentication: AuthService, private httpErrorHandlingService: HttpErrorHandlingService ) { super(); } @@ -46,13 +48,23 @@ export class UserInviteConfirmation extends BaseComponent implements OnInit { onConfirm(): void { if (this.showForm === false) return; - this.userService.confirmInviteUser(this.token) + if(this.isAuthenticated()){ + this.userService.confirmInviteUser(this.token) .subscribe(result => { if (result) { this.onCallbackConfirmationSuccess(); } }, - error => this.onCallbackError(error)); + error => this.onCallbackError(error)); + } else { + let returnUrl = `login/invitation/confirmation/${this.token}`; + this.router.navigate([this.routerUtils.generateUrl('login')], {queryParams:{returnUrl: this.routerUtils.generateUrl(returnUrl)}}); + } + + } + + public isAuthenticated(): boolean { + return this.authentication.currentAccountIsAuthenticated(); } onCallbackConfirmationSuccess() {