34 lines
895 B
Go
34 lines
895 B
Go
package handler
|
|
|
|
import (
|
|
"github.com/gorilla/csrf"
|
|
"net/http"
|
|
"picgo/corelib"
|
|
"picgo/data"
|
|
"picgo/model"
|
|
)
|
|
|
|
func IndexPageHandler(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")
|
|
} else {
|
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
|
}
|
|
}
|