mirror of https://github.com/ghostfolio/ghostfolio
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.
119 lines
3.7 KiB
119 lines
3.7 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 { GfLogoComponent } from '@ghostfolio/ui/logo';
|
|
|
|
import {
|
|
Component,
|
|
CUSTOM_ELEMENTS_SCHEMA,
|
|
OnDestroy,
|
|
OnInit
|
|
} from '@angular/core';
|
|
import { MatButtonModule } from '@angular/material/button';
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
import { Router, RouterModule } from '@angular/router';
|
|
import { DeviceDetectorService } from 'ngx-device-detector';
|
|
import { Subject } from 'rxjs';
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
import { ShowAccessTokenDialogParams } from './show-access-token-dialog/interfaces/interfaces';
|
|
import { ShowAccessTokenDialog } from './show-access-token-dialog/show-access-token-dialog.component';
|
|
import { ShowAccessTokenDialogModule } from './show-access-token-dialog/show-access-token-dialog.module';
|
|
|
|
@Component({
|
|
host: { class: 'page' },
|
|
imports: [
|
|
GfLogoComponent,
|
|
MatButtonModule,
|
|
RouterModule,
|
|
ShowAccessTokenDialogModule
|
|
],
|
|
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
|
selector: 'gf-register-page',
|
|
styleUrls: ['./register-page.scss'],
|
|
templateUrl: './register-page.html'
|
|
})
|
|
export class GfRegisterPageComponent implements OnDestroy, OnInit {
|
|
public deviceType: string;
|
|
public hasPermissionForSocialLogin: boolean;
|
|
public hasPermissionForSubscription: 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 { globalPermissions } = this.dataService.fetchInfo();
|
|
|
|
this.deviceType = this.deviceService.getDeviceInfo().deviceType;
|
|
|
|
this.hasPermissionForSocialLogin = hasPermission(
|
|
globalPermissions,
|
|
permissions.enableSocialLogin
|
|
);
|
|
|
|
this.hasPermissionForSubscription = hasPermission(
|
|
globalPermissions,
|
|
permissions.enableSubscription
|
|
);
|
|
|
|
this.hasPermissionToCreateUser = hasPermission(
|
|
globalPermissions,
|
|
permissions.createUserAccount
|
|
);
|
|
}
|
|
|
|
public async onLoginWithInternetIdentity() {
|
|
try {
|
|
const { authToken } = await this.internetIdentityService.login();
|
|
|
|
this.tokenStorageService.saveToken(authToken);
|
|
|
|
await this.router.navigate(['/']);
|
|
} catch {}
|
|
}
|
|
|
|
public openShowAccessTokenDialog() {
|
|
const dialogRef = this.dialog.open(ShowAccessTokenDialog, {
|
|
data: {
|
|
deviceType: this.deviceType,
|
|
needsToAcceptTermsOfService: this.hasPermissionForSubscription
|
|
} as ShowAccessTokenDialogParams,
|
|
disableClose: true,
|
|
height: this.deviceType === 'mobile' ? '98vh' : undefined,
|
|
width: this.deviceType === 'mobile' ? '100vw' : '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();
|
|
}
|
|
}
|
|
|