connect user compoonent: update method to check if user is subscribed, avoiid double messages, make sure it redirects properly after login and subscribe
This commit is contained in:
parent
e92b2eb824
commit
7169c182fc
|
@ -4,12 +4,13 @@ import {ActivatedRoute} from '@angular/router';
|
||||||
import {UserComponent} from '../openaireLibrary/login/user.component';
|
import {UserComponent} from '../openaireLibrary/login/user.component';
|
||||||
import {EmailService} from "../openaireLibrary/utils/email/email.service";
|
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 {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
||||||
import {SubscribeComponent} from '../utils/subscribe/subscribe.component';
|
import {SubscribeComponent} from '../utils/subscribe/subscribe.component';
|
||||||
import {ConnectHelper} from '../openaireLibrary/connect/connectHelper';
|
import {ConnectHelper} from '../openaireLibrary/connect/connectHelper';
|
||||||
import {properties} from "../../environments/environment";
|
import {properties} from "../../environments/environment";
|
||||||
import {Subscriber} from "rxjs";
|
import {Subscriber} from "rxjs";
|
||||||
|
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'openaire-user',
|
selector: 'openaire-user',
|
||||||
|
@ -17,8 +18,7 @@ import {Subscriber} from "rxjs";
|
||||||
<div id="tm-main" class="uk-section tm-middle">
|
<div id="tm-main" class="uk-section tm-middle">
|
||||||
<div class="uk-margin-small-top">
|
<div class="uk-margin-small-top">
|
||||||
<user [mainComponent]=false></user>
|
<user [mainComponent]=false></user>
|
||||||
<div *ngIf="!server" class=" uk-container uk-container-small uk-position-relative">
|
<div class=" uk-container uk-container-small uk-position-relative">
|
||||||
|
|
||||||
<div *ngIf="usercomponent.errorCode == '6' && !isSubscribed" class="uk-alert uk-alert-warning">
|
<div *ngIf="usercomponent.errorCode == '6' && !isSubscribed" class="uk-alert uk-alert-warning">
|
||||||
<span *ngIf="!isSubscribed ">For this action you have to <span *ngIf="!loggedIn">login and</span> subscribe to the research community.
|
<span *ngIf="!isSubscribed ">For this action you have to <span *ngIf="!loggedIn">login and</span> subscribe to the research community.
|
||||||
<span *ngIf="subscribe && !subscribeLoading "> <span *ngIf="!loggedIn">Login and </span>Subscribe <a
|
<span *ngIf="subscribe && !subscribeLoading "> <span *ngIf="!loggedIn">Login and </span>Subscribe <a
|
||||||
|
@ -27,13 +27,7 @@ import {Subscriber} from "rxjs";
|
||||||
<span *ngIf="subscribeLoading ">Subscribing to community....</span>
|
<span *ngIf="subscribeLoading ">Subscribing to community....</span>
|
||||||
<span *ngIf="subscribeError ">An error occured while trying to subscribe to community....</span>
|
<span *ngIf="subscribeError ">An error occured while trying to subscribe to community....</span>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="usercomponent.errorCode == '7'" class="uk-alert uk-alert-warning">
|
|
||||||
This action requires authentication.
|
|
||||||
<span *ngIf="!loggedIn">
|
|
||||||
Please <a class="" (click)="login()"> sign in</a> to continue.
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -52,39 +46,59 @@ export class OpenaireUserComponent {
|
||||||
isSubscribed: boolean = false;
|
isSubscribed: boolean = false;
|
||||||
public server: boolean = true;
|
public server: boolean = true;
|
||||||
loggedIn: boolean = false;
|
loggedIn: boolean = false;
|
||||||
sub;
|
private subscriptions = [];
|
||||||
constructor(private _emailService: EmailService, private route: ActivatedRoute) {
|
public user: User;
|
||||||
|
public redirectUrl: string = "";
|
||||||
|
constructor(private _emailService: EmailService, private route: ActivatedRoute,
|
||||||
|
private userManagementsService: UserManagementService) {
|
||||||
}
|
}
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
if (this.sub instanceof Subscriber) {
|
this.subscriptions.forEach(subscription => {
|
||||||
this.sub.unsubscribe();
|
if (subscription instanceof Subscriber) {
|
||||||
}
|
subscription.unsubscribe();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
public ngOnInit() {
|
public ngOnInit() {
|
||||||
if (typeof document !== 'undefined') {
|
if (typeof document !== 'undefined') {
|
||||||
this.server = false;
|
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.properties = properties;
|
||||||
this.sub = this.route.queryParams.subscribe(
|
this.subscriptions.push(this.route.queryParams.subscribe(
|
||||||
communityId => {
|
params => {
|
||||||
|
this.redirectUrl = params["redirectUrl"];
|
||||||
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
|
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
|
||||||
if (!this.communityId) {
|
if (!this.communityId) {
|
||||||
this.communityId = communityId['communityId'];
|
this.communityId = params['communityId'];
|
||||||
}
|
}
|
||||||
if (this.subscribe.subscribed) {
|
if (this.isSubscribed) {
|
||||||
this.usercomponent.redirect();
|
this.isSubscribed = true;
|
||||||
|
this.usercomponent.redirect(this.redirectUrl);
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
login() {
|
login() {
|
||||||
this.usercomponent.logIn();
|
this.usercomponent.logIn();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribeTo() {
|
subscribeTo() {
|
||||||
if (this.subscribe && this.communityId) {
|
if(!this.loggedIn){
|
||||||
|
this.login();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.isSubscribed && this.communityId) {
|
||||||
this.subscribeLoading = true;
|
this.subscribeLoading = true;
|
||||||
this.subscribe.subscribe();
|
this.subscribe.subscribe();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue