2026-01-28 22:37:47 +03:00
|
|
|
<template>
|
|
|
|
|
<div class="user-account-container mx-auto" style="max-width: 1000px;">
|
|
|
|
|
<div class="row g-4">
|
|
|
|
|
<!-- Security Card -->
|
|
|
|
|
<div class="col-lg-6">
|
|
|
|
|
<div class="card h-100">
|
2026-01-29 22:48:57 +03:00
|
|
|
<div class="card-header seccard d-flex justify-content-between align-items-center">
|
2026-01-28 22:37:47 +03:00
|
|
|
<span><i class="fas fa-user-shield me-2"></i>Security Settings</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="card-body p-4">
|
|
|
|
|
<div class="text-center py-4 d-flex flex-column align-items-center">
|
|
|
|
|
<div class="card-interior-icon">
|
|
|
|
|
<i class="fas fa-user-check fa-3x text-primary"></i>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="card-interior-title">
|
|
|
|
|
<h4 class="m-0 text-heading">Update Credentials</h4>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="card-interior-description">
|
|
|
|
|
<p class="text-muted m-0">Maintain your account security by updating your password regularly to prevent unauthorized access.</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<button class="btn btn-action btn-action-primary py-2 fw-bold btn-account-action" @click="showPwModal">
|
|
|
|
|
Change Password
|
|
|
|
|
</button>
|
2026-09-30 12:03:36 +00:00
|
|
|
<button class="btn btn-action btn-action-secondary py-2 fw-bold btn-account-action mt-2" @click="showUserModal">
|
|
|
|
|
Change Username
|
|
|
|
|
</button>
|
2026-01-28 22:37:47 +03:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- 2FA Card -->
|
|
|
|
|
<div class="col-lg-6">
|
|
|
|
|
<div class="card p-0 h-100">
|
2026-01-29 22:48:57 +03:00
|
|
|
<div class="card-header seccard d-flex justify-content-between align-items-center">
|
2026-01-28 22:37:47 +03:00
|
|
|
<span><i class="fas fa-key me-2"></i>Two-Factor Authentication</span>
|
|
|
|
|
<span v-if="isEnabled" class="status-badge status-valid">
|
|
|
|
|
<i class="fas fa-check-circle me-1"></i>Active
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="card-body p-4">
|
|
|
|
|
<div v-if="!isEnabled">
|
|
|
|
|
<div v-if="!step2" class="text-center py-4 d-flex flex-column align-items-center">
|
|
|
|
|
<div class="card-interior-icon">
|
|
|
|
|
<i class="fas fa-shield-alt fa-3x text-primary"></i>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="card-interior-title">
|
|
|
|
|
<h4 class="m-0 text-heading">Secure Your Account</h4>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="card-interior-description">
|
|
|
|
|
<p class="text-muted m-0">Protect your OpenVPN Monitor dashboard with second-layer security using Google Authenticator or any TOTP app.</p>
|
|
|
|
|
</div>
|
|
|
|
|
<button class="btn btn-action btn-action-primary py-2 fw-bold btn-account-action" @click="initSetup" :disabled="loading">
|
|
|
|
|
<span v-if="loading" class="spinner-border spinner-border-sm me-2"></span>
|
|
|
|
|
Start Setup
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div v-else class="setup-steps fade-in">
|
|
|
|
|
<div class="step-item mb-5 text-center">
|
|
|
|
|
<h5 class="mb-3 text-heading">1. Scan the QR Code</h5>
|
|
|
|
|
<p class="text-muted small mb-4">Open your authenticator app and scan this code or manually enter the secret.</p>
|
|
|
|
|
|
|
|
|
|
<div class="qr-setup-container mx-auto">
|
|
|
|
|
<div class="qr-code-wrapper p-3 d-inline-block rounded shadow-sm bg-white">
|
|
|
|
|
<qrcode-vue :value="setupData.uri" :size="150" level="H" :background="'#ffffff'" foreground="#24292f" />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="secret-box mt-3">
|
|
|
|
|
<div class="small fw-bold text-muted mb-2">Manual Secret:</div>
|
|
|
|
|
<div class="user-select-all font-monospace p-2 secret-value-box rounded small d-inline-block w-100">
|
|
|
|
|
{{ setupData.secret }}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="step-item text-center">
|
|
|
|
|
<h5 class="mb-3 text-heading">2. Verify Connection</h5>
|
|
|
|
|
<div class="verification-group mx-auto" style="max-width: 300px;">
|
|
|
|
|
<div class="input-group mb-3 shadow-sm rounded">
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
class="form-control text-center fw-bold"
|
|
|
|
|
v-model="otp"
|
|
|
|
|
placeholder="000000"
|
|
|
|
|
maxlength="6"
|
|
|
|
|
>
|
|
|
|
|
<button class="btn btn-action btn-action-primary px-4 fw-bold" @click="verifyAndEnable" :disabled="loading">
|
|
|
|
|
<span v-if="loading" class="spinner-border spinner-border-sm me-2"></span>
|
|
|
|
|
Enable
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div v-else class="text-center py-4 d-flex flex-column align-items-center">
|
|
|
|
|
<div class="card-interior-icon">
|
|
|
|
|
<i class="fas fa-key fa-3x text-primary"></i>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="card-interior-title">
|
|
|
|
|
<h4 class="m-0 text-heading">2FA is Enabled</h4>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="card-interior-description">
|
|
|
|
|
<p class="text-muted m-0">Your dashboard is now protected with two-factor authentication.</p>
|
|
|
|
|
</div>
|
|
|
|
|
<button class="btn btn-action btn-action-danger py-2 fw-bold btn-account-action" @click="disableConfirm">
|
|
|
|
|
<i class="fas fa-ban me-2"></i>Disable 2FA
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Alerts/Notifications Modal -->
|
|
|
|
|
<ConfirmModal ref="confirmModal" />
|
|
|
|
|
|
|
|
|
|
<!-- Action Confirmations Modal -->
|
|
|
|
|
<ConfirmModal ref="disable2FAModal" @confirm="handleDisable2FA" />
|
|
|
|
|
|
|
|
|
|
<!-- Password Change Modal -->
|
|
|
|
|
<BaseModal id="passwordChangeModal" title="Change Account Password" ref="pwModal">
|
|
|
|
|
<template #body>
|
|
|
|
|
<form @submit.prevent="handleChangePassword" id="pwForm">
|
|
|
|
|
<div class="mb-3">
|
|
|
|
|
<label class="form-label small fw-bold text-muted text-uppercase">Current Password</label>
|
|
|
|
|
<input
|
|
|
|
|
type="password"
|
|
|
|
|
class="form-control"
|
|
|
|
|
v-model="passwordForm.current_password"
|
|
|
|
|
placeholder="Enter current password"
|
|
|
|
|
required
|
|
|
|
|
>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="mb-3">
|
|
|
|
|
<label class="form-label small fw-bold text-muted text-uppercase">New Password</label>
|
|
|
|
|
<input
|
|
|
|
|
type="password"
|
|
|
|
|
class="form-control"
|
|
|
|
|
v-model="passwordForm.new_password"
|
|
|
|
|
placeholder="Min. 8 characters"
|
|
|
|
|
required
|
|
|
|
|
>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="mb-2">
|
|
|
|
|
<label class="form-label small fw-bold text-muted text-uppercase">Confirm New Password</label>
|
|
|
|
|
<input
|
|
|
|
|
type="password"
|
|
|
|
|
class="form-control"
|
|
|
|
|
v-model="passwordForm.confirm_password"
|
|
|
|
|
placeholder="Confirm new password"
|
|
|
|
|
required
|
|
|
|
|
>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</template>
|
|
|
|
|
<template #footer>
|
|
|
|
|
<button type="button" class="btn-action btn-action-secondary" @click="pwModal.hide()">Cancel</button>
|
|
|
|
|
<button type="submit" form="pwForm" class="btn-action btn-action-save" :disabled="pwLoading">
|
|
|
|
|
<span v-if="pwLoading" class="spinner-border spinner-border-sm me-2"></span>
|
|
|
|
|
Update Password
|
|
|
|
|
</button>
|
|
|
|
|
</template>
|
|
|
|
|
</BaseModal>
|
2026-09-30 12:03:36 +00:00
|
|
|
|
|
|
|
|
<!-- Username Change Modal -->
|
|
|
|
|
<BaseModal id="usernameChangeModal" title="Change Account Username" ref="userModal">
|
|
|
|
|
<template #body>
|
|
|
|
|
<form @submit.prevent="handleChangeUsername" id="userForm">
|
|
|
|
|
<div class="mb-3">
|
|
|
|
|
<label class="form-label small fw-bold text-muted text-uppercase">New Username</label>
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
class="form-control"
|
|
|
|
|
v-model="usernameForm.new_username"
|
|
|
|
|
placeholder="3-32 chars: letters, digits, . _ -"
|
|
|
|
|
pattern="[A-Za-z][A-Za-z0-9_.\-]{2,31}"
|
|
|
|
|
autocomplete="off"
|
|
|
|
|
required
|
|
|
|
|
>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="mb-3">
|
|
|
|
|
<label class="form-label small fw-bold text-muted text-uppercase">Current Password</label>
|
|
|
|
|
<input
|
|
|
|
|
type="password"
|
|
|
|
|
class="form-control"
|
|
|
|
|
v-model="usernameForm.current_password"
|
|
|
|
|
placeholder="Enter current password"
|
|
|
|
|
required
|
|
|
|
|
>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="mb-2" v-if="isEnabled">
|
|
|
|
|
<label class="form-label small fw-bold text-muted text-uppercase">2FA Code</label>
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
class="form-control"
|
|
|
|
|
v-model="usernameForm.otp"
|
|
|
|
|
placeholder="6-digit code"
|
|
|
|
|
inputmode="numeric"
|
|
|
|
|
autocomplete="one-time-code"
|
|
|
|
|
required
|
|
|
|
|
>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</template>
|
|
|
|
|
<template #footer>
|
|
|
|
|
<button type="button" class="btn-action btn-action-secondary" @click="userModal.hide()">Cancel</button>
|
|
|
|
|
<button type="submit" form="userForm" class="btn-action btn-action-save" :disabled="userLoading">
|
|
|
|
|
<span v-if="userLoading" class="spinner-border spinner-border-sm me-2"></span>
|
|
|
|
|
Update Username
|
|
|
|
|
</button>
|
|
|
|
|
</template>
|
|
|
|
|
</BaseModal>
|
2026-01-28 22:37:47 +03:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
import { ref, onMounted, reactive } from 'vue';
|
|
|
|
|
import { useApi } from '../composables/useApi';
|
|
|
|
|
import QrcodeVue from 'qrcode.vue';
|
|
|
|
|
import Swal from 'sweetalert2';
|
|
|
|
|
import BaseModal from '../components/BaseModal.vue';
|
|
|
|
|
import ConfirmModal from '../components/ConfirmModal.vue';
|
|
|
|
|
|
|
|
|
|
const { apiClient } = useApi();
|
|
|
|
|
|
|
|
|
|
// UI Refs
|
|
|
|
|
const pwModal = ref(null);
|
2026-09-30 12:03:36 +00:00
|
|
|
const userModal = ref(null);
|
2026-01-28 22:37:47 +03:00
|
|
|
const confirmModal = ref(null);
|
|
|
|
|
const disable2FAModal = ref(null);
|
|
|
|
|
|
|
|
|
|
// Password Logic
|
|
|
|
|
const pwLoading = ref(false);
|
|
|
|
|
const passwordForm = reactive({
|
|
|
|
|
current_password: '',
|
|
|
|
|
new_password: '',
|
|
|
|
|
confirm_password: ''
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const showPwModal = () => {
|
|
|
|
|
passwordForm.current_password = '';
|
|
|
|
|
passwordForm.new_password = '';
|
|
|
|
|
passwordForm.confirm_password = '';
|
|
|
|
|
pwModal.value.show();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleChangePassword = async () => {
|
|
|
|
|
if (passwordForm.new_password !== passwordForm.confirm_password) {
|
|
|
|
|
Swal.fire({
|
|
|
|
|
title: 'Error!',
|
|
|
|
|
text: 'New passwords do not match',
|
|
|
|
|
icon: 'error',
|
|
|
|
|
confirmButtonColor: '#EC7C31'
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pwLoading.value = true;
|
|
|
|
|
try {
|
|
|
|
|
await apiClient.post('../auth/change-password', {
|
|
|
|
|
current_password: passwordForm.current_password,
|
|
|
|
|
new_password: passwordForm.new_password
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
pwModal.value.hide();
|
|
|
|
|
Swal.fire({
|
|
|
|
|
title: 'Success!',
|
|
|
|
|
text: 'Password updated successfully.',
|
|
|
|
|
icon: 'success',
|
|
|
|
|
confirmButtonColor: '#1652B8'
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
Swal.fire({
|
|
|
|
|
title: 'Failed',
|
|
|
|
|
text: err.response?.data?.error || 'Failed to update password',
|
|
|
|
|
icon: 'error',
|
|
|
|
|
confirmButtonColor: '#cf222e'
|
|
|
|
|
});
|
|
|
|
|
} finally {
|
|
|
|
|
pwLoading.value = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-09-30 12:03:36 +00:00
|
|
|
// Username Logic
|
|
|
|
|
const userLoading = ref(false);
|
|
|
|
|
const usernameForm = reactive({ new_username: '', current_password: '', otp: '' });
|
|
|
|
|
|
|
|
|
|
const showUserModal = () => {
|
|
|
|
|
usernameForm.new_username = '';
|
|
|
|
|
usernameForm.current_password = '';
|
|
|
|
|
usernameForm.otp = '';
|
|
|
|
|
userModal.value.show();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleChangeUsername = async () => {
|
|
|
|
|
if (!/^[A-Za-z][A-Za-z0-9_.-]{2,31}$/.test(usernameForm.new_username)) {
|
|
|
|
|
Swal.fire({
|
|
|
|
|
title: 'Error!',
|
|
|
|
|
text: 'Username must be 3-32 chars, start with a letter, and contain only letters, digits, . _ -',
|
|
|
|
|
icon: 'error',
|
|
|
|
|
confirmButtonColor: '#EC7C31'
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userLoading.value = true;
|
|
|
|
|
try {
|
|
|
|
|
const res = await apiClient.post('../auth/change-username', {
|
|
|
|
|
new_username: usernameForm.new_username,
|
|
|
|
|
current_password: usernameForm.current_password,
|
|
|
|
|
otp: usernameForm.otp || undefined
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
try { localStorage.setItem('ovpmon_user', res.data.username); } catch (e) { /* ignore */ }
|
|
|
|
|
window.dispatchEvent(new Event('ovpmon-user-changed'));
|
|
|
|
|
userModal.value.hide();
|
|
|
|
|
Swal.fire({
|
|
|
|
|
title: 'Success!',
|
|
|
|
|
text: 'Username updated. Use the new username the next time you sign in.',
|
|
|
|
|
icon: 'success',
|
|
|
|
|
confirmButtonColor: '#1652B8'
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
Swal.fire({
|
|
|
|
|
title: 'Failed',
|
|
|
|
|
text: err.response?.data?.error || 'Failed to update username',
|
|
|
|
|
icon: 'error',
|
|
|
|
|
confirmButtonColor: '#cf222e'
|
|
|
|
|
});
|
|
|
|
|
} finally {
|
|
|
|
|
userLoading.value = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-28 22:37:47 +03:00
|
|
|
// 2FA Logic
|
|
|
|
|
const isEnabled = ref(false);
|
|
|
|
|
const step2 = ref(false);
|
|
|
|
|
const loading = ref(false);
|
|
|
|
|
const otp = ref('');
|
|
|
|
|
const setupData = ref({ secret: '', uri: '' });
|
|
|
|
|
const isDark = ref(document.documentElement.getAttribute('data-theme') === 'dark');
|
|
|
|
|
|
|
|
|
|
const fetchUserStatus = async () => {
|
|
|
|
|
loading.value = true;
|
|
|
|
|
try {
|
|
|
|
|
const res = await apiClient.get('/user/me');
|
|
|
|
|
isEnabled.value = res.data.is_2fa_enabled;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error('Failed to fetch user status:', err);
|
|
|
|
|
} finally {
|
|
|
|
|
loading.value = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
fetchUserStatus();
|
|
|
|
|
|
|
|
|
|
const observer = new MutationObserver((mutations) => {
|
|
|
|
|
mutations.forEach((mutation) => {
|
|
|
|
|
if (mutation.attributeName === 'data-theme') {
|
|
|
|
|
isDark.value = document.documentElement.getAttribute('data-theme') === 'dark';
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
observer.observe(document.documentElement, { attributes: true });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const initSetup = async () => {
|
|
|
|
|
loading.value = true;
|
|
|
|
|
try {
|
|
|
|
|
const res = await apiClient.post('../auth/setup-2fa');
|
|
|
|
|
setupData.value = res.data;
|
|
|
|
|
step2.value = true;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
Swal.fire('Error', 'Failed to initialize 2FA setup.', 'error');
|
|
|
|
|
} finally {
|
|
|
|
|
loading.value = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const verifyAndEnable = async () => {
|
|
|
|
|
if (!otp.value || otp.value.length !== 6) return;
|
|
|
|
|
loading.value = true;
|
|
|
|
|
try {
|
|
|
|
|
await apiClient.post('../auth/enable-2fa', {
|
|
|
|
|
secret: setupData.value.secret,
|
|
|
|
|
otp: otp.value
|
|
|
|
|
});
|
|
|
|
|
isEnabled.value = true;
|
|
|
|
|
confirmModal.value.open({
|
|
|
|
|
title: 'Success!',
|
|
|
|
|
message: 'Two-factor authentication has been enabled successfully. Your dashboard is now more secure.',
|
|
|
|
|
confirmText: 'Great!',
|
|
|
|
|
confirmBtnClass: 'btn-action-save',
|
|
|
|
|
showCancel: false
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
confirmModal.value.open({
|
|
|
|
|
title: 'Verification Failed',
|
|
|
|
|
message: err.response?.data?.error || 'The code you entered is invalid. Please check your authenticator app and try again.',
|
|
|
|
|
confirmText: 'Try Again',
|
|
|
|
|
confirmBtnClass: 'btn-action-danger',
|
|
|
|
|
showCancel: false
|
|
|
|
|
});
|
|
|
|
|
} finally {
|
|
|
|
|
loading.value = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const disableConfirm = () => {
|
|
|
|
|
disable2FAModal.value.open({
|
|
|
|
|
title: 'Disable 2FA?',
|
|
|
|
|
message: 'This will reduce your account security by removing the second-layer protection from your dashboard.',
|
|
|
|
|
confirmText: 'Yes, disable',
|
|
|
|
|
confirmBtnClass: 'btn-action-danger'
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleDisable2FA = async () => {
|
|
|
|
|
try {
|
|
|
|
|
await apiClient.post('../auth/disable-2fa');
|
|
|
|
|
|
|
|
|
|
isEnabled.value = false;
|
|
|
|
|
step2.value = false;
|
|
|
|
|
confirmModal.value.open({
|
|
|
|
|
title: '2FA Disabled',
|
|
|
|
|
message: 'Two-factor authentication has been disabled. Your account is now using standard password protection.',
|
|
|
|
|
confirmText: 'OK',
|
|
|
|
|
confirmBtnClass: 'btn-action-primary',
|
|
|
|
|
showCancel: false
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
confirmModal.value.open({
|
|
|
|
|
title: 'Error',
|
|
|
|
|
message: err.response?.data?.error || 'Failed to disable two-factor authentication. Please try again.',
|
|
|
|
|
confirmText: 'OK',
|
|
|
|
|
confirmBtnClass: 'btn-action-danger',
|
|
|
|
|
showCancel: false
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|