handlers: clean up deadcode
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
6ba09987a9
commit
58c9446130
@ -18,7 +18,6 @@ import (
|
||||
type tplMap map[string]*template.Template
|
||||
|
||||
var (
|
||||
// tmpl *template.Template
|
||||
tmpls = template.New("")
|
||||
templateMap tplMap
|
||||
tmplFS fs.FS
|
||||
@ -74,8 +73,6 @@ func getFuncMap() []template.FuncMap {
|
||||
}
|
||||
|
||||
func initTemplates(f fs.FS) {
|
||||
// tmpls := tmpl
|
||||
|
||||
if f != nil || f != tmplFS {
|
||||
tmplFS = f
|
||||
}
|
||||
@ -86,25 +83,11 @@ func initTemplates(f fs.FS) {
|
||||
// }
|
||||
setFuncMap(tmpls)
|
||||
|
||||
// tmpls, err := tmpls.ParseFS(f, listAllTmpls()...)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
|
||||
allTmpls := listAllTmpls()
|
||||
|
||||
// ensure this fails at compile time, if at all ("Must").
|
||||
tmpls = template.Must(tmpls.ParseFS(tmplFS, allTmpls...))
|
||||
makeTplMap(tmpls)
|
||||
|
||||
// tp := make(tplMap, len(allTmpls))
|
||||
// for _, v := range allTmpls {
|
||||
// tp[v] = tmpls.Lookup(v)
|
||||
// }
|
||||
//
|
||||
// templateMap = tp
|
||||
|
||||
// tmpl = tmpls
|
||||
}
|
||||
|
||||
func makeTplMap(tpl *template.Template) {
|
||||
@ -127,29 +110,12 @@ func getTmpl(name string) *template.Template {
|
||||
liveMode := conf.LiveMode
|
||||
|
||||
if liveMode {
|
||||
// reload the requested template before returning it.
|
||||
// tmpls = template.Must(tmpls.ParseFS(tmplFS, name))
|
||||
// nuTmpls, err := tmpls.ParseFS(tmplFS, name)
|
||||
// nuTmpls, err := tmpls.ParseFS(tmplFS, name)
|
||||
|
||||
//if err != nil {
|
||||
// log.Printf("error refreshing tmpl %s, '%q'", name, err)
|
||||
//} else {
|
||||
// tmpls = nuTmpls
|
||||
// makeTplMap(tmpls)
|
||||
//}
|
||||
|
||||
// tpl := template.Must(template.New(name).ParseFS(tmplFS, name))
|
||||
// templateMap[name] = tpl
|
||||
// return tpl
|
||||
|
||||
log.Info("re-reading tmpls")
|
||||
tpl := template.New("")
|
||||
setFuncMap(tpl)
|
||||
allTmpls := listAllTmpls()
|
||||
// ensure this fails at compile time, if at all ("Must").
|
||||
tmpls = template.Must(tpl.ParseFS(tmplFS, allTmpls...))
|
||||
// InitTemplates(tmplFS)
|
||||
}
|
||||
|
||||
return tmpls.Lookup(name)
|
||||
@ -161,7 +127,6 @@ func Admin() echo.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// func Index(conf *config.Config) echo.HandlerFunc {
|
||||
func Index() echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
// tpl, err := template.New("index").ParseFS(templates, "index.tmpl")
|
||||
@ -175,46 +140,11 @@ func Index() echo.HandlerFunc {
|
||||
// LoadTemplates(tmplFS)
|
||||
// }
|
||||
|
||||
// tpl = tpl.Funcs(template.FuncMap{
|
||||
// "pageIs": func(want, got string) bool {
|
||||
// if want == got {
|
||||
// return true
|
||||
// }
|
||||
// return false
|
||||
// },
|
||||
// })
|
||||
// log.Printf("%v", tpl)
|
||||
|
||||
// tpl := templateMap["index.tmpl"]
|
||||
|
||||
// secure := c.Request().URL.Scheme == "https"
|
||||
// secure := true
|
||||
csrf := c.Get("csrf").(string)
|
||||
// cookieCSRF := &http.Cookie{
|
||||
// Name: "_csrf",
|
||||
// Value: csrf,
|
||||
// // SameSite: http.SameSiteStrictMode,
|
||||
// SameSite: http.SameSiteLaxMode,
|
||||
// MaxAge: 3600,
|
||||
// Secure: secure,
|
||||
// HttpOnly: true,
|
||||
// }
|
||||
// c.SetCookie(cookieCSRF)
|
||||
|
||||
err := tpl.Execute(c.Response().Writer,
|
||||
// struct {
|
||||
// AppName string
|
||||
// AppVer string
|
||||
// Title string
|
||||
// CSRF string
|
||||
// DevelMode bool
|
||||
// }{
|
||||
// AppName: conf.AppName,
|
||||
// AppVer: appver,
|
||||
// Title: "Welcome!",
|
||||
// CSRF: csrf,
|
||||
// DevelMode: conf.DevelMode,
|
||||
// },
|
||||
page{
|
||||
AppName: conf.AppName,
|
||||
AppVer: appver,
|
||||
@ -252,32 +182,8 @@ func Signin() echo.HandlerFunc {
|
||||
}
|
||||
|
||||
tpl := getTmpl("signin.tmpl")
|
||||
// secure := c.Request().URL.Scheme == "https"
|
||||
// secure := true
|
||||
// csrf := c.Get("csrf").(string)
|
||||
// cookieCSRF := &http.Cookie{
|
||||
// Name: "_csrf",
|
||||
// Value: csrf,
|
||||
// // SameSite: http.SameSiteStrictMode,
|
||||
// SameSite: http.SameSiteLaxMode,
|
||||
// MaxAge: 3600,
|
||||
// Secure: secure,
|
||||
// HttpOnly: true,
|
||||
// }
|
||||
// c.SetCookie(cookieCSRF)
|
||||
|
||||
err = tpl.Execute(c.Response().Writer,
|
||||
// struct {
|
||||
// AppName string
|
||||
// AppVer string
|
||||
// Title string
|
||||
// DevelMode bool
|
||||
// }{
|
||||
// AppName: conf.AppName,
|
||||
// AppVer: appver,
|
||||
// Title: "Sign in",
|
||||
// DevelMode: conf.DevelMode,
|
||||
// },
|
||||
page{
|
||||
AppName: conf.AppName,
|
||||
AppVer: appver,
|
||||
@ -326,10 +232,6 @@ func SigninPost(client *ent.Client) echo.HandlerFunc {
|
||||
return nil
|
||||
}
|
||||
|
||||
// if usr := client.User.Query().
|
||||
// Where(
|
||||
// user.Username(username),
|
||||
// ); usr != nil {
|
||||
ctx := context.WithValue(context.Background(), "logger", log)
|
||||
if usr, err := moduser.QueryUser(ctx, client, username); err == nil {
|
||||
log.Info("queried user:", &usr.ID)
|
||||
@ -338,19 +240,6 @@ func SigninPost(client *ent.Client) echo.HandlerFunc {
|
||||
|
||||
c.Redirect(302, "/signin")
|
||||
}
|
||||
// if user.Password(password) {
|
||||
// c.Redirect(302, "/signin")
|
||||
// }
|
||||
|
||||
// if err != nil || p != password {
|
||||
// log.Println(echo.NewHTTPError(
|
||||
// http.StatusUnauthorized,
|
||||
// http.StatusText(http.StatusUnauthorized)+" "+err.Error(),
|
||||
// ))
|
||||
//
|
||||
// c.Redirect(302, "/signin")
|
||||
// return nil
|
||||
// }
|
||||
} else {
|
||||
// just log the error instead of returning it to the user and
|
||||
// redirect back to /signin.
|
||||
@ -439,11 +328,6 @@ func Signup() echo.HandlerFunc {
|
||||
|
||||
func SignupPost(client *ent.Client) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
// tpl := getTmpl("signup.tmpl", conf.LiveMode)
|
||||
|
||||
ct := c.Request().Header.Get("Content-Type")
|
||||
fmt.Printf("content-type: %s\n", ct)
|
||||
|
||||
err := c.Request().ParseForm()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -476,9 +360,6 @@ func SignupPost(client *ent.Client) echo.HandlerFunc {
|
||||
}
|
||||
|
||||
secure := c.Request().URL.Scheme == "https"
|
||||
// secure := true
|
||||
// csrf := c.Get("csrf").(string)
|
||||
|
||||
cookieSession := &http.Cookie{
|
||||
Name: "session",
|
||||
Value: username,
|
||||
@ -489,17 +370,6 @@ func SignupPost(client *ent.Client) echo.HandlerFunc {
|
||||
}
|
||||
c.SetCookie(cookieSession)
|
||||
|
||||
// cookieCSRF := &http.Cookie{
|
||||
// Name: "_csrf",
|
||||
// Value: csrf,
|
||||
// // SameSite: http.SameSiteStrictMode,
|
||||
// SameSite: http.SameSiteLaxMode,
|
||||
// MaxAge: 3600,
|
||||
// Secure: secure,
|
||||
// HttpOnly: true,
|
||||
// }
|
||||
// c.SetCookie(cookieCSRF)
|
||||
|
||||
c.Redirect(301, "/home")
|
||||
|
||||
return nil
|
||||
@ -522,7 +392,6 @@ func Home() echo.HandlerFunc {
|
||||
|
||||
log.Infof("error: %q", err)
|
||||
http.Error(c.Response().Writer, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||
// fmt.Println("session cookie not found, redirecting to signin page")
|
||||
|
||||
return nil
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user