aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexander Kavon <hawk@alexkavon.com>2023-11-28 05:24:30 -0500
committerAlexander Kavon <hawk@alexkavon.com>2023-11-28 05:24:30 -0500
commit629b0189b7bf20c748a1d37f8803ad0e3ffb8a49 (patch)
tree6692374508230b46be3aee323acd7aa25b3d4a91 /src
parent7d7059d53891bc1abb284d9b288505a5d406b307 (diff)
working container compose w/database, no more auth package, message template partial, working html template writing, auth routes in user/routes.go
Diffstat (limited to 'src')
-rw-r--r--src/auth/routes.go23
-rw-r--r--src/main.go2
-rw-r--r--src/server/ui.go16
-rw-r--r--src/user/routes.go50
-rw-r--r--src/user/user.go1
5 files changed, 55 insertions, 37 deletions
diff --git a/src/auth/routes.go b/src/auth/routes.go
deleted file mode 100644
index 5a28756..0000000
--- a/src/auth/routes.go
+++ /dev/null
@@ -1,23 +0,0 @@
-package auth
-
-import (
- "net/http"
-
- "gitlab.com/alexkavon/newsstand/src/server"
-)
-
-var Routes = server.Routes{
- server.Route{
- Name: "Register",
- Method: "GET",
- Path: "/auth/register",
- AuthRequired: false,
- HandlerFunc: Register,
- },
-}
-
-func Register(s *server.Server) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
- s.Ui.Render(w, "auth/register", nil)
- }
-}
diff --git a/src/main.go b/src/main.go
index d3f6c03..0687aae 100644
--- a/src/main.go
+++ b/src/main.go
@@ -1,7 +1,6 @@
package main
import (
- "gitlab.com/alexkavon/newsstand/src/auth"
"gitlab.com/alexkavon/newsstand/src/conf"
"gitlab.com/alexkavon/newsstand/src/db"
"gitlab.com/alexkavon/newsstand/src/server"
@@ -16,7 +15,6 @@ func main() {
s := server.NewServer(config, db.NewDb(config))
s.BuildUi()
routers := []server.Routes{
- auth.Routes,
user.Routes,
}
for _, r := range routers {
diff --git a/src/server/ui.go b/src/server/ui.go
index ce0ef01..a765d97 100644
--- a/src/server/ui.go
+++ b/src/server/ui.go
@@ -20,14 +20,15 @@ func NewUi(config *conf.Conf) Ui {
func (ui *Ui) CompilePages(uipath string) {
ui.pages = map[string]*template.Template{}
- baseTmpl, err := template.ParseFiles(filepath.Join(uipath, "templates/base.tmpl.html"))
+ baseTmpl, err := template.ParseGlob(filepath.Join(uipath, "templates/*.tmpl.html"))
if err != nil {
log.Fatal(err)
}
- pagesDir := filepath.Join(uipath, "pages")
- tmplGlob := "**/*.tmpl.html"
+ ui.pages["core/messages"] = baseTmpl
- fileglob, err := filepath.Glob(filepath.Join(pagesDir, tmplGlob))
+ pagesDir := filepath.Join(uipath, "pages")
+ tmplGlob := filepath.Join(pagesDir, "**/*.tmpl.html")
+ fileglob, err := filepath.Glob(tmplGlob)
if err != nil {
log.Fatal(err)
}
@@ -47,8 +48,13 @@ func (ui *Ui) CompilePages(uipath string) {
}
func (ui *Ui) Render(w http.ResponseWriter, pageName string, data interface{}) {
+ templateName := "base"
+ if pageName == "core/messages" {
+ templateName = "messages"
+ }
p := ui.pages[pageName]
- err := p.ExecuteTemplate(w, "base", data)
+
+ err := p.ExecuteTemplate(w, templateName, data)
if err != nil {
log.Fatal(err)
}
diff --git a/src/user/routes.go b/src/user/routes.go
index 791213d..09c53b2 100644
--- a/src/user/routes.go
+++ b/src/user/routes.go
@@ -1,6 +1,7 @@
package user
import (
+ "fmt"
"net/http"
"gitlab.com/alexkavon/newsstand/src/server"
@@ -8,16 +9,33 @@ import (
var Routes = server.Routes{
server.Route{
- Name: "Create",
- Method: "GET",
- Path: "/users/create",
- AuthRequired: false,
- HandlerFunc: Create,
+ Name: "Create",
+ Method: "GET",
+ Path: "/user/create",
+ HandlerFunc: Create,
+ },
+ server.Route{
+ Name: "Store",
+ Method: "POST",
+ Path: "/user",
+ HandlerFunc: Store,
+ },
+ server.Route{
+ Name: "LoginForm",
+ Method: "GET",
+ Path: "/user/auth",
+ HandlerFunc: LoginForm,
+ },
+ server.Route{
+ Name: "Authenticate",
+ Method: "POST",
+ Path: "/user/auth",
+ HandlerFunc: Authenticate,
},
server.Route{
Name: "Me",
Method: "GET",
- Path: "/users/me",
+ Path: "/user/me",
AuthRequired: true,
HandlerFunc: Show,
},
@@ -25,10 +43,28 @@ var Routes = server.Routes{
func Create(s *server.Server) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
- s.Ui.Render(w, "users/create", nil)
+ s.Ui.Render(w, "user/create", nil)
+ }
+}
+
+func Store(s *server.Server) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ r.ParseForm()
+ fmt.Println(r.PostForm)
+ s.Ui.Render(w, "core/messages", &struct{ Message string }{Message: "Congrats"})
}
}
+func LoginForm(s *server.Server) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ s.Ui.Render(w, "user/login", nil)
+ }
+}
+
+func Authenticate(s *server.Server) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {}
+}
+
func Show(s *server.Server) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {}
}
diff --git a/src/user/user.go b/src/user/user.go
index 9845b1b..97fe74c 100644
--- a/src/user/user.go
+++ b/src/user/user.go
@@ -3,4 +3,5 @@ package user
type User struct {
Id int64 `json:"id"`
Username string `json:"username"`
+ Karma uint64 `json:"karma"`
}