[Library | Trunk]: Make PreviousRouteRecorder singleton. Add verification guard and component
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59261 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
1e8a635c1b
commit
c17f6e5597
|
@ -53,16 +53,13 @@
|
||||||
Please <a class="" (click)="logIn()"> sign in</a> to continue.
|
Please <a class="" (click)="logIn()"> sign in</a> to continue.
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="errorCode == '2'" class="uk-alert uk-alert-warning">
|
<div *ngIf="errorCode == '2' || errorCode == '4' " class="uk-alert uk-alert-warning">
|
||||||
You are not authorized to use the requested page.
|
You are not authorized to use the requested page.
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="errorCode == '3'" class="uk-alert uk-alert-warning">
|
<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=""
|
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>
|
||||||
<div *ngIf="errorCode == '4'" class="uk-alert uk-alert-warning">
|
|
||||||
You are not authorized to use the requested page.
|
|
||||||
</div>
|
|
||||||
<div *ngIf="errorCode == '5'" class="uk-alert uk-alert-warning">
|
<div *ngIf="errorCode == '5'" class="uk-alert uk-alert-warning">
|
||||||
There is no research community selected.
|
There is no research community selected.
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
import {Injectable} from '@angular/core';
|
||||||
|
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from '@angular/router';
|
||||||
|
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 {UserManagementService} from "../services/user-management.service";
|
||||||
|
import {UserRegistryService} from "../services/user-registry.service";
|
||||||
|
import {of} from "rxjs";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class VerificationGuard implements CanActivate {
|
||||||
|
|
||||||
|
constructor(private router: Router,
|
||||||
|
private userRegistryService: UserRegistryService,
|
||||||
|
private userManagementService: UserManagementService) {
|
||||||
|
}
|
||||||
|
|
||||||
|
check(path: string): Observable<boolean> | boolean {
|
||||||
|
if (Session.isLoggedIn()) {
|
||||||
|
const obs = this.userManagementService.getUserInfo(false).pipe(map(user => {
|
||||||
|
if(user) {
|
||||||
|
of(true);
|
||||||
|
} else {
|
||||||
|
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}});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||||
|
console.log(route);
|
||||||
|
return this.check(state.url);
|
||||||
|
}
|
||||||
|
}
|
|
@ -39,6 +39,11 @@ export class UserRegistryService {
|
||||||
return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/subscribers/email').pipe(map(response => response.response));
|
return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/subscribers/email').pipe(map(response => response.response));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getInvitation(id: string): Observable<any> {
|
||||||
|
return this.http.get<any>(properties.registryUrl + "verification/" + encodeURIComponent(id))
|
||||||
|
.pipe(map(response => response.response), CustomOptions.registryOptions());
|
||||||
|
}
|
||||||
|
|
||||||
public getManagersEmail(type: string, id: string): Observable<any[]> {
|
public getManagersEmail(type: string, id: string): Observable<any[]> {
|
||||||
return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/managers/email').pipe(map(response => response.response));
|
return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '/managers/email').pipe(map(response => response.response));
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,9 @@ import { Injectable } from '@angular/core';
|
||||||
import { CanDeactivate, Router} from '@angular/router';
|
import { CanDeactivate, Router} from '@angular/router';
|
||||||
import {Observable} from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
|
|
||||||
@Injectable() // do not forget to register this class as a provider
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
}) // do not forget to register this class as a provider
|
||||||
export class PreviousRouteRecorder implements CanDeactivate<any> {
|
export class PreviousRouteRecorder implements CanDeactivate<any> {
|
||||||
constructor(private router: Router) {
|
constructor(private router: Router) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
import {Component} from "@angular/core";
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'verification',
|
||||||
|
template: ``
|
||||||
|
})
|
||||||
|
export class VerificationComponent {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
import {NgModule} from "@angular/core";
|
||||||
|
import {CommonModule} from "@angular/common";
|
||||||
|
import {VerificationComponent} from "./verification.component";
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [CommonModule],
|
||||||
|
declarations: [VerificationComponent],
|
||||||
|
exports: [VerificationComponent]
|
||||||
|
})
|
||||||
|
export class VerificationModule {}
|
Loading…
Reference in New Issue