Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add logout feature #1301

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 27 additions & 1 deletion static/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,30 @@ 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; /* 保持无下划线 */
}
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)
}
13 changes: 8 additions & 5 deletions web/writing.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
id="themeButton"
></span>
<span class="badge badge-secondary">{{.Version}}</span>
<a href="./logout" class="action-button logout-button" data-i18n="Logout">
注销
</a>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

向前缩进,注销文字保持和其它类似,为英文

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

向前缩进,注销文字保持和其它类似,为英文

哈,这个倒是改了,但是Logs 也推上去了,确实感觉还是之前的比较 OK

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

也可以

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

也可以

Logs 需要搞回去吗? 还是你push 一个上来?我刚想改回去,发现已经merge了

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改不改都可以,你想改就在来个

</div>
</div>
</header>
Expand Down Expand Up @@ -102,7 +105,7 @@

<form id="formDnsConf">
<div class="portlet">
<h5
<h5
data-i18n="DNS Provider"
class="portlet__head"
id="dnsProvider"
Expand Down Expand Up @@ -480,7 +483,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 +516,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 +564,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 +753,7 @@ <h5 class="portlet__head">Webhook</h5>
TTL: "",
};
</script>

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