diff --git a/src/app/login/user.component.ts b/src/app/login/user.component.ts index b7e9261..3682f01 100644 --- a/src/app/login/user.component.ts +++ b/src/app/login/user.component.ts @@ -4,12 +4,13 @@ import {ActivatedRoute} from '@angular/router'; import {UserComponent} from '../openaireLibrary/login/user.component'; import {EmailService} from "../openaireLibrary/utils/email/email.service"; -import {Session} from '../openaireLibrary/login/utils/helper.class'; +import {Session, User} from '../openaireLibrary/login/utils/helper.class'; import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties'; import {SubscribeComponent} from '../utils/subscribe/subscribe.component'; import {ConnectHelper} from '../openaireLibrary/connect/connectHelper'; import {properties} from "../../environments/environment"; import {Subscriber} from "rxjs"; +import {UserManagementService} from "../openaireLibrary/services/user-management.service"; @Component({ selector: 'openaire-user', @@ -17,8 +18,7 @@ import {Subscriber} from "rxjs";
-
- +
For this action you have to login and subscribe to the research community. Login and Subscribe Subscribing to community.... An error occured while trying to subscribe to community.... -
- +
@@ -52,39 +46,59 @@ export class OpenaireUserComponent { isSubscribed: boolean = false; public server: boolean = true; loggedIn: boolean = false; - sub; - constructor(private _emailService: EmailService, private route: ActivatedRoute) { + private subscriptions = []; + public user: User; + public redirectUrl: string = ""; + constructor(private _emailService: EmailService, private route: ActivatedRoute, + private userManagementsService: UserManagementService) { } ngOnDestroy() { - if (this.sub instanceof Subscriber) { - this.sub.unsubscribe(); - } + this.subscriptions.forEach(subscription => { + if (subscription instanceof Subscriber) { + subscription.unsubscribe(); + } + }); } public ngOnInit() { if (typeof document !== 'undefined') { this.server = false; - this.loggedIn = Session.isLoggedIn(); } + this.subscriptions.push(this.userManagementsService.getUserInfo(false).subscribe(user => { + this.user = user; + this.loggedIn = !!this.user; + this.isSubscribed = this.loggedIn && Session.isSubscribedTo('community', this.communityId, this.user); + if (this.isSubscribed) { + this.usercomponent.redirect(this.redirectUrl); + } + })); this.properties = properties; - this.sub = this.route.queryParams.subscribe( - communityId => { + this.subscriptions.push(this.route.queryParams.subscribe( + params => { + this.redirectUrl = params["redirectUrl"]; this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain); if (!this.communityId) { - this.communityId = communityId['communityId']; + this.communityId = params['communityId']; } - if (this.subscribe.subscribed) { - this.usercomponent.redirect(); + if (this.isSubscribed) { + this.isSubscribed = true; + this.usercomponent.redirect(this.redirectUrl); } - }); + })); } + login() { this.usercomponent.logIn(); } subscribeTo() { - if (this.subscribe && this.communityId) { + if(!this.loggedIn){ + this.login(); + return; + } + + if (!this.isSubscribed && this.communityId) { this.subscribeLoading = true; this.subscribe.subscribe(); }