Browse Source

The createAccount method is only called after the user accepts the terms and conditions of the first step

pull/4393/head
tobikugel 1 month ago
committed by Thomas Kaul
parent
commit
b09f101793
  1. 24
      apps/client/src/app/pages/register/register-page.component.ts
  2. 2
      apps/client/src/app/pages/register/register-page.html
  3. 34
      apps/client/src/app/pages/register/show-access-token-dialog/show-access-token-dialog.component.ts
  4. 2
      apps/client/src/app/pages/register/show-access-token-dialog/show-access-token-dialog.html

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

@ -7,7 +7,6 @@ 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 { Role } from '@prisma/client';
import { DeviceDetectorService } from 'ngx-device-detector';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@ -59,15 +58,6 @@ export class RegisterPageComponent implements OnDestroy, OnInit {
);
}
public async createAccount() {
this.dataService
.postUser()
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe(({ accessToken, authToken, role }) => {
this.openShowAccessTokenDialog(accessToken, authToken, role);
});
}
public async onLoginWithInternetIdentity() {
try {
const { authToken } = await this.internetIdentityService.login();
@ -76,16 +66,12 @@ export class RegisterPageComponent implements OnDestroy, OnInit {
} catch {}
}
public openShowAccessTokenDialog(
accessToken: string,
authToken: string,
role: Role
) {
public openShowAccessTokenDialog() {
const dialogRef = this.dialog.open(ShowAccessTokenDialog, {
data: {
accessToken,
authToken,
role
accessToken: undefined,
authToken: undefined,
role: undefined
},
disableClose: true,
width: '30rem'
@ -96,7 +82,7 @@ export class RegisterPageComponent implements OnDestroy, OnInit {
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe((data) => {
if (data?.authToken) {
this.tokenStorageService.saveToken(authToken, true);
this.tokenStorageService.saveToken(data.authToken, true);
this.router.navigate(['/']);
}

2
apps/client/src/app/pages/register/register-page.html

@ -22,7 +22,7 @@
class="d-inline-block"
color="primary"
mat-flat-button
(click)="createAccount()"
(click)="openShowAccessTokenDialog()"
>
<ng-container i18n>Create Account</ng-container>
</button>

34
apps/client/src/app/pages/register/show-access-token-dialog/show-access-token-dialog.component.ts

@ -1,5 +1,15 @@
import { ChangeDetectionStrategy, Component, Inject } from '@angular/core';
import { DataService } from '@ghostfolio/client/services/data.service';
import {
ChangeDetectionStrategy,
Component,
Inject,
ViewChild
} from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { MatStepper } from '@angular/material/stepper';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Component({
selector: 'gf-show-access-token-dialog',
@ -9,10 +19,16 @@ import { MAT_DIALOG_DATA } from '@angular/material/dialog';
standalone: false
})
export class ShowAccessTokenDialog {
@ViewChild(MatStepper) stepper!: MatStepper;
public isCreateAccountButtonDisabled = true;
public disclaimerChecked = false;
public constructor(@Inject(MAT_DIALOG_DATA) public data: any) {}
private unsubscribeSubject = new Subject<void>();
public constructor(
@Inject(MAT_DIALOG_DATA) public data: any,
private dataService: DataService
) {}
public onChangeDislaimerChecked() {
this.disclaimerChecked = !this.disclaimerChecked;
@ -21,4 +37,18 @@ export class ShowAccessTokenDialog {
public enableCreateAccountButton() {
this.isCreateAccountButtonDisabled = false;
}
public async createAccount() {
this.dataService
.postUser()
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe(({ accessToken, authToken, role }) => {
this.data = {
accessToken,
authToken,
role
};
this.stepper.next();
});
}
}

2
apps/client/src/app/pages/register/show-access-token-dialog/show-access-token-dialog.html

@ -41,8 +41,8 @@
color="primary"
i18n
mat-flat-button
matStepperNext
[disabled]="!disclaimerChecked"
(click)="createAccount()"
>
Continue
</button>

Loading…
Cancel
Save