feat: implement server restart functionality and refactor logout handling
This commit is contained in:
+1
-2
@@ -43,8 +43,7 @@ export const systemApi = {
|
|||||||
},
|
},
|
||||||
setSettings: (settings) =>
|
setSettings: (settings) =>
|
||||||
api.post('/system/settings/set', settings),
|
api.post('/system/settings/set', settings),
|
||||||
testWebhook: (webhookConfig) =>
|
restartServer: () => api.get('/system/restart')
|
||||||
api.post('/system/webhook/test', webhookConfig)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const authApi = {
|
export const authApi = {
|
||||||
|
|||||||
@@ -75,8 +75,9 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { ref, onMounted, onBeforeUnmount } from 'vue';
|
import { ref, onMounted, onBeforeUnmount } from 'vue';
|
||||||
import { systemApi, authApi, userApi } from '../api/index.js';
|
import { systemApi, userApi } from '../api/index.js';
|
||||||
import { getCookie, setCookie, deleteCookie as removeCookie, showNotification } from '../utils/functions.js';
|
import { getCookie, setCookie, showNotification } from '../utils/functions.js';
|
||||||
|
import { handleLogout as performLogout } from '../utils/session.js';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -174,16 +175,7 @@ export default {
|
|||||||
|
|
||||||
const handleLogout = async () => {
|
const handleLogout = async () => {
|
||||||
menuVisible.value = false;
|
menuVisible.value = false;
|
||||||
try {
|
await performLogout(router);
|
||||||
await authApi.logout();
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Logout API error:', error);
|
|
||||||
}
|
|
||||||
removeCookie('token');
|
|
||||||
removeCookie('username');
|
|
||||||
removeCookie('user-type');
|
|
||||||
removeCookie('user-id');
|
|
||||||
router.push('/login');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeMenu = (event) => {
|
const closeMenu = (event) => {
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { authApi } from '../api/index.js';
|
||||||
|
import { deleteCookie as removeCookie } from './functions.js';
|
||||||
|
|
||||||
|
async function handleLogout(router) {
|
||||||
|
try {
|
||||||
|
await authApi.logout();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Logout API error:', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeCookie('token');
|
||||||
|
removeCookie('username');
|
||||||
|
removeCookie('user-type');
|
||||||
|
removeCookie('user-id');
|
||||||
|
|
||||||
|
if (router) {
|
||||||
|
router.push('/login');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
handleLogout
|
||||||
|
};
|
||||||
@@ -81,7 +81,7 @@
|
|||||||
|
|
||||||
<div class="form-actions save-actions">
|
<div class="form-actions save-actions">
|
||||||
<button @click="saveSettings" class="submit-btn" :disabled="isSaving">
|
<button @click="saveSettings" class="submit-btn" :disabled="isSaving">
|
||||||
{{ isSaving ? 'Saving...' : 'Save Settings' }}
|
{{ isSaving ? 'Saving...' : 'Save Settings and Restart' }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -122,14 +122,17 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { ref, reactive, onMounted } from 'vue';
|
import { ref, reactive, onMounted } from 'vue';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
import { systemApi } from '../api/index.js';
|
import { systemApi } from '../api/index.js';
|
||||||
import { showNotification } from '../utils/functions.js';
|
import { showNotification } from '../utils/functions.js';
|
||||||
|
import { handleLogout as performLogout } from '../utils/session.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Settings',
|
name: 'Settings',
|
||||||
setup() {
|
setup() {
|
||||||
const isSaving = ref(false);
|
const isSaving = ref(false);
|
||||||
const showWebhookDialog = ref(false);
|
const showWebhookDialog = ref(false);
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
const settings = reactive({
|
const settings = reactive({
|
||||||
listenAddr: '',
|
listenAddr: '',
|
||||||
@@ -188,6 +191,8 @@ export default {
|
|||||||
const result = await systemApi.setSettings(payload);
|
const result = await systemApi.setSettings(payload);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
alert('Settings saved successfully');
|
alert('Settings saved successfully');
|
||||||
|
systemApi.restartServer();
|
||||||
|
await performLogout(router);
|
||||||
} else {
|
} else {
|
||||||
alert(result.message || 'Failed to save settings');
|
alert(result.message || 'Failed to save settings');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user