picgo/handler/index.go

34 lines
895 B
Go
Raw Permalink Normal View History

2024-07-11 21:25:58 +08:00
package handler
2024-07-12 20:32:33 +08:00
import (
2024-07-14 20:31:27 +08:00
"github.com/gorilla/csrf"
2024-07-12 20:32:33 +08:00
"net/http"
"picgo/corelib"
"picgo/data"
"picgo/model"
2024-07-12 20:32:33 +08:00
)
2024-08-06 20:37:34 +08:00
func IndexPageHandler(w http.ResponseWriter, r *http.Request) {
2024-07-12 20:32:33 +08:00
if r.Method == "GET" {
var (
err error
user model.SysUser
)
username := r.Context().Value("username").(string)
if user, err = data.SysUserGetCacheByUsername(username); err != nil {
http.Error(w, "IndexHandler SysUserGetCacheByUsername Error", http.StatusInternalServerError)
return
}
2024-07-14 20:31:27 +08:00
tmpData := map[string]interface{}{
csrf.TemplateTag: csrf.TemplateField(r),
2024-07-12 20:32:33 +08:00
}
2024-07-14 20:31:27 +08:00
tmpData["Title"] = "Dashboard"
tmpData["Active"] = r.URL.Path
tmpData["IsSuper"] = user.IsSuper
2024-07-14 20:31:27 +08:00
w.Header().Add("X-CSRF-Token", csrf.Token(r))
corelib.TemplateHandler(w, tmpData, "layout.html", "view/layout.html", "view/index.html")
2024-08-06 20:37:34 +08:00
} else {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
2024-07-12 20:32:33 +08:00
}
}