2020-10-05 15:15:33 +02:00
|
|
|
import {Component, Input, OnDestroy, OnInit, ViewChild} from "@angular/core";
|
|
|
|
import {User} from "../login/utils/helper.class";
|
|
|
|
import {ActivatedRoute, Router} from "@angular/router";
|
|
|
|
import {UserManagementService} from "../services/user-management.service";
|
|
|
|
import {UserRegistryService} from "../services/user-registry.service";
|
|
|
|
import {LoginErrorCodes} from "../login/utils/guardHelper.class";
|
|
|
|
import {Subscriber} from "rxjs";
|
|
|
|
import {FormBuilder, FormControl, Validators} from "@angular/forms";
|
|
|
|
import {AlertModal} from "../utils/modal/alert";
|
2021-02-19 18:50:34 +01:00
|
|
|
import {properties} from "../../../environments/environment";
|
2021-03-01 17:05:37 +01:00
|
|
|
import {EmailService} from "../utils/email/email.service";
|
|
|
|
import {Composer} from "../utils/email/composer";
|
2020-10-05 15:15:33 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'role-verification',
|
|
|
|
template: `
|
|
|
|
<modal-alert #managerModal>
|
|
|
|
<div>
|
2021-02-19 18:50:34 +01:00
|
|
|
You have been invited to join <span class="uk-text-bold">{{name}}</span> {{(service === 'monitor'?'Monitor':'Research Community')}} Dashboard as a manager.
|
2020-10-05 15:15:33 +02:00
|
|
|
<span class="portal-color">Fill</span> in the <span class="portal-color">verification code</span>, sent to your
|
|
|
|
email, to accept the invitation request.
|
|
|
|
</div>
|
2020-11-12 18:49:20 +01:00
|
|
|
<div *ngIf="!loading" class="uk-margin-medium-top uk-flex uk-flex-center">
|
2021-03-03 19:04:53 +01:00
|
|
|
<div dashboard-input [formInput]="code" class="uk-width-medium" placeholder="Write verification code">
|
|
|
|
<span *ngIf="error" error>{{error}}</span>
|
2020-11-12 18:49:20 +01:00
|
|
|
</div>
|
2020-10-05 15:15:33 +02:00
|
|
|
</div>
|
2021-02-19 18:50:34 +01:00
|
|
|
<div *ngIf="loading" class="uk-margin-medium-top uk-flex uk-flex-center">
|
2020-10-05 15:15:33 +02:00
|
|
|
<loading></loading>
|
|
|
|
</div>
|
|
|
|
<div class="uk-margin-medium-top uk-flex uk-flex-right">
|
|
|
|
<button class="uk-button uk-button-default uk-margin-medium-right" [class.uk-disabled]="loading"
|
|
|
|
(click)="cancel(managerModal)">Cancel
|
|
|
|
</button>
|
|
|
|
<button class="uk-button" [class.portal-button]="code.valid" [class.uk-disabled]="code.invalid || loading"
|
|
|
|
(click)="verifyManager()">Accept
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</modal-alert>
|
2021-02-19 18:50:34 +01:00
|
|
|
<modal-alert *ngIf="service !== 'connect'" #memberModal>
|
2020-10-05 15:15:33 +02:00
|
|
|
<div *ngIf="!isMember">
|
|
|
|
<div>
|
2020-11-13 13:51:35 +01:00
|
|
|
You have been invited to join <span class="uk-text-bold">{{name}}</span> Monitor Dashboard as a member.
|
2020-10-05 15:15:33 +02:00
|
|
|
<span class="portal-color">Fill</span> in the <span class="portal-color">verification code</span>, sent to
|
|
|
|
your
|
|
|
|
email, to accept the invitation request.
|
|
|
|
</div>
|
2020-11-12 18:49:20 +01:00
|
|
|
<div *ngIf="!loading" class="uk-margin-medium-top uk-flex uk-flex-wrap uk-flex-center">
|
2021-03-03 19:04:53 +01:00
|
|
|
<div dashboard-input [formInput]="code" class="uk-width-medium" placeholder="Write verification code">
|
|
|
|
<span *ngIf="error" error>{{error}}</span>>
|
2020-11-12 18:49:20 +01:00
|
|
|
</div>
|
2020-10-05 15:15:33 +02:00
|
|
|
</div>
|
|
|
|
<div *ngIf="loading" class="uk-margin-medium-top">
|
|
|
|
<loading></loading>
|
|
|
|
</div>
|
|
|
|
<div class="uk-margin-medium-top uk-flex uk-flex-right">
|
|
|
|
<button class="uk-button uk-button-default uk-margin-medium-right" [class.uk-disabled]="loading"
|
|
|
|
(click)="cancel(memberModal)">Cancel
|
|
|
|
</button>
|
|
|
|
<button class="uk-button" [class.portal-button]="code.valid" [class.uk-disabled]="code.invalid || loading"
|
|
|
|
(click)="verifyMember()">Accept
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div *ngIf="isMember">
|
|
|
|
<div>
|
2020-12-22 16:42:43 +01:00
|
|
|
Welcome! You are now a member of the OpenAIRE Monitor Dashboard for the <span class="uk-text-bold">{{name}}</span>!
|
2020-10-05 15:15:33 +02:00
|
|
|
From now on, you will have access to our restricted content.
|
|
|
|
</div>
|
|
|
|
<div class="uk-margin-medium-top uk-flex uk-flex-right">
|
|
|
|
<button class="uk-button uk-button-default" [class.uk-disabled]="loading"
|
|
|
|
(click)="cancel(memberModal)">Close
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</modal-alert>
|
|
|
|
<modal-alert #errorModal (alertOutput)="cancel(errorModal)">
|
|
|
|
<div>
|
|
|
|
We are unable to process the request because the link is invalid, or it has expired.
|
|
|
|
</div>
|
|
|
|
</modal-alert>
|
|
|
|
`
|
|
|
|
})
|
|
|
|
export class RoleVerificationComponent implements OnInit, OnDestroy {
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
public id: string;
|
|
|
|
@Input()
|
|
|
|
public type: string;
|
|
|
|
@Input()
|
|
|
|
public name: string;
|
2021-02-19 18:50:34 +01:00
|
|
|
@Input()
|
|
|
|
public service: "connect" | "monitor" = "monitor";
|
2020-10-05 15:15:33 +02:00
|
|
|
public user: User;
|
|
|
|
public verification: any;
|
|
|
|
public code: FormControl;
|
|
|
|
private subs: any[] = [];
|
|
|
|
@ViewChild('managerModal') managerModal: AlertModal;
|
|
|
|
@ViewChild('memberModal') memberModal: AlertModal;
|
|
|
|
@ViewChild('errorModal') errorModal: AlertModal;
|
|
|
|
public error: string = null;
|
|
|
|
public loading: boolean = false;
|
|
|
|
public isMember: boolean = false;
|
|
|
|
|
|
|
|
constructor(private route: ActivatedRoute,
|
|
|
|
private router: Router,
|
|
|
|
private fb: FormBuilder,
|
2021-03-01 17:05:37 +01:00
|
|
|
private emailService: EmailService,
|
2020-10-05 15:15:33 +02:00
|
|
|
private userManagementService: UserManagementService,
|
|
|
|
private userRegistryService: UserRegistryService) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.reset();
|
|
|
|
this.subs.push(this.route.queryParams.subscribe(params => {
|
|
|
|
if (params && params['verify']) {
|
|
|
|
this.subs.push(this.userManagementService.getUserInfo(false).subscribe(user => {
|
|
|
|
this.user = user;
|
|
|
|
if (this.user) {
|
|
|
|
this.subs.push(this.userRegistryService.getInvitation(params['verify']).subscribe(verification => {
|
|
|
|
this.verification = verification;
|
2021-03-04 12:58:44 +01:00
|
|
|
if (this.user.email === this.verification.email.toLowerCase() && this.id === this.verification.entity && this.type === this.verification.type) {
|
2020-10-05 15:15:33 +02:00
|
|
|
if (this.verification.verificationType === 'manager') {
|
|
|
|
this.openManagerModal();
|
2021-02-19 18:50:34 +01:00
|
|
|
} else if (this.verification.verificationType === 'member' && this.service === "monitor") {
|
2020-10-05 15:15:33 +02:00
|
|
|
this.openMemberModal();
|
2021-02-19 18:50:34 +01:00
|
|
|
} else {
|
|
|
|
this.openErrorModal();
|
2020-10-05 15:15:33 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.openErrorModal();
|
|
|
|
}
|
|
|
|
}, error => {
|
|
|
|
this.openErrorModal();
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
this.router.navigate(['/user-info'], {
|
|
|
|
queryParams: {
|
|
|
|
'errorCode': LoginErrorCodes.NOT_LOGIN,
|
|
|
|
'redirectUrl': this.router.url
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.subs.forEach(value => {
|
|
|
|
if (value instanceof Subscriber) {
|
|
|
|
value.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public openManagerModal() {
|
|
|
|
this.error = null;
|
|
|
|
this.managerModal.okButton = false;
|
|
|
|
this.managerModal.cancelButton = false;
|
|
|
|
this.managerModal.alertTitle = 'Manager Invitation';
|
|
|
|
this.managerModal.open();
|
|
|
|
}
|
|
|
|
|
|
|
|
public openMemberModal() {
|
|
|
|
this.error = null;
|
|
|
|
this.memberModal.okButton = false;
|
|
|
|
this.memberModal.cancelButton = false;
|
|
|
|
this.memberModal.alertTitle = 'Member Invitation';
|
|
|
|
this.memberModal.open();
|
|
|
|
}
|
|
|
|
|
|
|
|
public openErrorModal() {
|
|
|
|
this.error = null;
|
|
|
|
this.errorModal.cancelButton = false;
|
|
|
|
this.errorModal.okButtonText = 'Ok';
|
2020-11-12 18:49:20 +01:00
|
|
|
this.errorModal.alertTitle = 'Invalid request';
|
2020-10-05 15:15:33 +02:00
|
|
|
this.errorModal.open();
|
|
|
|
}
|
|
|
|
|
|
|
|
public verifyManager() {
|
|
|
|
this.loading = true;
|
2020-11-11 15:43:13 +01:00
|
|
|
this.subs.push(this.userRegistryService.verify(this.verification.id, this.code.value).subscribe(() => {
|
2020-10-05 15:15:33 +02:00
|
|
|
this.managerModal.cancel();
|
|
|
|
this.error = null;
|
2020-12-23 17:06:31 +01:00
|
|
|
this.userManagementService.updateUserInfo(() => {
|
2021-02-19 18:50:34 +01:00
|
|
|
if(this.service === "monitor") {
|
2021-03-01 17:05:37 +01:00
|
|
|
this.loading = false;
|
2021-02-19 18:50:34 +01:00
|
|
|
this.router.navigate(['/admin/' + this.verification.entity]);
|
|
|
|
} else {
|
2021-03-01 17:05:37 +01:00
|
|
|
this.subs.push(this.emailService.notifyManagers(this.id, 'manager',
|
|
|
|
Composer.composeEmailToInformOldManagersForTheNewOnes(this.name, this.id)).subscribe(() => {
|
|
|
|
this.subs.push(this.emailService.notifyNewManager(Composer.composeEmailForNewManager(this.id, this.name)).subscribe(
|
|
|
|
() => {
|
|
|
|
this.loading = false;
|
|
|
|
window.location.href = properties.adminPortalURL + '/' + this.verification.entity;
|
|
|
|
},
|
|
|
|
error1 => {
|
|
|
|
console.error(error1);
|
|
|
|
this.loading = false;
|
|
|
|
window.location.href = properties.adminPortalURL + '/' + this.verification.entity;
|
|
|
|
}
|
|
|
|
));
|
|
|
|
}, error => {
|
|
|
|
console.error(error);
|
|
|
|
this.loading = false;
|
|
|
|
window.location.href = properties.adminPortalURL + '/' + this.verification.entity;
|
|
|
|
}));
|
2021-02-19 18:50:34 +01:00
|
|
|
}
|
2020-12-23 17:06:31 +01:00
|
|
|
});
|
2020-10-05 15:15:33 +02:00
|
|
|
}, error => {
|
|
|
|
this.loading = false;
|
|
|
|
this.error = 'The verification code is invalid';
|
2020-11-11 15:43:13 +01:00
|
|
|
}));
|
2020-10-05 15:15:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public verifyMember() {
|
|
|
|
this.loading = true;
|
2020-11-11 15:43:13 +01:00
|
|
|
this.subs.push(this.userRegistryService.verify(this.verification.id, this.code.value, "member").subscribe(() => {
|
2020-10-05 15:15:33 +02:00
|
|
|
this.loading = false;
|
|
|
|
this.error = null;
|
2020-12-23 17:06:31 +01:00
|
|
|
this.userManagementService.updateUserInfo(() => {
|
2020-11-12 18:49:20 +01:00
|
|
|
this.isMember = true;
|
2020-12-23 17:06:31 +01:00
|
|
|
});
|
2020-10-05 15:15:33 +02:00
|
|
|
}, error => {
|
|
|
|
this.loading = false;
|
|
|
|
this.error = 'The verification code is invalid';
|
2020-11-11 15:43:13 +01:00
|
|
|
}));
|
2020-10-05 15:15:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public reset() {
|
|
|
|
this.code = this.fb.control('', [Validators.required, Validators.pattern('^[+0-9]{6}$')]);
|
|
|
|
}
|
|
|
|
|
|
|
|
cancel(modal: AlertModal) {
|
|
|
|
modal.cancel();
|
|
|
|
this.router.navigate([this.router.url.split('?')[0]]);
|
|
|
|
}
|
|
|
|
}
|