fix server show type errors

This commit is contained in:
Matt Hill
2023-07-26 11:39:20 -06:00
parent da37d649ec
commit 180589144a
3 changed files with 41 additions and 41 deletions

View File

@@ -21,6 +21,11 @@ import {
GenericInputComponent, GenericInputComponent,
GenericInputOptions, GenericInputOptions,
} from 'src/app/apps/ui/modals/generic-input/generic-input.component' } from 'src/app/apps/ui/modals/generic-input/generic-input.component'
import { FormDialogService } from 'src/app/services/form-dialog.service'
import { FormPage } from '../../../modals/form/form.page'
import { Config } from '@start9labs/start-sdk/lib/config/builder/config'
import { Value } from '@start9labs/start-sdk/lib/config/builder/value'
import { configBuilderToSpec } from 'src/app/util/configBuilderToSpec'
import { ConfigService } from 'src/app/services/config.service' import { ConfigService } from 'src/app/services/config.service'
import { DOCUMENT } from '@angular/common' import { DOCUMENT } from '@angular/common'
import { getServerInfo } from 'src/app/util/get-server-info' import { getServerInfo } from 'src/app/util/get-server-info'
@@ -57,6 +62,7 @@ export class ServerShowPage {
private readonly authService: AuthService, private readonly authService: AuthService,
private readonly toastCtrl: ToastController, private readonly toastCtrl: ToastController,
private readonly config: ConfigService, private readonly config: ConfigService,
private readonly formDialog: FormDialogService,
@Inject(DOCUMENT) private readonly document: Document, @Inject(DOCUMENT) private readonly document: Document,
) {} ) {}
@@ -121,44 +127,36 @@ export class ServerShowPage {
} }
async presentModalResetPassword(): Promise<void> { async presentModalResetPassword(): Promise<void> {
const modal = await this.modalCtrl.create({ this.formDialog.open(FormPage, {
component: GenericFormPage, label: 'Change Master Password',
componentProps: { data: {
title: 'Change Master Password', spec: await configBuilderToSpec(passwordSpec),
spec: PasswordSpec,
buttons: [ buttons: [
{ {
text: 'Save', text: 'Save',
handler: (value: any) => { handler: (value: PasswordSpec) => this.resetPassword(value),
return this.resetPassword(value)
},
isSubmit: true,
}, },
], ],
}, },
}) })
await modal.present()
} }
private async resetPassword(value: { private async resetPassword(value: PasswordSpec): Promise<boolean> {
currPass: string console.log(value)
newPass: string
newPass2: string
}): Promise<boolean> {
let err = '' let err = ''
if (value.newPass !== value.newPass2) { if (value.newPassword1 !== value.newPassword2) {
err = 'New passwords do not match' err = 'New passwords do not match'
} else if (value.newPass.length < 12) { } else if (value.newPassword1.length < 12) {
err = 'New password must be 12 characters or greater' err = 'New password must be 12 characters or greater'
} else if (value.newPass.length > 64) { } else if (value.newPassword1.length > 64) {
err = 'New password must be less than 65 characters' err = 'New password must be less than 65 characters'
} }
// confirm current password is correct // confirm current password is correct
const { 'password-hash': passwordHash } = await getServerInfo(this.patch) const { 'password-hash': passwordHash } = await getServerInfo(this.patch)
try { try {
argon2.verify(passwordHash, value.currPass) argon2.verify(passwordHash, value.currentPassword)
} catch (e) { } catch (e) {
err = 'Current password is invalid' err = 'Current password is invalid'
} }
@@ -175,8 +173,8 @@ export class ServerShowPage {
try { try {
await this.embassyApi.resetPassword({ await this.embassyApi.resetPassword({
'old-password': value.currPass, 'old-password': value.currentPassword,
'new-password': value.newPass, 'new-password': value.newPassword1,
}) })
const toast = await this.toastCtrl.create({ const toast = await this.toastCtrl.create({
header: 'Password changed!', header: 'Password changed!',
@@ -721,29 +719,28 @@ interface SettingBtn {
disabled$: Observable<boolean> disabled$: Observable<boolean>
} }
const PasswordSpec: ConfigSpec = { export const passwordSpec = Config.of({
currPass: { currentPassword: Value.text({
type: 'string',
name: 'Current Password', name: 'Current Password',
placeholder: 'CurrentPass', required: {
nullable: false, default: null,
},
masked: true, masked: true,
copyable: false, }),
}, newPassword1: Value.text({
newPass: {
type: 'string',
name: 'New Password', name: 'New Password',
placeholder: 'NewPass', required: {
nullable: false, default: null,
},
masked: true, masked: true,
copyable: false, }),
}, newPassword2: Value.text({
newPass2: {
type: 'string',
name: 'Retype New Password', name: 'Retype New Password',
placeholder: 'NewPass', required: {
nullable: false, default: null,
},
masked: true, masked: true,
copyable: false, }),
}, })
}
type PasswordSpec = typeof passwordSpec.validator._TYPE

View File

@@ -73,6 +73,8 @@ export const mockPatchData: DataModel = {
password: '', password: '',
tls: true, tls: true,
}, },
'password-hash':
'$argon2d$v=19$m=1024,t=1,p=1$YXNkZmFzZGZhc2RmYXNkZg$Ceev1I901G6UwU+hY0sHrFZ56D+o+LNJ',
}, },
'package-data': { 'package-data': {
bitcoind: Mock.bitcoind, bitcoind: Mock.bitcoind,

View File

@@ -69,6 +69,7 @@ export interface ServerInfo {
'system-start-time': string 'system-start-time': string
zram: boolean zram: boolean
smtp: typeof customSmtp.validator._TYPE smtp: typeof customSmtp.validator._TYPE
'password-hash': string
} }
export interface IpInfo { export interface IpInfo {