Browse Source

Stay signed in with social login

pull/161/head
Thomas 4 years ago
parent
commit
a69443a5b8
  1. 17
      apps/client/src/app/components/header/header.component.ts
  2. 17
      apps/client/src/app/components/login-with-access-token-dialog/login-with-access-token-dialog.component.ts
  3. 2
      apps/client/src/app/components/login-with-access-token-dialog/login-with-access-token-dialog.html
  4. 10
      apps/client/src/app/pages/auth/auth-page.component.ts
  5. 5
      apps/client/src/app/pages/landing/landing-page.component.ts
  6. 8
      apps/client/src/app/pages/register/register-page.component.ts
  7. 1
      apps/client/src/app/services/settings-storage.service.ts
  8. 2
      apps/client/src/app/services/token-storage.service.ts

17
apps/client/src/app/components/header/header.component.ts

@ -11,6 +11,10 @@ import { Router } from '@angular/router';
import { LoginWithAccessTokenDialog } from '@ghostfolio/client/components/login-with-access-token-dialog/login-with-access-token-dialog.component'; import { LoginWithAccessTokenDialog } from '@ghostfolio/client/components/login-with-access-token-dialog/login-with-access-token-dialog.component';
import { DataService } from '@ghostfolio/client/services/data.service'; import { DataService } from '@ghostfolio/client/services/data.service';
import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service'; import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service';
import {
STAY_SIGNED_IN,
SettingsStorageService
} from '@ghostfolio/client/services/settings-storage.service';
import { TokenStorageService } from '@ghostfolio/client/services/token-storage.service'; import { TokenStorageService } from '@ghostfolio/client/services/token-storage.service';
import { WebAuthnService } from '@ghostfolio/client/services/web-authn.service'; import { WebAuthnService } from '@ghostfolio/client/services/web-authn.service';
import { InfoItem, User } from '@ghostfolio/common/interfaces'; import { InfoItem, User } from '@ghostfolio/common/interfaces';
@ -43,8 +47,8 @@ export class HeaderComponent implements OnChanges {
private dialog: MatDialog, private dialog: MatDialog,
private impersonationStorageService: ImpersonationStorageService, private impersonationStorageService: ImpersonationStorageService,
private router: Router, private router: Router,
private tokenStorageService: TokenStorageService, private settingsStorageService: SettingsStorageService,
private webAuthnService: WebAuthnService private tokenStorageService: TokenStorageService
) { ) {
this.impersonationStorageService this.impersonationStorageService
.onChangeHasImpersonation() .onChangeHasImpersonation()
@ -108,14 +112,17 @@ export class HeaderComponent implements OnChanges {
takeUntil(this.unsubscribeSubject) takeUntil(this.unsubscribeSubject)
) )
.subscribe(({ authToken }) => { .subscribe(({ authToken }) => {
this.setToken(authToken, data.staySignedIn); this.setToken(authToken);
}); });
} }
}); });
} }
public setToken(aToken: string, staySignedIn: boolean) { public setToken(aToken: string) {
this.tokenStorageService.saveToken(aToken, staySignedIn); this.tokenStorageService.saveToken(
aToken,
this.settingsStorageService.getSetting(STAY_SIGNED_IN) === 'true'
);
this.router.navigate(['/']); this.router.navigate(['/']);
} }

17
apps/client/src/app/components/login-with-access-token-dialog/login-with-access-token-dialog.component.ts

@ -1,5 +1,10 @@
import { ChangeDetectionStrategy, Component, Inject } from '@angular/core'; import { ChangeDetectionStrategy, Component, Inject } from '@angular/core';
import { MatCheckboxChange } from '@angular/material/checkbox';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import {
STAY_SIGNED_IN,
SettingsStorageService
} from '@ghostfolio/client/services/settings-storage.service';
@Component({ @Component({
selector: 'gf-login-with-access-token-dialog', selector: 'gf-login-with-access-token-dialog',
@ -9,13 +14,21 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
}) })
export class LoginWithAccessTokenDialog { export class LoginWithAccessTokenDialog {
public constructor( public constructor(
@Inject(MAT_DIALOG_DATA) public data: any,
public dialogRef: MatDialogRef<LoginWithAccessTokenDialog>, public dialogRef: MatDialogRef<LoginWithAccessTokenDialog>,
@Inject(MAT_DIALOG_DATA) public data: any private settingsStorageService: SettingsStorageService
) {} ) {}
ngOnInit() {} ngOnInit() {}
public onClose(): void { public onChangeStaySignedIn(aValue: MatCheckboxChange) {
this.settingsStorageService.setSetting(
STAY_SIGNED_IN,
aValue.checked?.toString()
);
}
public onClose() {
this.dialogRef.close(); this.dialogRef.close();
} }
} }

