You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

91 lines
2.9 KiB

import { DataService } from '@ghostfolio/client/services/data.service';
import { InternetIdentityService } from '@ghostfolio/client/services/internet-identity.service';
import { TokenStorageService } from '@ghostfolio/client/services/token-storage.service';
import { InfoItem, LineChartItem } from '@ghostfolio/common/interfaces';
import { hasPermission, permissions } from '@ghostfolio/common/permissions';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { Router } from '@angular/router';
import { DeviceDetectorService } from 'ngx-device-detector';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { ShowAccessTokenDialog } from './show-access-token-dialog/show-access-token-dialog.component';
@Component({
host: { class: 'page' },
selector: 'gf-register-page',
styleUrls: ['./register-page.scss'],
templateUrl: './register-page.html',
standalone: false
})
export class RegisterPageComponent implements OnDestroy, OnInit {
public demoAuthToken: string;
public deviceType: string;
public hasPermissionForSocialLogin: boolean;
public hasPermissionToCreateUser: boolean;
public historicalDataItems: LineChartItem[];
public info: InfoItem;
private unsubscribeSubject = new Subject<void>();
public constructor(
private dataService: DataService,
private deviceService: DeviceDetectorService,
private dialog: MatDialog,
private internetIdentityService: InternetIdentityService,
private router: Router,
private tokenStorageService: TokenStorageService
) {
this.info = this.dataService.fetchInfo();
this.tokenStorageService.signOut();
}
public ngOnInit() {
const { demoAuthToken, globalPermissions } = this.dataService.fetchInfo();
this.demoAuthToken = demoAuthToken;
this.deviceType = this.deviceService.getDeviceInfo().deviceType;
this.hasPermissionForSocialLogin = hasPermission(
globalPermissions,
permissions.enableSocialLogin
);
this.hasPermissionToCreateUser = hasPermission(
globalPermissions,
permissions.createUserAccount
);
}
public async onLoginWithInternetIdentity() {
try {
const { authToken } = await this.internetIdentityService.login();
this.tokenStorageService.saveToken(authToken);
this.router.navigate(['/']);
} catch {}
}
public openShowAccessTokenDialog() {
const dialogRef = this.dialog.open(ShowAccessTokenDialog, {
disableClose: true,
width: '30rem'
});
dialogRef
.afterClosed()
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe((authToken) => {
if (authToken) {
this.tokenStorageService.saveToken(authToken, true);
this.router.navigate(['/']);
}
});
}
public ngOnDestroy() {
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();
}
}