UI review, stage 3: cleanup, shared chart code, confirmations, routing

useTrafficChart composable replaces the duplicated chart code in Analytics
and HistoryModal; theme observer is released on unmount; blob URLs are
revoked. ConfirmModal gets a unique id; confirm() in Server/PKI and
SweetAlert2 in Account are replaced by ConfirmModal and toasts, sweetalert2
and sass removed. Separate authApiClient for /api/auth. 404 redirect, lazy
Clients, token-based isAuthenticated, theme from prefers-color-scheme set
before mount. BaseModal reactive size, NewClientModal name check and focus
on opened, HistoryModal ignores stale answers. Login.vue.bak, the dead
global axios interceptor and empty <p> removed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ayurishchevandClaude Sonnet 5.5 committed 2026-10-07 13:10:41 +03:00
1 parent 600119cdd1
commit 897c82ab88
23 files changed
+430 -710

No files matched your search

+21 -90
View File
@@ -117,10 +117,7 @@
</div>
</div>
<!-- Alerts/Notifications Modal -->
<ConfirmModal ref="confirmModal" />
<!-- Action Confirmations Modal -->
<!-- Confirmation before 2FA is disabled; results are shown as toasts -->
<ConfirmModal ref="disable2FAModal" @confirm="handleDisable2FA" />
<!-- Password Change Modal -->
@@ -223,16 +220,16 @@
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';
import { useToast } from '../composables/useToast';
const { apiClient } = useApi();
const { apiClient, authApiClient } = useApi();
const toast = useToast();
// UI Refs
const pwModal = ref(null);
const userModal = ref(null);
const confirmModal = ref(null);
const disable2FAModal = ref(null);
// Password Logic
@@ -252,36 +249,21 @@ const showPwModal = () => {
const handleChangePassword = async () => {
if (passwordForm.new_password !== passwordForm.confirm_password) {
Swal.fire({
title: 'Error!',
text: 'New passwords do not match',
icon: 'error',
confirmButtonColor: '#EC7C31'
});
toast.show('New passwords do not match', 'error');
return;
}
pwLoading.value = true;
try {
await apiClient.post('../auth/change-password', {
await authApiClient.post('/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'
});
toast.show('Password updated successfully.', 'success');
} catch (err) {
Swal.fire({
title: 'Failed',
text: err.response?.data?.error || 'Failed to update password',
icon: 'error',
confirmButtonColor: '#cf222e'
});
toast.show(err.response?.data?.error || 'Failed to update password', 'error');
} finally {
pwLoading.value = false;
}
@@ -300,18 +282,13 @@ const showUserModal = () => {
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'
});
toast.show('Username must be 3-32 chars, start with a letter, and contain only letters, digits, . _ -', 'error');
return;
}
userLoading.value = true;
try {
const res = await apiClient.post('../auth/change-username', {
const res = await authApiClient.post('/change-username', {
new_username: usernameForm.new_username,
current_password: usernameForm.current_password,
otp: usernameForm.otp || undefined
@@ -320,19 +297,9 @@ const handleChangeUsername = async () => {
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'
});
toast.show('Username updated. Use the new username the next time you sign in.', 'success');
} catch (err) {
Swal.fire({
title: 'Failed',
text: err.response?.data?.error || 'Failed to update username',
icon: 'error',
confirmButtonColor: '#cf222e'
});
toast.show(err.response?.data?.error || 'Failed to update username', 'error');
} finally {
userLoading.value = false;
}
@@ -344,7 +311,6 @@ 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;
@@ -358,27 +324,16 @@ const fetchUserStatus = async () => {
}
};
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 });
});
onMounted(fetchUserStatus);
const initSetup = async () => {
loading.value = true;
try {
const res = await apiClient.post('../auth/setup-2fa');
const res = await authApiClient.post('/setup-2fa');
setupData.value = res.data;
step2.value = true;
} catch (err) {
Swal.fire('Error', 'Failed to initialize 2FA setup.', 'error');
toast.show(err.response?.data?.error || 'Failed to initialize 2FA setup.', 'error');
} finally {
loading.value = false;
}
@@ -388,26 +343,14 @@ const verifyAndEnable = async () => {
if (!otp.value || otp.value.length !== 6) return;
loading.value = true;
try {
await apiClient.post('../auth/enable-2fa', {
await authApiClient.post('/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
});
toast.show('Two-factor authentication has been enabled. Your dashboard is now more secure.', 'success');
} 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
});
toast.show(err.response?.data?.error || 'The code you entered is invalid. Please check your authenticator app and try again.', 'error');
} finally {
loading.value = false;
}
@@ -424,25 +367,13 @@ const disableConfirm = () => {
const handleDisable2FA = async () => {
try {
await apiClient.post('../auth/disable-2fa');
await authApiClient.post('/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
});
toast.show('Two-factor authentication has been disabled. Your account is now using standard password protection.', 'warning');
} 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
});
toast.show(err.response?.data?.error || 'Failed to disable two-factor authentication. Please try again.', 'error');
}
};
</script>