2
apps/client/src/app/components/login-with-access-token-dialog/login-with-access-token-dialog.html

@ -28,7 +28,7 @@
</div> </div>
<div mat-dialog-actions> <div mat-dialog-actions>
<div class="flex-grow-1"> <div class="flex-grow-1">
<mat-checkbox i18n [(ngModel)]="data.staySignedIn" <mat-checkbox i18n (change)="onChangeStaySignedIn($event)"
>Stay signed in</mat-checkbox >Stay signed in</mat-checkbox
> >
</div> </div>

10
apps/client/src/app/pages/auth/auth-page.component.ts

@ -1,5 +1,9 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import {
STAY_SIGNED_IN,
SettingsStorageService
} from '@ghostfolio/client/services/settings-storage.service';
import { TokenStorageService } from '@ghostfolio/client/services/token-storage.service'; import { TokenStorageService } from '@ghostfolio/client/services/token-storage.service';
@Component({ @Component({
@ -14,6 +18,7 @@ export class AuthPageComponent implements OnInit {
public constructor( public constructor(
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router, private router: Router,
private settingsStorageService: SettingsStorageService,
private tokenStorageService: TokenStorageService private tokenStorageService: TokenStorageService
) {} ) {}
@ -23,7 +28,10 @@ export class AuthPageComponent implements OnInit {
public ngOnInit() { public ngOnInit() {
this.route.params.subscribe((params) => { this.route.params.subscribe((params) => {
const jwt = params['jwt']; const jwt = params['jwt'];
this.tokenStorageService.saveToken(jwt); this.tokenStorageService.saveToken(
jwt,
this.settingsStorageService.getSetting(STAY_SIGNED_IN) === 'true'
);
this.router.navigate(['/']); this.router.navigate(['/']);
}); });

5
apps/client/src/app/pages/landing/landing-page.component.ts

@ -26,8 +26,7 @@ export class LandingPageComponent implements OnDestroy, OnInit {
private changeDetectorRef: ChangeDetectorRef, private changeDetectorRef: ChangeDetectorRef,
private dataService: DataService, private dataService: DataService,
private router: Router, private router: Router,
private tokenStorageService: TokenStorageService, private tokenStorageService: TokenStorageService
private webAuthnService: WebAuthnService
) {} ) {}
/** /**
@ -257,7 +256,7 @@ export class LandingPageComponent implements OnDestroy, OnInit {
} }
public setToken(aToken: string) { public setToken(aToken: string) {
this.tokenStorageService.saveToken(aToken); this.tokenStorageService.saveToken(aToken, true);
this.router.navigate(['/']); this.router.navigate(['/']);
} }

8
apps/client/src/app/pages/register/register-page.component.ts

@ -78,19 +78,13 @@ export class RegisterPageComponent implements OnDestroy, OnInit {
dialogRef.afterClosed().subscribe((data) => { dialogRef.afterClosed().subscribe((data) => {
if (data?.authToken) { if (data?.authToken) {
this.tokenStorageService.saveToken(authToken); this.tokenStorageService.saveToken(authToken, true);
this.router.navigate(['/']); this.router.navigate(['/']);
} }
}); });
} }
public setToken(aToken: string) {
this.tokenStorageService.saveToken(aToken);
this.router.navigate(['/']);
}
public ngOnDestroy() { public ngOnDestroy() {
this.unsubscribeSubject.next(); this.unsubscribeSubject.next();
this.unsubscribeSubject.complete(); this.unsubscribeSubject.complete();

1
apps/client/src/app/services/settings-storage.service.ts

@ -1,6 +1,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
export const RANGE = 'range'; export const RANGE = 'range';
export const STAY_SIGNED_IN = 'staySignedIn';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'

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

@ -21,7 +21,7 @@ export class TokenStorageService {
); );
} }
public saveToken(token: string, staySignedIn: boolean = false): void { public saveToken(token: string, staySignedIn = false): void {
if (staySignedIn) { if (staySignedIn) {
window.localStorage.setItem(TOKEN_KEY, token); window.localStorage.setItem(TOKEN_KEY, token);
} }

Loading…
Cancel
Save