Skip to content

Commit

Permalink
add logout feature (#1301)
Browse files Browse the repository at this point in the history
* add logout feature

* fix bug, optimize display

* optimize logout display

* keep Logs ui to logout

---------

Co-authored-by: luo.pengcheng <[email protected]>
  • Loading branch information
lpcheng1208 and luo.pengcheng authored Oct 31, 2024
1 parent 92354d6 commit abef25c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 11 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,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.Logout))

util.Log("监听 %s", *listen)

Expand Down
29 changes: 28 additions & 1 deletion static/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,31 @@ main {
line-height: 0;
text-align: center;
font-size: 16px;
}
}

.badge {
margin-right: 20px; /* 给版本号添加右侧间距 */
}

.action-button {
display: inline-block;
padding: 6px 12px;
font-size: 14px;
color: white;
border: 1px solid white;
border-radius: 8px;
background-color: transparent;
text-align: center;
text-decoration: none;
}

.action-button:hover,
.action-button:visited,
.action-button:active,
.action-button:focus {
color: white;
border-color: white;
background-color: transparent;
text-decoration: none;
outline: none;
}
2 changes: 2 additions & 0 deletions static/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ const I18N_MAP = {
"NetInterfaceEmptyHelp": '<span style="color: red">No available network card found</span>',
"Login": 'Login',
"LoginInit": 'Login and configure as an administrator account',
"Logout": 'Logout',
},
'zh-cn': {
'Logs': '日志',
Expand Down Expand Up @@ -298,5 +299,6 @@ const I18N_MAP = {
"NetInterfaceEmptyHelp": '<span style="color: red">没有找到可用的网卡</span>',
"Login": '登录',
"LoginInit": '登录并配置为管理员账号',
"Logout": '注销',
}
};
23 changes: 23 additions & 0 deletions web/logout.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package web

import (
"net/http"
"time"
)

func Logout(w http.ResponseWriter, r *http.Request) {
// 创建一个过期的 Cookie 来清除客户端的身份认证 Cookie
expiredCookie := http.Cookie{
Name: cookieName, // 假设你的身份验证使用的是名为 "auth" 的 Cookie
Value: "",
Path: "/",
Expires: time.Unix(0, 0), // 设置为过期时间
MaxAge: -1, // 立即删除该 Cookie
HttpOnly: true,
}
// 设置过期的 Cookie
http.SetCookie(w, &expiredCookie)

// 重定向用户到登录页面
http.Redirect(w, r, "./login", http.StatusFound)
}
19 changes: 9 additions & 10 deletions web/writing.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@
>
<strong>DDNS-GO</strong>
</a>
<button
data-i18n="Logs"
class="btn btn-info btn-sm"
id="logsBtn"
>
<button data-i18n="Logs" class="action-button logout-button" id="logsBtn">
Logs
</button>
<span
class="theme-button gg-dark-mode"
id="themeButton"
></span>
<span class="badge badge-secondary">{{.Version}}</span>
<a href="./logout" class="action-button logout-button" data-i18n="Logout">
Logout
</a>
</div>
</div>
</header>
Expand Down Expand Up @@ -102,7 +101,7 @@

<form id="formDnsConf">
<div class="portlet">
<h5
<h5
data-i18n="DNS Provider"
class="portlet__head"
id="dnsProvider"
Expand Down Expand Up @@ -480,7 +479,7 @@ <h5 class="portlet__head">IPv6</h5>
id="Ipv6Reg"
aria-describedby="Ipv6RegHelp"
/>
<small
<small
data-i18n_html="regHelp"
id="Ipv6RegHelp"
class="form-text text-muted"
Expand Down Expand Up @@ -513,7 +512,7 @@ <h5 class="portlet__head">IPv6</h5>

<form id="formGlobal">
<div class="portlet">
<h5
<h5
data-i18n="Others"
class="portlet__head"
>Others</h5>
Expand Down Expand Up @@ -561,7 +560,7 @@ <h5 class="portlet__head">IPv6</h5>
/>
<small
data-i18n_html="accountHelp"
id="UsernameHelp"
id="UsernameHelp"
class="form-text text-muted"
></small>
</div>
Expand Down Expand Up @@ -750,7 +749,7 @@ <h5 class="portlet__head">Webhook</h5>
TTL: "",
};
</script>

<!-- 表单相关 -->
<script>
// 生成DNS选择项
Expand Down

0 comments on commit abef25c

Please sign in to comment.