[Library | Trunk]: Add verification component
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59271 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
e8a40e5e37
commit
1dae58490f
|
@ -21,7 +21,8 @@
|
|||
<a *ngIf="user && isUserManager()" class="uk-button uk-button-primary"
|
||||
href="https://aai.openaire.eu/roles/admin.php"
|
||||
target="_blank">Manage role requests</a>{{" "}}
|
||||
<a *ngIf="user && isUserManager()" class="uk-button uk-button-primary" href="https://aai.openaire.eu/registry"
|
||||
<a *ngIf="user && isUserManager()" class="uk-button uk-button-primary"
|
||||
href="https://aai.openaire.eu/registry"
|
||||
target="_blank">Manage users</a>
|
||||
</div>
|
||||
|
||||
|
@ -53,12 +54,13 @@
|
|||
Please <a class="" (click)="logIn()"> sign in</a> to continue.
|
||||
</span>
|
||||
</div>
|
||||
<div *ngIf="errorCode == '2' || errorCode == '4' " class="uk-alert uk-alert-warning">
|
||||
<div *ngIf="errorCode == '2' || errorCode == '4' || errorCode == '8'" class="uk-alert uk-alert-warning">
|
||||
You are not authorized to use the requested page.
|
||||
</div>
|
||||
<div *ngIf="errorCode == '3'" class="uk-alert uk-alert-warning">
|
||||
The session has expired. Please <a class="" (click)="logIn()">sign in</a> again or continue <a class=""
|
||||
(click)="redirect();">browsing as a guest</a>.
|
||||
(click)="redirect();">browsing
|
||||
as a guest</a>.
|
||||
</div>
|
||||
<div *ngIf="errorCode == '5'" class="uk-alert uk-alert-warning">
|
||||
There is no research community selected.
|
||||
|
|
|
@ -116,7 +116,7 @@ export class UserComponent {
|
|||
}
|
||||
Session.setReloadUrl(location.protocol + "//" + location.host, baseUrl, queryParams);
|
||||
}
|
||||
|
||||
console.log(Session.getReloadUrl());
|
||||
window.location.href = this.properties.loginUrl;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,4 +6,5 @@ export class LoginErrorCodes {
|
|||
public static NO_COMMUNITY = 5;
|
||||
public static NOT_SUBSCRIBER = 6;
|
||||
public static ACTION_REQUIRES_LOGIN = 7;
|
||||
public static NOT_AUTHORIZED = 8;
|
||||
}
|
||||
|
|
|
@ -3,10 +3,12 @@ import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from '
|
|||
import {Observable} from 'rxjs/Observable';
|
||||
import {Session} from './utils/helper.class';
|
||||
import {LoginErrorCodes} from './utils/guardHelper.class';
|
||||
import {filter, map, mergeMap} from "rxjs/operators";
|
||||
import {catchError, filter, map, mergeMap} from "rxjs/operators";
|
||||
import {UserManagementService} from "../services/user-management.service";
|
||||
import {UserRegistryService} from "../services/user-registry.service";
|
||||
import {of} from "rxjs";
|
||||
import {properties} from "../../../environments/environment";
|
||||
import {ConnectHelper} from "../connect/connectHelper";
|
||||
|
||||
@Injectable()
|
||||
export class VerificationGuard implements CanActivate {
|
||||
|
@ -16,29 +18,50 @@ export class VerificationGuard implements CanActivate {
|
|||
private userManagementService: UserManagementService) {
|
||||
}
|
||||
|
||||
check(path: string): Observable<boolean> | boolean {
|
||||
check(path: string, id: string, type: string, entity: string): Observable<boolean> | boolean {
|
||||
if (Session.isLoggedIn()) {
|
||||
const obs = this.userManagementService.getUserInfo(false).pipe(map(user => {
|
||||
return this.userManagementService.getUserInfo(false).pipe(map(user => {
|
||||
if(user) {
|
||||
of(true);
|
||||
if(id) {
|
||||
return this.userRegistryService.getInvitation(id).pipe(map(invitation => {
|
||||
if(invitation.type !== type || invitation.entity !== entity) {
|
||||
this.router.navigate(['/error'], {queryParams: {'page': path}});
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}), catchError(error => {
|
||||
if(error.status === 404) {
|
||||
this.router.navigate(['/error'], {queryParams: {'page': path}});
|
||||
} else {
|
||||
this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_AUTHORIZED, 'redirectUrl': path}});
|
||||
}
|
||||
return of(false);
|
||||
}));
|
||||
} else {
|
||||
this.router.navigate(['/error'], {queryParams: {'page': path}});
|
||||
return of(false);
|
||||
}
|
||||
} else {
|
||||
this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_LOGIN, 'redirectUrl': path}});
|
||||
return of(false);
|
||||
}
|
||||
}), mergeMap(authorized => {
|
||||
return authorized;
|
||||
}));
|
||||
obs.pipe(filter(isLoggedIn => !isLoggedIn)).subscribe(() => {
|
||||
this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_LOGIN, path}});
|
||||
});
|
||||
return obs;
|
||||
} else {
|
||||
this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_LOGIN, path}});
|
||||
this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_LOGIN,'redirectUrl': path}});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
console.log(route);
|
||||
return this.check(state.url);
|
||||
if(properties.dashboard === "connect" && properties.environment === 'development') {
|
||||
let communityId = ConnectHelper.getCommunityFromDomain(properties.domain);
|
||||
communityId = (communityId)?communityId:route.queryParams['communityId'];
|
||||
return this.check(state.url, route.params.id, 'community', communityId);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from "rxjs";
|
||||
import {Observable, of} from "rxjs";
|
||||
import {properties} from "../../../environments/environment";
|
||||
import {CustomOptions} from "./servicesUtils/customOptions.class";
|
||||
import {map} from "rxjs/operators";
|
||||
import {catchError, map} from "rxjs/operators";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
@ -40,8 +40,16 @@ export class UserRegistryService {
|
|||
}
|
||||
|
||||
public getInvitation(id: string): Observable<any> {
|
||||
return this.http.get<any>(properties.registryUrl + "verification/" + encodeURIComponent(id))
|
||||
.pipe(map(response => response.response), CustomOptions.registryOptions());
|
||||
return this.http.get<any>(properties.registryUrl + "verification/" + encodeURIComponent(id), CustomOptions.registryOptions())
|
||||
.pipe(map((response: any) => response.response));
|
||||
}
|
||||
|
||||
public verify(id: string, code: string): Observable<any> {
|
||||
return this.http.post<any>(properties.registryUrl + "verification/" + encodeURIComponent(id), code,CustomOptions.registryOptions());
|
||||
}
|
||||
|
||||
public deleteVerification(id: string): Observable<any> {
|
||||
return this.http.delete<any>(properties.registryUrl + "verification/" + encodeURIComponent(id), CustomOptions.registryOptions());
|
||||
}
|
||||
|
||||
public getManagersEmail(type: string, id: string): Observable<any[]> {
|
||||
|
|
|
@ -1,9 +1,71 @@
|
|||
import {Component} from "@angular/core";
|
||||
import {Component, Input, OnInit} from "@angular/core";
|
||||
import {FormBuilder, FormControl, Validators} from "@angular/forms";
|
||||
import {UserRegistryService} from "../services/user-registry.service";
|
||||
|
||||
@Component({
|
||||
selector: 'verification',
|
||||
template: ``
|
||||
template: `
|
||||
<div *ngIf="loading" class="loading-gif"></div>
|
||||
<div *ngIf="name && !loading" class="uk-text-center uk-text-large">
|
||||
<ng-container *ngIf="state === 'default'">
|
||||
<div>
|
||||
You have been invited to join <span class="uk-text-bold">{{name}}</span> as Manager;<br>
|
||||
Fill in the verification code, sent to your email, to accept the invitation request.
|
||||
</div>
|
||||
<div class="uk-margin-medium-top">
|
||||
<input [formControl]="code" class="uk-input uk-width-small" [class.uk-form-danger]="code.invalid">
|
||||
</div>
|
||||
<div class="uk-margin-medium-top">
|
||||
<button class="uk-button" [class.portal-button]="code.valid" [class.uk-disabled]="code.invalid"
|
||||
(click)="verify()">Accept
|
||||
</button>
|
||||
<button class="uk-button uk-button-danger uk-margin-medium-left" (click)="reject()">Reject</button>
|
||||
</div>
|
||||
</ng-container>
|
||||
<ng-container *ngIf="state === 'verified'">
|
||||
<div>
|
||||
You are now manager of {{name}}.
|
||||
</div>
|
||||
</ng-container>
|
||||
<ng-container *ngIf="state === 'refused'">
|
||||
<div>
|
||||
You have been refused to be manager of {{name}}.
|
||||
</div>
|
||||
</ng-container>
|
||||
</div>
|
||||
`
|
||||
})
|
||||
export class VerificationComponent {
|
||||
|
||||
export class VerificationComponent implements OnInit {
|
||||
|
||||
@Input()
|
||||
public name: string;
|
||||
@Input()
|
||||
public invitation;
|
||||
public code: FormControl;
|
||||
public loading = false;
|
||||
public state: 'default' | 'verified' | 'refused' | 'error' = 'default';
|
||||
|
||||
constructor(private fb: FormBuilder,
|
||||
private userRegistryService: UserRegistryService) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.code = this.fb.control('', [Validators.required, Validators.pattern('^[+0-9]{6}$')]);
|
||||
}
|
||||
|
||||
verify() {
|
||||
this.loading = true;
|
||||
this.userRegistryService.verify(this.invitation.id, this.code.value).subscribe(() => {
|
||||
this.state = 'verified';
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
reject() {
|
||||
this.loading = true;
|
||||
this.userRegistryService.deleteVerification(this.invitation.id).subscribe(() => {
|
||||
this.state = 'refused';
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import {NgModule} from "@angular/core";
|
||||
import {CommonModule} from "@angular/common";
|
||||
import {VerificationComponent} from "./verification.component";
|
||||
import {ReactiveFormsModule} from "@angular/forms";
|
||||
|
||||
@NgModule({
|
||||
imports: [CommonModule],
|
||||
imports: [CommonModule, ReactiveFormsModule],
|
||||
declarations: [VerificationComponent],
|
||||
exports: [VerificationComponent]
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue