From 6f868c9ec3bc8814f385dcd353aeec5e32ef0939 Mon Sep 17 00:00:00 2001 From: LouisLam Date: Sat, 31 Jul 2021 23:41:24 +0800 Subject: [PATCH] implement no auth --- server/server.js | 9 +++++- src/mixins/socket.js | 13 ++++++-- src/pages/Settings.vue | 71 +++++++++++++++++++++++------------------- 3 files changed, 58 insertions(+), 35 deletions(-) diff --git a/server/server.js b/server/server.js index 967db53a7..25c44ebf9 100644 --- a/server/server.js +++ b/server/server.js @@ -26,7 +26,7 @@ console.log("Importing this project modules"); debug("Importing Monitor"); const Monitor = require("./model/monitor"); debug("Importing Settings"); -const { getSettings, setSettings } = require("./util-server"); +const { getSettings, setSettings, setting } = require("./util-server"); debug("Importing Notification"); const { Notification } = require("./notification"); debug("Importing Database"); @@ -114,6 +114,11 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); socket.emit("setup") } + if (await setting("disableAuth")) { + console.log("Disabled Auth: auto login to admin") + await afterLogin(socket, await R.findOne("user", " username = 'admin' ")) + } + socket.on("disconnect", () => { totalClient--; }); @@ -600,6 +605,8 @@ async function afterLogin(socket, user) { } sendNotificationList(socket) + + socket.emit("autoLogin") } async function getMonitorJSONList(userID) { diff --git a/src/mixins/socket.js b/src/mixins/socket.js index 0c7fed15b..bae045650 100644 --- a/src/mixins/socket.js +++ b/src/mixins/socket.js @@ -56,6 +56,11 @@ export default { this.$router.push("/setup") }); + socket.on("autoLogin", (monitorID, data) => { + this.loggedIn = true; + this.storage().token = "autoLogin" + }); + socket.on("monitorList", (data) => { // Add Helper function Object.entries(data).forEach(([monitorID, monitor]) => { @@ -156,8 +161,12 @@ export default { this.clearData() } - if (this.storage().token) { - this.loginByToken(this.storage().token) + let token = this.storage().token; + + if (token) { + if (token !== "autoLogin") { + this.loginByToken(token) + } } else { this.allowLoginDialog = true; } diff --git a/src/pages/Settings.vue b/src/pages/Settings.vue index d11479162..5923e4482 100644 --- a/src/pages/Settings.vue +++ b/src/pages/Settings.vue @@ -27,40 +27,44 @@ -

Change Password

-
-
- - -
+
@@ -128,7 +132,8 @@ export default { }, settings: { - } + }, + loaded: false, } }, watch: { @@ -166,6 +171,7 @@ export default { loadSettings() { this.$root.getSocket().emit("getSettings", (res) => { this.settings = res.data; + this.loaded = true; }) }, @@ -188,6 +194,7 @@ export default { enableAuth() { this.settings.disableAuth = false; this.saveSettings(); + this.$root.storage().token = null; }, },