2019-10-22 12:29:31 +02:00
|
|
|
import {Component, Input} from '@angular/core';
|
2019-09-13 10:26:09 +02:00
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
2019-10-22 12:29:31 +02:00
|
|
|
import {Title, Meta} from '@angular/platform-browser';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-10-22 12:29:31 +02:00
|
|
|
import {User, Session} from './utils/helper.class';
|
2019-09-13 10:26:09 +02:00
|
|
|
import {RouterHelper} from '../utils/routerHelper.class';
|
Replace meta service import and use with meta and title from angular/platform-browser for user, publication, claimAdmin,claimsByToken, directLinking, linkingGeneric, myClaims, depositBySubject, depositBySubjectResult, deposit, depositResult, dataProvider, htmlProjectReport, organization, project, software, search, advancedSearchPage, searchPage and searchPageTableView component
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@51835 d315682c-612b-4755-9ff5-7f18f6832af3
2018-04-17 15:00:23 +02:00
|
|
|
|
2019-09-13 10:26:09 +02:00
|
|
|
import {EnvProperties} from '../utils/properties/env-properties';
|
2019-09-13 09:01:19 +02:00
|
|
|
import {UserManagementService} from "../services/user-management.service";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Component({
|
2019-09-13 10:26:09 +02:00
|
|
|
selector: 'user',
|
|
|
|
templateUrl: 'user.component.html'
|
|
|
|
})
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
export class UserComponent {
|
2019-09-13 10:26:09 +02:00
|
|
|
public user: User;
|
|
|
|
public loggedIn: boolean = false;
|
|
|
|
public server: boolean = true;
|
|
|
|
public errorMessage: string = "";
|
|
|
|
public password: string = "";
|
|
|
|
private sub: any;
|
|
|
|
private sublogin: any;
|
|
|
|
public errorCode: string = "";
|
|
|
|
public redirectUrl: string = "";
|
|
|
|
public routerHelper: RouterHelper = new RouterHelper();
|
|
|
|
public loginUrl;
|
|
|
|
properties: EnvProperties;
|
|
|
|
@Input() mainComponent = true;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-09-13 10:26:09 +02:00
|
|
|
constructor(private router: Router,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private _meta: Meta,
|
|
|
|
private _title: Title,
|
2019-10-22 12:29:31 +02:00
|
|
|
private userManagementsService: UserManagementService) {
|
Replace meta service import and use with meta and title from angular/platform-browser for user, publication, claimAdmin,claimsByToken, directLinking, linkingGeneric, myClaims, depositBySubject, depositBySubjectResult, deposit, depositResult, dataProvider, htmlProjectReport, organization, project, software, search, advancedSearchPage, searchPage and searchPageTableView component
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@51835 d315682c-612b-4755-9ff5-7f18f6832af3
2018-04-17 15:00:23 +02:00
|
|
|
|
2019-09-13 10:26:09 +02:00
|
|
|
var title = "OpenAIRE | Login";
|
|
|
|
this._title.setTitle(title);
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-09-13 10:26:09 +02:00
|
|
|
ngOnInit() {
|
|
|
|
this.route.data
|
|
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
this.properties = data.envSpecific;
|
|
|
|
this.loginUrl = this.properties.loginUrl;
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2019-09-13 09:01:19 +02:00
|
|
|
});
|
2019-09-13 10:26:09 +02:00
|
|
|
if (typeof document !== 'undefined') {
|
|
|
|
this.server = false;
|
2019-11-08 12:01:50 +01:00
|
|
|
this.userManagementsService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
|
|
|
|
this.user = user;
|
|
|
|
this.loggedIn = !!this.user;
|
2017-12-19 13:53:46 +01:00
|
|
|
this.errorMessage = "";
|
2019-11-08 12:01:50 +01:00
|
|
|
this.sub = this.route.queryParams.subscribe(params => {
|
|
|
|
this.errorCode = params["errorCode"];
|
|
|
|
this.redirectUrl = params["redirectUrl"];
|
|
|
|
this.errorMessage = "";
|
|
|
|
if (this.loggedIn && this.errorCode == '1') {
|
|
|
|
this.redirect();
|
|
|
|
}
|
|
|
|
});
|
2017-12-19 13:53:46 +01:00
|
|
|
});
|
2019-11-08 12:01:50 +01:00
|
|
|
}
|
2019-09-13 10:26:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-08 12:01:50 +01:00
|
|
|
|
2019-09-13 10:26:09 +02:00
|
|
|
ngOnDestroy() {
|
2019-11-12 13:56:43 +01:00
|
|
|
if(this.sub) {
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
2019-09-13 10:26:09 +02:00
|
|
|
if (this.sublogin) {
|
|
|
|
this.sublogin.unsubscribe();
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-09-13 10:26:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
redirect() {
|
|
|
|
if (this.redirectUrl && this.redirectUrl != "") {
|
|
|
|
this.redirectUrl = decodeURIComponent(this.redirectUrl);
|
|
|
|
var baseUrl = this.redirectUrl;
|
|
|
|
var queryParams = "";
|
|
|
|
var paramsArray = [];
|
|
|
|
var valuesArray = [];
|
|
|
|
if (this.redirectUrl.indexOf('?') != -1) {
|
|
|
|
baseUrl = this.redirectUrl.split('?')[0];
|
|
|
|
queryParams = this.redirectUrl.split('?')[1];
|
|
|
|
}
|
|
|
|
if (queryParams != "") {
|
|
|
|
var queryParamsArray = queryParams.split('&');
|
|
|
|
for (var i = 0; i < queryParamsArray.length; i++) {
|
|
|
|
paramsArray.push(queryParamsArray[i].split("=")[0]);
|
|
|
|
valuesArray.push(queryParamsArray[i].split("=")[1]);
|
|
|
|
}
|
|
|
|
this.router.navigate([baseUrl], {queryParams: this.routerHelper.createQueryParams(paramsArray, valuesArray)});
|
|
|
|
} else {
|
|
|
|
this.router.navigate([baseUrl]);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
2019-09-13 10:26:09 +02:00
|
|
|
// else{
|
|
|
|
// this.router.navigate(['/']);
|
|
|
|
// }
|
|
|
|
}
|
2019-02-25 16:28:14 +01:00
|
|
|
|
2019-09-13 10:26:09 +02:00
|
|
|
logIn() {
|
|
|
|
if (this.redirectUrl && this.redirectUrl != "") {
|
|
|
|
this.redirectUrl = decodeURIComponent(this.redirectUrl);
|
|
|
|
var baseUrl = this.redirectUrl;
|
|
|
|
var queryParams = "";
|
|
|
|
if (this.redirectUrl.indexOf('?') != -1) {
|
|
|
|
var splits = this.redirectUrl.split('?');
|
|
|
|
if (splits.length > 0) {
|
|
|
|
baseUrl = splits[0];
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-09-13 10:26:09 +02:00
|
|
|
if (splits.length > 1) {
|
|
|
|
queryParams = splits[1];
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
2019-09-13 10:26:09 +02:00
|
|
|
Session.setReloadUrl(location.protocol + "//" + location.host, baseUrl, queryParams);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-02-25 16:28:14 +01:00
|
|
|
|
2019-09-13 10:26:09 +02:00
|
|
|
window.location.href = this.properties.loginUrl;
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-09-13 10:26:09 +02:00
|
|
|
getTheRolesFormatted(roles: string[]) {
|
|
|
|
let formattedRoles = [];
|
|
|
|
for (let role of roles) {
|
|
|
|
let formattedRole = role.split("urn:geant:openaire.eu:group:")[1];
|
|
|
|
formattedRole = formattedRole.split("#aai.openaire.eu")[0]
|
|
|
|
formattedRole = formattedRole.replace("+", " ");
|
|
|
|
formattedRole = formattedRole.split("+").join(" ");
|
|
|
|
formattedRoles.push(formattedRole);
|
2019-06-12 13:50:48 +02:00
|
|
|
}
|
2019-09-13 10:26:09 +02:00
|
|
|
return formattedRoles.join(", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
isUserManager() {
|
|
|
|
return Session.isUserManager(this.user);
|
|
|
|
}
|
2018-06-01 14:28:49 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|