|
@@ -16,7 +16,7 @@ type LoginResp struct {
|
|
|
Success bool `json:"success"`
|
|
Success bool `json:"success"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func loginHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
+func WebLoginHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
if r.Method != http.MethodPost {
|
|
if r.Method != http.MethodPost {
|
|
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
|
|
return
|
|
return
|
|
@@ -31,8 +31,8 @@ func loginHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
ok := req.Username == "admin" && req.Password == "admin123456"
|
|
ok := req.Username == "admin" && req.Password == "admin123456"
|
|
|
|
|
|
|
|
if ok {
|
|
if ok {
|
|
|
- sessionID := createSession()
|
|
|
|
|
- addSession(sessionID)
|
|
|
|
|
|
|
+ sessionID := WebCreateSession()
|
|
|
|
|
+ WebAddSession(sessionID)
|
|
|
|
|
|
|
|
http.SetCookie(w, &http.Cookie{
|
|
http.SetCookie(w, &http.Cookie{
|
|
|
Name: "session_id",
|
|
Name: "session_id",
|
|
@@ -47,7 +47,7 @@ func loginHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
json.NewEncoder(w).Encode(LoginResp{Success: ok})
|
|
json.NewEncoder(w).Encode(LoginResp{Success: ok})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func logoutHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
+func WebLogoutHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
if cookie, err := r.Cookie("session_id"); err == nil {
|
|
if cookie, err := r.Cookie("session_id"); err == nil {
|
|
|
sessionMu.Lock()
|
|
sessionMu.Lock()
|
|
|
delete(sessions, cookie.Value)
|
|
delete(sessions, cookie.Value)
|
|
@@ -64,7 +64,7 @@ func logoutHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
http.Redirect(w, r, "/", http.StatusFound)
|
|
http.Redirect(w, r, "/", http.StatusFound)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (ui *WebUI) rootHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
+func (ui *WebUI) WebRootHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
path := r.URL.Path
|
|
path := r.URL.Path
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
@@ -73,7 +73,7 @@ func (ui *WebUI) rootHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
w.Header().Set("Expires", "0")
|
|
w.Header().Set("Expires", "0")
|
|
|
|
|
|
|
|
// 1, 未登录时, 只能看登录页
|
|
// 1, 未登录时, 只能看登录页
|
|
|
- if !checkSession(r) {
|
|
|
|
|
|
|
+ if !WebCheckSession(r) {
|
|
|
data, err := fs.ReadFile(ui.fs, "login.html")
|
|
data, err := fs.ReadFile(ui.fs, "login.html")
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
http.NotFound(w, r)
|
|
http.NotFound(w, r)
|