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";
|
2020-09-21 09:27:19 +02:00
|
|
|
import {properties} from "../../../environments/environment";
|
2020-11-11 15:43:13 +01:00
|
|
|
import {Subscriber} from "rxjs";
|
2020-11-03 10:38:11 +01:00
|
|
|
import {StringUtils} from "../utils/string-utils.class";
|
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;
|
2021-03-17 10:21:37 +01:00
|
|
|
public loading: boolean = true;
|
2019-09-13 10:26:09 +02:00
|
|
|
public loggedIn: boolean = false;
|
|
|
|
public server: boolean = true;
|
|
|
|
public errorMessage: string = "";
|
|
|
|
public password: string = "";
|
2020-11-11 15:43:13 +01:00
|
|
|
private subscriptions = [];
|
2019-09-13 10:26:09 +02:00
|
|
|
public errorCode: string = "";
|
|
|
|
public redirectUrl: string = "";
|
|
|
|
public routerHelper: RouterHelper = new RouterHelper();
|
|
|
|
public loginUrl;
|
2021-03-17 10:21:37 +01:00
|
|
|
public properties: EnvProperties = properties;
|
2019-09-13 10:26:09 +02:00
|
|
|
@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) {
|
2021-03-17 10:21:37 +01:00
|
|
|
this._title.setTitle("OpenAIRE | Login");
|
2019-09-13 10:26:09 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-09-13 10:26:09 +02:00
|
|
|
ngOnInit() {
|
2020-11-18 17:06:27 +01:00
|
|
|
this.loginUrl = this.properties.loginUrl;
|
2019-09-13 10:26:09 +02:00
|
|
|
if (typeof document !== 'undefined') {
|
|
|
|
this.server = false;
|
2022-09-08 15:43:59 +02:00
|
|
|
this.userManagementsService.updateUserInfo(() => {
|
|
|
|
this.user = this.userManagementsService.user;
|
2019-11-08 12:01:50 +01:00
|
|
|
this.loggedIn = !!this.user;
|
2017-12-19 13:53:46 +01:00
|
|
|
this.errorMessage = "";
|
2021-03-17 10:21:37 +01:00
|
|
|
this.loading = true;
|
2020-11-11 15:43:13 +01:00
|
|
|
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
2019-11-08 12:01:50 +01:00
|
|
|
this.errorCode = params["errorCode"];
|
|
|
|
this.redirectUrl = params["redirectUrl"];
|
|
|
|
this.errorMessage = "";
|
2022-07-27 15:57:46 +02:00
|
|
|
if (this.loggedIn && (this.errorCode == '1' || this.errorCode == '3' || this.errorCode == '7')) {
|
2019-11-08 12:01:50 +01:00
|
|
|
this.redirect();
|
2021-03-17 10:21:37 +01:00
|
|
|
} else {
|
|
|
|
this.loading = false;
|
2019-11-08 12:01:50 +01:00
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
}));
|
2022-09-08 15:43:59 +02:00
|
|
|
});
|
2019-11-08 12:01:50 +01:00
|
|
|
}
|
2019-09-13 10:26:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
2020-11-11 15:43:13 +01:00
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscriber) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
2019-09-13 10:26:09 +02:00
|
|
|
}
|
|
|
|
|
2022-07-27 15:57:46 +02:00
|
|
|
redirect(redirectUrl = null) {
|
|
|
|
//if parameters are not read yet, force them to use the function parameter
|
|
|
|
if(!this.redirectUrl && redirectUrl){
|
|
|
|
this.redirectUrl = redirectUrl
|
|
|
|
}
|
2019-09-13 10:26:09 +02:00
|
|
|
if (this.redirectUrl && this.redirectUrl != "") {
|
|
|
|
this.redirectUrl = decodeURIComponent(this.redirectUrl);
|
2021-03-17 10:21:37 +01:00
|
|
|
this.userManagementsService.setRedirectUrl(this.redirectUrl);
|
|
|
|
this.router.navigate(['/reload']);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-09-13 10:26:09 +02:00
|
|
|
}
|
2019-02-25 16:28:14 +01:00
|
|
|
|
2019-09-13 10:26:09 +02:00
|
|
|
logIn() {
|
2021-03-17 10:21:37 +01:00
|
|
|
this.userManagementsService.login();
|
2019-09-13 10:26:09 +02:00
|
|
|
}
|
2020-09-16 15:00:07 +02:00
|
|
|
|
2019-09-13 10:26:09 +02:00
|
|
|
getTheRolesFormatted(roles: string[]) {
|
|
|
|
let formattedRoles = [];
|
|
|
|
for (let role of roles) {
|
2021-02-19 19:18:53 +01:00
|
|
|
if(role.indexOf("_MANAGER")!=-1){
|
|
|
|
formattedRoles.push("Manager of " + role.split("_")[1]);
|
|
|
|
}else if((["FUNDER","COMMUNITY","INSTITUTION","PROJECT"]).indexOf(role.split("_")[0])!=-1){
|
|
|
|
formattedRoles.push("Member of " + role.split("_")[1]);
|
2020-11-03 10:38:11 +01:00
|
|
|
}else{
|
2021-02-19 19:18:53 +01:00
|
|
|
formattedRoles.splice(0,0,StringUtils.capitalize(role.split('_').join(' ').toLowerCase()));
|
2020-09-16 15:00:07 +02:00
|
|
|
}
|
2019-06-12 13:50:48 +02:00
|
|
|
}
|
2019-09-13 10:26:09 +02:00
|
|
|
return formattedRoles.join(", ");
|
|
|
|
}
|
2022-12-09 17:01:18 +01:00
|
|
|
|
|
|
|
get isCurator() {
|
|
|
|
return Session.isPortalAdministrator(this.user) || Session.isMonitorCurator(this.user);
|
|
|
|
}
|
2019-09-13 10:26:09 +02:00
|
|
|
|
2022-12-09 17:01:18 +01:00
|
|
|
get isUserManager() {
|
2019-09-13 10:26:09 +02:00
|
|
|
return Session.isUserManager(this.user);
|
|
|
|
}
|
2018-06-01 14:28:49 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|