refactor: rewrite oauth setup for the new api

This commit is contained in:
2024-12-28 07:44:41 +03:00
parent a8b1485b0e
commit a7542eaf32
6 changed files with 137 additions and 41 deletions

View File

@ -76,7 +76,9 @@
}
</mat-form-field>
<OAuthProviders [canUnlink]="true" [activeProvidersId]="activatedProviders" (oAuthUpdateProviders)="updateProviders()"
[message]="'Или можете получить часть данных от сторонних сервисов'"/>
<OAuthProviders [canUnlink]="true" [activeProvidersId]="activatedProviders"
(oAuthUpdateProviders)="updateProviders()"
[message]="'Или можете получить часть данных от сторонних сервисов'"
[action]="OAuthAction.Bind" [isSetup]="true"/>
</div>
</form>

View File

@ -1,4 +1,5 @@
import {Component} from '@angular/core';
import {Location} from '@angular/common';
import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms";
import {NavigationService} from "@service/navigation.service";
import {passwordMatchValidator} from '@service/password-match.validator';
@ -13,6 +14,8 @@ import AuthApiService from "@api/v1/authApiService";
import {OAuthProviders} from "@component/OAuthProviders/OAuthProviders";
import {OAuthProvider} from "@model/oAuthProvider";
import {PasswordInputComponent} from "@component/common/password-input/password-input.component";
import {OAuthAction} from "@model/oAuthAction";
import {Router} from "@angular/router";
@Component({
selector: 'app-create-admin',
@ -29,7 +32,7 @@ import {PasswordInputComponent} from "@component/common/password-input/password-
PasswordInputComponent
],
templateUrl: './create-admin.component.html',
providers: [AuthApiService]
providers: [AuthApiService, Location]
})
export class CreateAdminComponent {
@ -37,8 +40,9 @@ export class CreateAdminComponent {
protected hideRetypePass = true;
protected activatedProviders: OAuthProvider[] = [];
constructor(
private navigationService: NavigationService, private formBuilder: FormBuilder, private api: SetupService) {
constructor(private router: Router,
private location: Location,
private navigationService: NavigationService, private formBuilder: FormBuilder, private api: SetupService) {
this.createAdminForm = this.formBuilder.group({
user: ['', Validators.pattern(/^([A-Za-z0-9]){4,}$/)],
email: ['', Validators.email],
@ -76,6 +80,9 @@ export class CreateAdminComponent {
this.activatedProviders = configuration.usedOAuthProviders;
}
const currentPath = this.router.url.split('?')[0];
this.location.replaceState(currentPath);
});
}
@ -87,4 +94,6 @@ export class CreateAdminComponent {
protected updateProviders() {
this.updateAdminData();
}
protected readonly OAuthAction = OAuthAction;
}

View File

@ -1,6 +1,6 @@
import {Component, ViewEncapsulation} from '@angular/core';
import {MatSidenavModule} from "@angular/material/sidenav";
import {Router, RouterOutlet} from "@angular/router";
import {ActivatedRoute, Router, RouterOutlet} from "@angular/router";
import {MatCard} from "@angular/material/card";
import {MatButton} from "@angular/material/button";
import {NavigationService} from "@service/navigation.service";
@ -30,20 +30,29 @@ export class SetupComponent {
protected skipButtonDisabled: boolean = false;
protected loaderActive: boolean = false;
protected routes: Array<string> = ['', 'welcome', 'database', 'cache', 'password-policy', 'schedule', 'logging', 'create-admin', 'two-factor', 'summary'];
protected routes: Array<string> = ['', 'welcome', 'create-admin', 'database', 'cache', 'password-policy', 'schedule', 'logging', 'two-factor', 'summary'];
private index: number = 1;
protected get getIndex() {
return this.index;
}
constructor(private router: Router, private navigationService: NavigationService, api: SetupService, private notify: ToastrService) {
constructor(private route: ActivatedRoute,
private router: Router,
private navigationService: NavigationService,
api: SetupService,
private notify: ToastrService) {
api.isConfigured().subscribe(x => {
if (x) this.router.navigate(['/']).then();
});
if (!this.router.url.includes(this.routes[this.index])) {
this.router.navigate(['setup/', this.routes[this.index]]).then();
const currentQueryParams = this.route.snapshot.queryParams;
this.router.navigate(
['setup/', this.routes[this.index]],
{queryParams: currentQueryParams}
).then();
}
this.initializeButtonSubscriptions();
@ -104,13 +113,25 @@ export class SetupComponent {
this.moveToPreviousPage();
}
private moveToNextPage() {
private moveToNextPage(): void {
if (this.index < this.routes.length - 1) {
this.index++;
this.router.navigate(['setup/', this.routes[this.index]]).then();
this.initializePage();
const currentQueryParams = this.route.snapshot.queryParams;
this.router.navigate(
['setup/', this.routes[this.index]],
{queryParams: currentQueryParams}
).then(() => {
this.initializePage();
});
} else {
this.router.navigate(['/']).then();
const currentQueryParams = this.route.snapshot.queryParams;
this.router.navigate(
['/'],
{queryParams: currentQueryParams}
).then();
}
}