webapp: create interface for SecurityConfig

This commit is contained in:
Thomas Basler 2022-10-17 20:07:48 +02:00
parent 05eb741833
commit 61924a2768
2 changed files with 10 additions and 9 deletions

View File

@ -0,0 +1,3 @@
export interface SecurityConfig {
password: string
}

View File

@ -22,7 +22,7 @@
<label for="inputPassword" class="col-sm-2 col-form-label">Password:</label> <label for="inputPassword" class="col-sm-2 col-form-label">Password:</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword" maxlength="64" <input type="password" class="form-control" id="inputPassword" maxlength="64"
placeholder="Password" v-model="password" /> placeholder="Password" v-model="securityConfigList.password" />
</div> </div>
</div> </div>
@ -51,6 +51,7 @@
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import BootstrapAlert from "@/components/BootstrapAlert.vue"; import BootstrapAlert from "@/components/BootstrapAlert.vue";
import type { SecurityConfig } from '@/types/SecurityConfig';
export default defineComponent({ export default defineComponent({
components: { components: {
@ -63,7 +64,7 @@ export default defineComponent({
alertType: "info", alertType: "info",
showAlert: false, showAlert: false,
password: "", securityConfigList: {} as SecurityConfig,
passwordRepeat: "", passwordRepeat: "",
}; };
}, },
@ -77,8 +78,8 @@ export default defineComponent({
.then((response) => response.json()) .then((response) => response.json())
.then( .then(
(data) => { (data) => {
this.password = data["password"]; this.securityConfigList = data;
this.passwordRepeat = this.password; this.passwordRepeat = this.securityConfigList.password;
this.dataLoading = false; this.dataLoading = false;
} }
); );
@ -86,7 +87,7 @@ export default defineComponent({
savePasswordConfig(e: Event) { savePasswordConfig(e: Event) {
e.preventDefault(); e.preventDefault();
if (this.password != this.passwordRepeat) { if (this.securityConfigList.password != this.passwordRepeat) {
this.alertMessage = "Passwords are not equal"; this.alertMessage = "Passwords are not equal";
this.alertType = "warning"; this.alertType = "warning";
this.showAlert = true; this.showAlert = true;
@ -94,10 +95,7 @@ export default defineComponent({
} }
const formData = new FormData(); const formData = new FormData();
const data = { formData.append("data", JSON.stringify(this.securityConfigList));
password: this.password
}
formData.append("data", JSON.stringify(data));
fetch("/api/security/password", { fetch("/api/security/password", {
method: "POST", method: "POST",