picgo/handler/picture.go

35 lines
903 B
Go
Raw Normal View History

package handler
import (
"github.com/gorilla/csrf"
"net/http"
"picgo/corelib"
"picgo/data"
"picgo/model"
)
2024-08-06 20:37:34 +08:00
func PicturePageHandler(w http.ResponseWriter, r *http.Request) {
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
}
tmpData := map[string]interface{}{
csrf.TemplateTag: csrf.TemplateField(r),
}
tmpData["Title"] = "图片管理"
tmpData["Active"] = r.URL.Path
tmpData["IsSuper"] = user.IsSuper
w.Header().Add("X-CSRF-Token", csrf.Token(r))
corelib.TemplateHandler(w, tmpData, "layout.html", "view/layout.html", "view/picture.html")
2024-08-06 20:37:34 +08:00
} else {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
}
}