diff --git a/src/components/OAuthProviders/OAuthProviders.ts b/src/components/OAuthProviders/OAuthProviders.ts index a39360c..01ae8b5 100644 --- a/src/components/OAuthProviders/OAuthProviders.ts +++ b/src/components/OAuthProviders/OAuthProviders.ts @@ -1,4 +1,4 @@ -import {Component, Inject, Input, OnInit} from '@angular/core'; +import {Component, EventEmitter, Inject, Input, Output} from '@angular/core'; import AuthApiService, {OAuthProviderData} from "@api/v1/authApiService"; import {OAuthProvider} from "@model/oAuthProvider"; import {ToastrService} from "ngx-toastr"; @@ -62,7 +62,7 @@ export class DeleteConfirmDialog { styleUrl: './OAuthProviders.css', providers: [AuthApiService] }) -export class OAuthProviders implements OnInit { +export class OAuthProviders { protected providers: AvailableOAuthProviders[] = []; protected _activeProvidersId: OAuthProvider[] = []; protected _activeProviders: string[] = []; @@ -81,6 +81,8 @@ export class OAuthProviders implements OnInit { @Input() canUnlink: boolean = false; + @Output() public oAuthUpdateProviders = new EventEmitter(); + constructor(authApi: AuthApiService, private notify: ToastrService, private dialog: MatDialog) { authApi.availableProviders().subscribe(providers => this.updateDisabledProviders(providers)); } @@ -95,18 +97,6 @@ export class OAuthProviders implements OnInit { }); } - ngOnInit(): void { - window.addEventListener('message', (event) => { - if (event.data && event.data.success === false) { - console.error(event.data.message); - this.notify.error(event.data.message, 'OAuth ошибка'); - } else { - this.activeProvidersId.push(event.data.provider); - this.updateDisabledProviders(); - } - }); - } - protected openOAuth(provider: AvailableOAuthProviders) { console.log(provider.redirect); const oauthWindow = window.open( @@ -120,6 +110,14 @@ export class OAuthProviders implements OnInit { } provider.active = true; + + const checkInterval = setInterval(() => { + if (oauthWindow.closed) { + clearInterval(checkInterval); + this.oAuthUpdateProviders.emit(); + provider.active = false; + } + }, 1500); } protected confirmDelete(provider: AvailableOAuthProviders) { diff --git a/src/pages/setup/create-admin/create-admin.component.html b/src/pages/setup/create-admin/create-admin.component.html index d4f2448..e650d88 100644 --- a/src/pages/setup/create-admin/create-admin.component.html +++ b/src/pages/setup/create-admin/create-admin.component.html @@ -116,7 +116,7 @@ } - diff --git a/src/pages/setup/create-admin/create-admin.component.ts b/src/pages/setup/create-admin/create-admin.component.ts index 4dddd93..1582cba 100644 --- a/src/pages/setup/create-admin/create-admin.component.ts +++ b/src/pages/setup/create-admin/create-admin.component.ts @@ -70,10 +70,17 @@ export class CreateAdminComponent { this.createAdminForm.get('password')?.updateValueAndValidity(); }); + this.updateAdminData(); + } + + private updateAdminData() { this.api.adminConfiguration().subscribe(configuration => { if (configuration) { - this.createAdminForm.get('email')?.setValue(configuration.email); - this.createAdminForm.get('user')?.setValue(configuration.username); + if (this.createAdminForm.get('email')?.value == 0) + this.createAdminForm.get('email')?.setValue(configuration.email); + + if (this.createAdminForm.get('user')?.value == 0) + this.createAdminForm.get('user')?.setValue(configuration.username); this.activatedProviders = configuration.usedOAuthProviders; } @@ -111,4 +118,8 @@ export class CreateAdminComponent { this.hideRetypePass = !this.hideRetypePass; event.stopPropagation(); } + + protected updateProviders() { + this.updateAdminData(); + } }