picgo/handler/index.go

32 lines
814 B
Go

package handler
import (
"github.com/gorilla/csrf"
"net/http"
"picgo/corelib"
"picgo/data"
"picgo/model"
)
func IndexHandler(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"] = "Dashboard"
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/index.html")
}
}