2021-09-09 15:10:31 -04:00
|
|
|
<template>
|
|
|
|
<form @submit.prevent="submit">
|
|
|
|
<div ref="modal" class="modal fade" tabindex="-1" data-bs-backdrop="static">
|
|
|
|
<div class="modal-dialog">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<h5 class="modal-title">
|
|
|
|
{{ $t("Setup 2FA") }}
|
|
|
|
<span v-if="twoFAStatus == true" class="badge bg-primary">{{ $t("Active") }}</span>
|
|
|
|
<span v-if="twoFAStatus == false" class="badge bg-primary">{{ $t("Inactive") }}</span>
|
|
|
|
</h5>
|
|
|
|
<button :disabled="processing" type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" />
|
|
|
|
</div>
|
|
|
|
<div class="modal-body">
|
|
|
|
<div class="mb-3">
|
|
|
|
<div v-if="uri && twoFAStatus == false" class="mx-auto text-center" style="width: 210px;">
|
|
|
|
<vue-qrcode :key="uri" :value="uri" type="image/png" :quality="1" :color="{ light: '#ffffffff' }" />
|
2021-09-09 19:33:26 -04:00
|
|
|
<button v-show="!showURI" type="button" class="btn btn-outline-primary btn-sm mt-2" @click="showURI = true">{{ $t("Show URI") }}</button>
|
2021-09-09 15:10:31 -04:00
|
|
|
</div>
|
|
|
|
<p v-if="showURI && twoFAStatus == false" class="text-break mt-2">{{ uri }}</p>
|
|
|
|
|
2022-03-29 05:38:48 -04:00
|
|
|
<div v-if="!(uri && twoFAStatus == false)" class="mb-3">
|
|
|
|
<label for="current-password" class="form-label">
|
|
|
|
{{ $t("Current Password") }}
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
id="current-password"
|
|
|
|
v-model="currentPassword"
|
|
|
|
type="password"
|
|
|
|
class="form-control"
|
|
|
|
required
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2021-09-09 15:10:31 -04:00
|
|
|
<button v-if="uri == null && twoFAStatus == false" class="btn btn-primary" type="button" @click="prepare2FA()">
|
|
|
|
{{ $t("Enable 2FA") }}
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button v-if="twoFAStatus == true" class="btn btn-danger" type="button" :disabled="processing" @click="confirmDisableTwoFA()">
|
|
|
|
{{ $t("Disable 2FA") }}
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<div v-if="uri && twoFAStatus == false" class="mt-3">
|
|
|
|
<label for="basic-url" class="form-label">{{ $t("twoFAVerifyLabel") }}</label>
|
|
|
|
<div class="input-group">
|
2021-09-09 16:08:34 -04:00
|
|
|
<input v-model="token" type="text" maxlength="6" class="form-control">
|
2021-09-09 15:10:31 -04:00
|
|
|
<button class="btn btn-outline-primary" type="button" @click="verifyToken()">{{ $t("Verify Token") }}</button>
|
|
|
|
</div>
|
2022-04-13 12:52:07 -04:00
|
|
|
<p v-show="tokenValid" class="mt-2" style="color: green;">{{ $t("tokenValidSettingsMsg") }}</p>
|
2021-09-09 15:10:31 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2021-09-09 15:38:39 -04:00
|
|
|
<div v-if="uri && twoFAStatus == false" class="modal-footer">
|
2021-09-09 15:10:31 -04:00
|
|
|
<button type="submit" class="btn btn-primary" :disabled="processing || tokenValid == false" @click="confirmEnableTwoFA()">
|
|
|
|
<div v-if="processing" class="spinner-border spinner-border-sm me-1"></div>
|
|
|
|
{{ $t("Save") }}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<Confirm ref="confirmEnableTwoFA" btn-style="btn-danger" :yes-text="$t('Yes')" :no-text="$t('No')" @yes="save2FA">
|
|
|
|
{{ $t("confirmEnableTwoFAMsg") }}
|
|
|
|
</Confirm>
|
|
|
|
|
|
|
|
<Confirm ref="confirmDisableTwoFA" btn-style="btn-danger" :yes-text="$t('Yes')" :no-text="$t('No')" @yes="disable2FA">
|
|
|
|
{{ $t("confirmDisableTwoFAMsg") }}
|
|
|
|
</Confirm>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2022-03-29 05:38:48 -04:00
|
|
|
import { Modal } from "bootstrap";
|
2021-09-09 15:10:31 -04:00
|
|
|
import Confirm from "./Confirm.vue";
|
2022-03-29 05:38:48 -04:00
|
|
|
import VueQrcode from "vue-qrcode";
|
|
|
|
import { useToast } from "vue-toastification";
|
|
|
|
const toast = useToast();
|
2021-09-09 15:10:31 -04:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
Confirm,
|
|
|
|
VueQrcode,
|
|
|
|
},
|
|
|
|
props: {},
|
|
|
|
data() {
|
|
|
|
return {
|
2022-03-29 05:38:48 -04:00
|
|
|
currentPassword: "",
|
2021-09-09 15:10:31 -04:00
|
|
|
processing: false,
|
|
|
|
uri: null,
|
|
|
|
tokenValid: false,
|
|
|
|
twoFAStatus: null,
|
|
|
|
token: null,
|
|
|
|
showURI: false,
|
2022-03-29 05:38:48 -04:00
|
|
|
};
|
2021-09-09 15:10:31 -04:00
|
|
|
},
|
|
|
|
mounted() {
|
2022-03-29 05:38:48 -04:00
|
|
|
this.modal = new Modal(this.$refs.modal);
|
2021-09-09 15:10:31 -04:00
|
|
|
this.getStatus();
|
|
|
|
},
|
|
|
|
methods: {
|
2022-06-01 19:32:05 -04:00
|
|
|
/** Show the dialog */
|
2021-09-09 15:10:31 -04:00
|
|
|
show() {
|
2022-03-29 05:38:48 -04:00
|
|
|
this.modal.show();
|
2021-09-09 15:10:31 -04:00
|
|
|
},
|
|
|
|
|
2022-06-01 19:32:05 -04:00
|
|
|
/** Show dialog to confirm enabling 2FA */
|
2021-09-09 15:10:31 -04:00
|
|
|
confirmEnableTwoFA() {
|
2022-03-29 05:38:48 -04:00
|
|
|
this.$refs.confirmEnableTwoFA.show();
|
2021-09-09 15:10:31 -04:00
|
|
|
},
|
|
|
|
|
2022-06-01 19:32:05 -04:00
|
|
|
/** Show dialog to confirm disabling 2FA */
|
2021-09-09 15:10:31 -04:00
|
|
|
confirmDisableTwoFA() {
|
2022-03-29 05:38:48 -04:00
|
|
|
this.$refs.confirmDisableTwoFA.show();
|
2021-09-09 15:10:31 -04:00
|
|
|
},
|
|
|
|
|
2022-06-01 19:32:05 -04:00
|
|
|
/** Prepare 2FA configuration */
|
2021-09-09 15:10:31 -04:00
|
|
|
prepare2FA() {
|
|
|
|
this.processing = true;
|
|
|
|
|
2022-03-29 05:38:48 -04:00
|
|
|
this.$root.getSocket().emit("prepare2FA", this.currentPassword, (res) => {
|
2021-09-09 15:10:31 -04:00
|
|
|
this.processing = false;
|
|
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
this.uri = res.uri;
|
|
|
|
} else {
|
|
|
|
toast.error(res.msg);
|
|
|
|
}
|
2022-03-29 05:38:48 -04:00
|
|
|
});
|
2021-09-09 15:10:31 -04:00
|
|
|
},
|
|
|
|
|
2022-06-01 19:32:05 -04:00
|
|
|
/** Save the current 2FA configuration */
|
2021-09-09 15:10:31 -04:00
|
|
|
save2FA() {
|
|
|
|
this.processing = true;
|
|
|
|
|
2022-03-29 05:38:48 -04:00
|
|
|
this.$root.getSocket().emit("save2FA", this.currentPassword, (res) => {
|
2021-09-09 15:10:31 -04:00
|
|
|
this.processing = false;
|
|
|
|
|
|
|
|
if (res.ok) {
|
2022-03-29 05:38:48 -04:00
|
|
|
this.$root.toastRes(res);
|
2021-09-09 15:10:31 -04:00
|
|
|
this.getStatus();
|
2022-03-29 05:38:48 -04:00
|
|
|
this.currentPassword = "";
|
2021-09-09 15:10:31 -04:00
|
|
|
this.modal.hide();
|
|
|
|
} else {
|
|
|
|
toast.error(res.msg);
|
|
|
|
}
|
2022-03-29 05:38:48 -04:00
|
|
|
});
|
2021-09-09 15:10:31 -04:00
|
|
|
},
|
|
|
|
|
2022-06-01 19:32:05 -04:00
|
|
|
/** Disable 2FA for this user */
|
2021-09-09 15:10:31 -04:00
|
|
|
disable2FA() {
|
|
|
|
this.processing = true;
|
|
|
|
|
2022-03-29 05:38:48 -04:00
|
|
|
this.$root.getSocket().emit("disable2FA", this.currentPassword, (res) => {
|
2021-09-09 15:10:31 -04:00
|
|
|
this.processing = false;
|
|
|
|
|
|
|
|
if (res.ok) {
|
2022-03-29 05:38:48 -04:00
|
|
|
this.$root.toastRes(res);
|
2021-09-09 15:10:31 -04:00
|
|
|
this.getStatus();
|
2022-03-29 05:38:48 -04:00
|
|
|
this.currentPassword = "";
|
2021-09-09 15:10:31 -04:00
|
|
|
this.modal.hide();
|
|
|
|
} else {
|
|
|
|
toast.error(res.msg);
|
|
|
|
}
|
2022-03-29 05:38:48 -04:00
|
|
|
});
|
2021-09-09 15:10:31 -04:00
|
|
|
},
|
|
|
|
|
2022-06-01 19:32:05 -04:00
|
|
|
/** Verify the token generated by the user */
|
2021-09-09 15:10:31 -04:00
|
|
|
verifyToken() {
|
2022-03-29 05:38:48 -04:00
|
|
|
this.$root.getSocket().emit("verifyToken", this.token, this.currentPassword, (res) => {
|
2021-09-09 15:10:31 -04:00
|
|
|
if (res.ok) {
|
|
|
|
this.tokenValid = res.valid;
|
|
|
|
} else {
|
|
|
|
toast.error(res.msg);
|
|
|
|
}
|
2022-03-29 05:38:48 -04:00
|
|
|
});
|
2021-09-09 15:10:31 -04:00
|
|
|
},
|
|
|
|
|
2022-06-01 19:32:05 -04:00
|
|
|
/** Get current status of 2FA */
|
2021-09-09 15:10:31 -04:00
|
|
|
getStatus() {
|
|
|
|
this.$root.getSocket().emit("twoFAStatus", (res) => {
|
|
|
|
if (res.ok) {
|
|
|
|
this.twoFAStatus = res.status;
|
|
|
|
} else {
|
|
|
|
toast.error(res.msg);
|
|
|
|
}
|
2022-03-29 05:38:48 -04:00
|
|
|
});
|
2021-09-09 15:10:31 -04:00
|
|
|
},
|
|
|
|
},
|
2022-03-29 05:38:48 -04:00
|
|
|
};
|
2021-09-09 15:10:31 -04:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
@import "../assets/vars.scss";
|
|
|
|
|
|
|
|
.dark {
|
|
|
|
.modal-dialog .form-text, .modal-dialog p {
|
|
|
|
color: $dark-font-color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|