Browse Source

Feature: Better validation

master
parent
commit
8f486881f9
  1. 2
      pages/base.html
  2. 21
      src/server/server.go
  3. 1
      src/server/validation.go

2
pages/base.html

@ -29,7 +29,7 @@
</a>
<ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
<li><a href="/register" class="nav-link px-2 text-white">Register</a></li>
<li><a href="/" class="nav-link px-2 text-white">Main</a></li>
<li><a href="/about" class="nav-link px-2 text-white">About</a></li>
</ul>

21
src/server/server.go

@ -134,7 +134,12 @@ func New(config conf.Conf) (*Server, error) {
return
}
requestedPage.ExecuteTemplate(w, "index.html", &pageData)
err = requestedPage.ExecuteTemplate(w, "index.html", &pageData)
if err != nil {
http.Redirect(w, req, "/error", http.StatusTemporaryRedirect)
logger.Error("[Server][/category/] Template error: %s", err)
return
}
} else if path.Dir(req.URL.Path) == "/group" {
if req.Method != "GET" {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
@ -178,7 +183,12 @@ func New(config conf.Conf) (*Server, error) {
return
}
requestedPage.ExecuteTemplate(w, "category.html", &pageData)
err = requestedPage.ExecuteTemplate(w, "category.html", &pageData)
if err != nil {
http.Redirect(w, req, "/error", http.StatusTemporaryRedirect)
logger.Error("[Server][/category/] Template error: %s", err)
return
}
} else {
// default
@ -188,7 +198,12 @@ func New(config conf.Conf) (*Server, error) {
req.URL.Path[1:]+".html",
)
if err == nil {
requestedPage.ExecuteTemplate(w, req.URL.Path[1:]+".html", nil)
err = requestedPage.ExecuteTemplate(w, req.URL.Path[1:]+".html", nil)
if err != nil {
http.Redirect(w, req, "/error", http.StatusTemporaryRedirect)
logger.Error("[Server][/default] Template error: %s", err)
return
}
} else {
http.Redirect(w, req, "/error", http.StatusTemporaryRedirect)
}

1
src/server/validation.go

@ -30,6 +30,7 @@ const (
MinimalPasswordLength uint = 5
MaxLoginLength uint = 60
MaxPasswordLength uint = 250
MaxTodoLength uint = 150
)
// Check if user is valid. Returns false and a reason-string if not

Loading…
Cancel
Save