Skip to content

Commit

Permalink
feat: jeessy2#1156 增加退出登录
Browse files Browse the repository at this point in the history
  • Loading branch information
huyinghuan committed Jun 28, 2024
1 parent 451b425 commit f0fdaa4
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 8 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 5 additions & 1 deletion static/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions static/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -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": '<span style="color: red">No available network card found</span>',
"Login": 'Login',
'Logout': 'Logout',
},
'zh-cn': {
'Logs': '日志',
Expand Down Expand Up @@ -295,5 +296,6 @@ const I18N_MAP = {
`,
"NetInterfaceEmptyHelp": '<span style="color: red">没有找到可用的网卡</span>',
"Login": '登录',
'Logout': '退出',
}
};
1 change: 1 addition & 0 deletions util/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
16 changes: 16 additions & 0 deletions web/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 22 additions & 7 deletions web/writing.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,24 @@
>
<strong>DDNS-GO</strong>
</a>
<button
data-i18n="Logs"
class="btn btn-info btn-sm"
id="logsBtn"
>
Logs

<div class="opt-btn-group">
<button
data-i18n="Logs"
class="btn btn-info btn-sm"
id="logsBtn"
>
Logs
</button>
<button
data-i18n="Logout"
class="btn btn-danger btn-sm"
id="logoutBtn"
>
Logout
</button>
</div>

<span
class="theme-button gg-dark-mode"
id="themeButton"
Expand Down Expand Up @@ -1124,7 +1135,11 @@ <h5 class="portlet__head">Webhook</h5>
}
});
});

// 退出登录
document.getElementById("logoutBtn").addEventListener('click', async e => {
e.preventDefault();
location.href = "./logout";
});
// 页面加载完成后定时获取日志
document.addEventListener('DOMContentLoaded', () => getLogs(true));
</script>
Expand Down

0 comments on commit f0fdaa4

Please sign in to comment.