diff --git a/main.go b/main.go index 22ccec3ff..efc72a880 100644 --- a/main.go +++ b/main.go @@ -180,6 +180,7 @@ func runWebServer() error { http.HandleFunc("/logs", web.Auth(web.Logs)) http.HandleFunc("/clearLog", web.Auth(web.ClearLog)) http.HandleFunc("/webhookTest", web.Auth(web.WebhookTest)) + http.HandleFunc("/logout", web.Auth(web.LogoutFunc)) util.Log("监听 %s", *listen) diff --git a/static/common.css b/static/common.css index 8d6e4fea0..d283638c8 100644 --- a/static/common.css +++ b/static/common.css @@ -122,12 +122,16 @@ main { background-color: transparent !important; } -#logsBtn { +.opt-btn-group { position: relative; margin-left: auto; margin-right: 25px; } +#logsBtn { + position: relative; +} + .unread:after { content: ''; position: absolute; diff --git a/static/constant.js b/static/constant.js index 1a34e02d0..fef853ec7 100644 --- a/static/constant.js +++ b/static/constant.js @@ -230,6 +230,7 @@ const I18N_MAP = { "Ipv6CmdHelp": "Get IPv6 through command, only use the first matching IPv6 address of standard output(stdout). Such as: ip -6 addr show eth1", "NetInterfaceEmptyHelp": 'No available network card found', "Login": 'Login', + 'Logout': 'Logout', }, 'zh-cn': { 'Logs': '日志', @@ -295,5 +296,6 @@ const I18N_MAP = { `, "NetInterfaceEmptyHelp": '没有找到可用的网卡', "Login": '登录', + 'Logout': '退出', } }; diff --git a/util/messages.go b/util/messages.go index 810053671..f9edbd6eb 100644 --- a/util/messages.go +++ b/util/messages.go @@ -114,6 +114,7 @@ func init() { // Login message.SetString(language.English, "%q 登陆成功", "%q login successfully") + message.SetString(language.English, "注销登录成功", "logout successfully") message.SetString(language.English, "用户名或密码错误", "Username or password is incorrect") message.SetString(language.English, "登录失败次数过多,请等待 %d 分钟后再试", "Too many login failures, please try again after %d minutes") message.SetString(language.English, "用户名 %s 的密码已重置成功! 请重启ddns-go", "The password of username %s has been reset successfully! Please restart ddns-go") diff --git a/web/login.go b/web/login.go index f02ca9243..ff76114cb 100755 --- a/web/login.go +++ b/web/login.go @@ -108,6 +108,22 @@ func LoginFunc(w http.ResponseWriter, r *http.Request) { returnError(w, util.LogStr("用户名或密码错误")) } +func LogoutFunc(w http.ResponseWriter, r *http.Request) { + // 覆盖cookie + cookieInSystem = &http.Cookie{ + Name: cookieName, + Value: "", // 生成token + Path: "/", + HttpOnly: true, + } + // 写入cookie + http.SetCookie(w, cookieInSystem) + util.Log("注销登录成功") + // 设置临时重定向到根目录 + http.Redirect(w, r, "/", http.StatusTemporaryRedirect) + return +} + // loginUnlock login unlock, return minute func loginUnlock() (minute uint32) { ld.failedTimes = ld.failedTimes + 1 diff --git a/web/writing.html b/web/writing.html index b6a21a3cc..b164a9bb1 100755 --- a/web/writing.html +++ b/web/writing.html @@ -30,13 +30,24 @@ > DDNS-GO - + + + Webhook } }); }); - + // 退出登录 + document.getElementById("logoutBtn").addEventListener('click', async e => { + e.preventDefault(); + location.href = "./logout"; + }); // 页面加载完成后定时获取日志 document.addEventListener('DOMContentLoaded', () => getLogs(true));