...
 
......@@ -28,7 +28,7 @@ export class ExplicitOverlayComponent {
login() {
this.storage.set(
'redirectTo',
'redirect',
window.Minds.site_url + this._channel.username
);
this.router.navigate(['/login']);
......
......@@ -3,6 +3,7 @@ import { ActivatedRoute, Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { Session } from '../../../../services/session';
import { ProChannelService } from '../channel.service';
import { Storage } from "../../../../services/storage";
@Component({
selector: 'm-pro--channel-login',
......@@ -25,9 +26,9 @@ import { ProChannelService } from '../channel.service';
<ng-container *ngIf="currentSection === 'register'">
<span class="m-proChannelLogin--subtext">
<a (click)="currentSection = 'login'"
>I already have a Minds account</a
>
<a (click)="currentSection = 'login'">
I already have a Minds account
</a>
</span>
<minds-form-register (done)="registered()"></minds-form-register>
......@@ -43,6 +44,8 @@ export class ProChannelLoginComponent {
paramsSubscription: Subscription;
redirectTo: string;
get settings() {
return this.service.currentChannel.pro_settings;
}
......@@ -51,7 +54,8 @@ export class ProChannelLoginComponent {
public session: Session,
public service: ProChannelService,
private router: Router,
private route: ActivatedRoute
private route: ActivatedRoute,
private storage: Storage,
) {
this.paramsSubscription = this.route.params.subscribe(params => {
if (params['username']) {
......@@ -64,7 +68,17 @@ export class ProChannelLoginComponent {
});
}
ngOnInit() {
this.redirectTo = this.storage.get('redirect');
}
registered() {
if (this.redirectTo) {
this.storage.destroy('redirect');
this.router.navigate([this.redirectTo]);
return;
}
this.router.navigate(this.service.getRouterLink('home'));
}
}
import { Cookie } from '../cookie';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Location } from "@angular/common";
/**
* API Class
......@@ -9,11 +10,11 @@ export class Client {
origin: string = '';
cookie: Cookie = new Cookie();
static _(http: HttpClient) {
return new Client(http);
static _(http: HttpClient, location: Location) {
return new Client(http, location);
}
constructor(public http: HttpClient) {
constructor(public http: HttpClient, public location: Location) {
if (window.Minds.pro) {
this.base = window.Minds.site_url;
this.origin = document.location.host;
......@@ -40,6 +41,7 @@ export class Client {
return reject(err || new Error('GET error'));
}
if (err.status === 401 && err.error.loggedin === false) {
localStorage.setItem('redirect', this.location.path());
window.location.href = '/login';
return reject(err);
}
......@@ -64,6 +66,7 @@ export class Client {
return reject(err || new Error('GET error'));
}
if (err.status === 401 && err.error.loggedin === false) {
localStorage.setItem('redirect', this.location.path());
window.location.href = '/login';
return reject(err);
}
......@@ -95,7 +98,8 @@ export class Client {
if (err.data && !err.data()) {
return reject(err || new Error('POST error'));
}
if (err.status === 401 && err.loggedin === false) {
if (err.status === 401 && err.error.loggedin === false) {
localStorage.setItem('redirect', this.location.path());
window.location.href = '/login';
return reject(err);
}
......@@ -127,6 +131,7 @@ export class Client {
},
err => {
if (err.status === 401 && err.data().loggedin === false) {
localStorage.setItem('redirect', this.location.path());
window.location.href = '/login';
return reject(err);
}
......@@ -154,6 +159,7 @@ export class Client {
},
err => {
if (err.status === 401 && err.error.loggedin === false) {
localStorage.setItem('redirect', this.location.path());
window.location.href = '/login';
return reject(err);
}
......
import { NgZone, RendererFactory2 } from '@angular/core';
import { Router } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { Location } from '@angular/common';
import { Title } from '@angular/platform-browser';
......@@ -64,7 +64,7 @@ export const MINDS_PROVIDERS: any[] = [
{
provide: Client,
useFactory: Client._,
deps: [HttpClient],
deps: [HttpClient, Location],
},
{
provide: Upload,
......