Commit 574e8ad7 authored by Emiliano Balbuena's avatar Emiliano Balbuena Committed by Mark Harding

(feat): Redirect to /login and back if not logged in during upgrade

1 merge request!590WIP: Epic/pro affiliate launch
Pipeline #89261962 running with stages
......@@ -66,12 +66,12 @@ export class LoginComponent {
loggedin() {
if (this.referrer) this.router.navigateByUrl(this.referrer);
else if (this.redirectTo) this.router.navigate([this.redirectTo]);
else if (this.redirectTo) this.navigateToRedirection();
else this.loginReferrer.navigate();
}
registered() {
if (this.redirectTo) this.router.navigate([this.redirectTo]);
if (this.redirectTo) this.navigateToRedirection();
else {
this.modal.setDisplay('categories').open();
this.loginReferrer.navigate({
......@@ -79,4 +79,20 @@ export class LoginComponent {
});
}
}
navigateToRedirection() {
const uri = this.redirectTo.split('?', 2);
const extras = {};
if (uri[1]) {
extras['queryParams'] = {};
for (const queryParamString of uri[1].split('&')) {
const queryParam = queryParamString.split('=');
extras['queryParams'][queryParam[0]] = queryParam[1];
}
}
this.router.navigate([uri[0]], extras);
}
}
......@@ -6,7 +6,7 @@ import {
OnInit,
Output,
} from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { Session } from '../../../services/session';
......@@ -19,6 +19,7 @@ import {
UpgradeOptionInterval,
} from '../../upgrades/upgrade-options.component';
import currency from '../../../helpers/currency';
import { Location } from '@angular/common';
@Component({
selector: 'm-plus--subscription',
......@@ -54,7 +55,8 @@ export class PlusSubscriptionComponent implements OnInit {
protected overlayModal: OverlayModalService,
protected wirePaymentHandlers: WirePaymentHandlersService,
protected cd: ChangeDetectorRef,
protected route: ActivatedRoute
protected route: ActivatedRoute,
protected router: Router
) {}
ngOnInit() {
......@@ -69,7 +71,9 @@ export class PlusSubscriptionComponent implements OnInit {
this.currency = params.c || 'usd';
this.interval = params.i || 'yearly';
if (params.c || params.i) this.enable();
if (params.c || params.i) {
this.enable();
}
}
);
}
......@@ -91,6 +95,15 @@ export class PlusSubscriptionComponent implements OnInit {
}
async enable() {
if (!this.session.isLoggedIn()) {
localStorage.setItem(
'redirect',
`/plus?c=${this.currency}&i=${this.interval}`
);
this.router.navigate(['/login']);
return;
}
this.inProgress = true;
this.error = '';
this.detectChanges();
......
......@@ -6,7 +6,7 @@ import {
OnInit,
Output,
} from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { Session } from '../../../services/session';
......@@ -54,7 +54,8 @@ export class ProSubscriptionComponent implements OnInit {
protected overlayModal: OverlayModalService,
protected wirePaymentHandlers: WirePaymentHandlersService,
protected cd: ChangeDetectorRef,
protected route: ActivatedRoute
protected route: ActivatedRoute,
protected router: Router
) {}
ngOnInit() {
......@@ -69,7 +70,9 @@ export class ProSubscriptionComponent implements OnInit {
this.currency = params.c || 'usd';
this.interval = params.i || 'yearly';
if (params.c || params.i) this.enable();
if (params.c || params.i) {
this.enable();
}
}
);
}
......@@ -91,6 +94,15 @@ export class ProSubscriptionComponent implements OnInit {
}
async enable() {
if (!this.session.isLoggedIn()) {
localStorage.setItem(
'redirect',
`/pro?c=${this.currency}&i=${this.interval}`
);
this.router.navigate(['/login']);
return;
}
this.inProgress = true;
this.error = '';
this.detectChanges();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment