Browse Source

Store utm_source in local storage (#106)

pull/108/head
Thomas 4 years ago
committed by GitHub
parent
commit
79edc09710
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      apps/client/src/app/app-routing.module.ts
  2. 9
      apps/client/src/app/core/auth.guard.ts
  3. 2
      apps/client/src/app/pages/home/home-page.component.ts
  4. 3
      apps/client/src/app/pages/login/login-page.component.ts
  5. 23
      apps/client/src/app/services/data.service.ts
  6. 6
      apps/client/src/app/services/token-storage.service.ts

2
apps/client/src/app/app-routing.module.ts

@ -82,7 +82,7 @@ const routes: Routes = [
// wildcard, if requested url doesn't match any paths for routes defined // wildcard, if requested url doesn't match any paths for routes defined
// earlier // earlier
path: '**', path: '**',
redirectTo: '/home', redirectTo: 'home',
pathMatch: 'full' pathMatch: 'full'
} }
]; ];

9
apps/client/src/app/core/auth.guard.ts

@ -6,16 +6,25 @@ import {
RouterStateSnapshot RouterStateSnapshot
} from '@angular/router'; } from '@angular/router';
import { SettingsStorageService } from '../services/settings-storage.service';
import { TokenStorageService } from '../services/token-storage.service'; import { TokenStorageService } from '../services/token-storage.service';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class AuthGuard implements CanActivate { export class AuthGuard implements CanActivate {
constructor( constructor(
private router: Router, private router: Router,
private settingsStorageService: SettingsStorageService,
private tokenStorageService: TokenStorageService private tokenStorageService: TokenStorageService
) {} ) {}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (route.queryParams?.utm_source) {
this.settingsStorageService.setSetting(
'utm_source',
route.queryParams?.utm_source
);
}
const isLoggedIn = !!this.tokenStorageService.getToken(); const isLoggedIn = !!this.tokenStorageService.getToken();
if (isLoggedIn) { if (isLoggedIn) {

2
apps/client/src/app/pages/home/home-page.component.ts

@ -68,7 +68,7 @@ export class HomePageComponent implements OnDestroy, OnInit {
private settingsStorageService: SettingsStorageService, private settingsStorageService: SettingsStorageService,
private tokenStorageService: TokenStorageService private tokenStorageService: TokenStorageService
) { ) {
this.routeQueryParams = route.queryParams this.routeQueryParams = this.route.queryParams
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe((params) => { .subscribe((params) => {
if (params['performanceChartDialog']) { if (params['performanceChartDialog']) {

3
apps/client/src/app/pages/login/login-page.component.ts

@ -37,9 +37,6 @@ export class LoginPageComponent implements OnDestroy, OnInit {
* Initializes the controller * Initializes the controller
*/ */
public ngOnInit() { public ngOnInit() {
// Remove all tokens (e.g. impersonationId)
window.localStorage.clear();
this.dataService.fetchInfo().subscribe(({ demoAuthToken }) => { this.dataService.fetchInfo().subscribe(({ demoAuthToken }) => {
this.demoAuthToken = demoAuthToken; this.demoAuthToken = demoAuthToken;

23
apps/client/src/app/services/data.service.ts

@ -23,19 +23,25 @@ import {
PortfolioReport, PortfolioReport,
User User
} from '@ghostfolio/common/interfaces'; } from '@ghostfolio/common/interfaces';
import { permissions } from '@ghostfolio/common/permissions';
import { Order as OrderModel } from '@prisma/client'; import { Order as OrderModel } from '@prisma/client';
import { Account as AccountModel } from '@prisma/client'; import { Account as AccountModel } from '@prisma/client';
import { parseISO } from 'date-fns'; import { parseISO } from 'date-fns';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { SettingsStorageService } from './settings-storage.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class DataService { export class DataService {
private info: InfoItem; private info: InfoItem;
public constructor(private http: HttpClient) {} public constructor(
private http: HttpClient,
private settingsStorageService: SettingsStorageService
) {}
public fetchAccounts() { public fetchAccounts() {
return this.http.get<AccountModel[]>('/api/account'); return this.http.get<AccountModel[]>('/api/account');
@ -75,7 +81,20 @@ export class DataService {
} }
*/ */
return this.http.get<InfoItem>('/api/info'); return this.http.get<InfoItem>('/api/info').pipe(
map((data) => {
if (
this.settingsStorageService.getSetting('utm_source') ===
'trusted-web-activity'
) {
data.globalPermissions = data.globalPermissions.filter(
(permission) => permission !== permissions.enableSubscription
);
}
return data;
})
);
} }
public fetchSymbolItem(aSymbol: string) { public fetchSymbolItem(aSymbol: string) {

6
apps/client/src/app/services/token-storage.service.ts

@ -27,8 +27,14 @@ export class TokenStorageService {
} }
public signOut(): void { public signOut(): void {
const utmSource = window.localStorage.getItem('utm_source');
window.localStorage.clear(); window.localStorage.clear();
if (utmSource) {
window.localStorage.setItem('utm_source', utmSource);
}
this.hasTokenChangeSubject.next(); this.hasTokenChangeSubject.next();
} }
} }

Loading…
Cancel
Save