1 |
57064
|
k.triantaf
|
import {Component, Input} from '@angular/core';
|
2 |
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
3 |
|
|
import {Title, Meta} from '@angular/platform-browser';
|
4 |
50169
|
argiro.kok
|
|
5 |
57064
|
k.triantaf
|
import {User, Session} from './utils/helper.class';
|
6 |
|
|
import {RouterHelper} from '../utils/routerHelper.class';
|
7 |
51835
|
sofia.balt
|
|
8 |
57064
|
k.triantaf
|
import {EnvProperties} from '../utils/properties/env-properties';
|
9 |
57058
|
k.triantaf
|
import {UserManagementService} from "../services/user-management.service";
|
10 |
51835
|
sofia.balt
|
|
11 |
50169
|
argiro.kok
|
@Component({
|
12 |
57064
|
k.triantaf
|
selector: 'user',
|
13 |
|
|
templateUrl: 'user.component.html'
|
14 |
|
|
})
|
15 |
50169
|
argiro.kok
|
|
16 |
|
|
export class UserComponent {
|
17 |
57064
|
k.triantaf
|
public user: User;
|
18 |
|
|
public loggedIn: boolean = false;
|
19 |
|
|
public server: boolean = true;
|
20 |
|
|
public errorMessage: string = "";
|
21 |
|
|
public password: string = "";
|
22 |
|
|
private sub: any;
|
23 |
|
|
private sublogin: any;
|
24 |
|
|
public errorCode: string = "";
|
25 |
|
|
public redirectUrl: string = "";
|
26 |
|
|
public routerHelper: RouterHelper = new RouterHelper();
|
27 |
|
|
public loginUrl;
|
28 |
|
|
properties: EnvProperties;
|
29 |
|
|
@Input() mainComponent = true;
|
30 |
50169
|
argiro.kok
|
|
31 |
57064
|
k.triantaf
|
constructor(private router: Router,
|
32 |
|
|
private route: ActivatedRoute,
|
33 |
|
|
private _meta: Meta,
|
34 |
|
|
private _title: Title,
|
35 |
|
|
private userManagementsService: UserManagementService) {
|
36 |
51835
|
sofia.balt
|
|
37 |
57064
|
k.triantaf
|
var title = "OpenAIRE | Login";
|
38 |
|
|
this._title.setTitle(title);
|
39 |
|
|
}
|
40 |
50169
|
argiro.kok
|
|
41 |
57064
|
k.triantaf
|
ngOnInit() {
|
42 |
|
|
this.route.data
|
43 |
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
44 |
|
|
this.properties = data.envSpecific;
|
45 |
|
|
this.loginUrl = this.properties.loginUrl;
|
46 |
50586
|
argiro.kok
|
|
47 |
57058
|
k.triantaf
|
});
|
48 |
57064
|
k.triantaf
|
if (typeof document !== 'undefined') {
|
49 |
|
|
this.server = false;
|
50 |
|
|
}
|
51 |
|
|
this.userManagementsService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
|
52 |
|
|
this.user = user;
|
53 |
|
|
this.loggedIn = !!this.user;
|
54 |
50169
|
argiro.kok
|
this.errorMessage = "";
|
55 |
57064
|
k.triantaf
|
this.sub = this.route.queryParams.subscribe(params => {
|
56 |
50169
|
argiro.kok
|
this.errorCode = params["errorCode"];
|
57 |
|
|
this.redirectUrl = params["redirectUrl"];
|
58 |
|
|
this.errorMessage = "";
|
59 |
57064
|
k.triantaf
|
if (this.loggedIn && this.errorCode == '1') {
|
60 |
50169
|
argiro.kok
|
this.redirect();
|
61 |
|
|
}
|
62 |
|
|
});
|
63 |
57064
|
k.triantaf
|
});
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
ngOnDestroy() {
|
67 |
|
|
this.sub.unsubscribe();
|
68 |
|
|
if (this.sublogin) {
|
69 |
|
|
this.sublogin.unsubscribe();
|
70 |
50169
|
argiro.kok
|
}
|
71 |
57064
|
k.triantaf
|
}
|
72 |
|
|
|
73 |
|
|
redirect() {
|
74 |
|
|
if (this.redirectUrl && this.redirectUrl != "") {
|
75 |
|
|
this.redirectUrl = decodeURIComponent(this.redirectUrl);
|
76 |
|
|
var baseUrl = this.redirectUrl;
|
77 |
|
|
var queryParams = "";
|
78 |
|
|
var paramsArray = [];
|
79 |
|
|
var valuesArray = [];
|
80 |
|
|
if (this.redirectUrl.indexOf('?') != -1) {
|
81 |
|
|
baseUrl = this.redirectUrl.split('?')[0];
|
82 |
|
|
queryParams = this.redirectUrl.split('?')[1];
|
83 |
50169
|
argiro.kok
|
}
|
84 |
57064
|
k.triantaf
|
if (queryParams != "") {
|
85 |
|
|
var queryParamsArray = queryParams.split('&');
|
86 |
|
|
for (var i = 0; i < queryParamsArray.length; i++) {
|
87 |
|
|
paramsArray.push(queryParamsArray[i].split("=")[0]);
|
88 |
|
|
valuesArray.push(queryParamsArray[i].split("=")[1]);
|
89 |
|
|
}
|
90 |
|
|
this.router.navigate([baseUrl], {queryParams: this.routerHelper.createQueryParams(paramsArray, valuesArray)});
|
91 |
|
|
} else {
|
92 |
|
|
this.router.navigate([baseUrl]);
|
93 |
|
|
}
|
94 |
50169
|
argiro.kok
|
}
|
95 |
57064
|
k.triantaf
|
// else{
|
96 |
|
|
// this.router.navigate(['/']);
|
97 |
|
|
// }
|
98 |
|
|
}
|
99 |
54903
|
k.triantaf
|
|
100 |
57064
|
k.triantaf
|
logIn() {
|
101 |
|
|
if (this.redirectUrl && this.redirectUrl != "") {
|
102 |
|
|
this.redirectUrl = decodeURIComponent(this.redirectUrl);
|
103 |
|
|
var baseUrl = this.redirectUrl;
|
104 |
|
|
var queryParams = "";
|
105 |
|
|
if (this.redirectUrl.indexOf('?') != -1) {
|
106 |
|
|
var splits = this.redirectUrl.split('?');
|
107 |
|
|
if (splits.length > 0) {
|
108 |
|
|
baseUrl = splits[0];
|
109 |
50169
|
argiro.kok
|
}
|
110 |
57064
|
k.triantaf
|
if (splits.length > 1) {
|
111 |
|
|
queryParams = splits[1];
|
112 |
50169
|
argiro.kok
|
}
|
113 |
|
|
}
|
114 |
57064
|
k.triantaf
|
Session.setReloadUrl(location.protocol + "//" + location.host, baseUrl, queryParams);
|
115 |
50169
|
argiro.kok
|
}
|
116 |
54903
|
k.triantaf
|
|
117 |
57064
|
k.triantaf
|
window.location.href = this.properties.loginUrl;
|
118 |
|
|
}
|
119 |
50169
|
argiro.kok
|
|
120 |
57064
|
k.triantaf
|
getTheRolesFormatted(roles: string[]) {
|
121 |
|
|
let formattedRoles = [];
|
122 |
|
|
for (let role of roles) {
|
123 |
|
|
let formattedRole = role.split("urn:geant:openaire.eu:group:")[1];
|
124 |
|
|
formattedRole = formattedRole.split("#aai.openaire.eu")[0]
|
125 |
|
|
formattedRole = formattedRole.replace("+", " ");
|
126 |
|
|
formattedRole = formattedRole.split("+").join(" ");
|
127 |
|
|
formattedRoles.push(formattedRole);
|
128 |
50169
|
argiro.kok
|
}
|
129 |
57064
|
k.triantaf
|
return formattedRoles.join(", ");
|
130 |
|
|
}
|
131 |
50169
|
argiro.kok
|
|
132 |
57064
|
k.triantaf
|
isUserManager() {
|
133 |
|
|
return Session.isUserManager(this.user);
|
134 |
|
|
}
|
135 |
|
|
|
136 |
50169
|
argiro.kok
|
}
|