From 481b799f9eced5432fdc0c66d2bf04226cdc723b Mon Sep 17 00:00:00 2001 From: Alexander Kavon Date: Mon, 22 Jan 2024 20:46:39 -0500 Subject: remove unneccessary Request.ParseForm() calls and update password placeholder on user create/auth pages --- src/post/routes.go | 43 ++++++++++++++++++++++++++++++++++++++++++ src/user/routes.go | 3 --- ui/pages/user/create.tmpl.html | 2 +- ui/pages/user/login.tmpl.html | 2 +- 4 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 src/post/routes.go diff --git a/src/post/routes.go b/src/post/routes.go new file mode 100644 index 0000000..9932004 --- /dev/null +++ b/src/post/routes.go @@ -0,0 +1,43 @@ +package post + +import ( + "log" + "net/http" + + "github.com/volatiletech/sqlboiler/boil" + "gitlab.com/alexkavon/newsstand/src/server" + "gitlab.com/alexkavon/newsstand/src/sessions" +) + +var Routes = server.Routes{ + server.Route{ + Name: "Create", + Method: "GET", + Path: "/p/create", + HandlerFunc: Create, + Middlewares: server.NewMiddlewares(sessions.AuthSession), + }, +} + +func Create(s *server.Server) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + s.Ui.Render(w, r, "post/create", nil) + } +} + +func Store(s *server.Server) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var post models.Post + post.Title = r.PostFormValue("title") + post.Url = r.PostFormValue("url") + post.Description = r.PostFormValue("description") + + err := post.Insert(r.Context(), s.Db.ToSqlDb(), boil.Infer()) + if err != nil { + log.Fatal("Insert Error", err) + } + + // increment user points maybe + + } +} diff --git a/src/user/routes.go b/src/user/routes.go index 28e0ccb..0ac3e54 100644 --- a/src/user/routes.go +++ b/src/user/routes.go @@ -63,8 +63,6 @@ func Create(s *server.Server) http.HandlerFunc { func Store(s *server.Server) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - r.ParseForm() - var user models.User user.Username = r.PostFormValue("username") user.Secret = r.PostFormValue("secret") @@ -92,7 +90,6 @@ func LoginForm(s *server.Server) http.HandlerFunc { func Login(s *server.Server) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - r.ParseForm() // look up the user from the db user, err := models.Users(models.UserWhere.Username.EQ(r.PostFormValue("username"))).One(r.Context(), s.Db.ToSqlDb()) if err != nil { diff --git a/ui/pages/user/create.tmpl.html b/ui/pages/user/create.tmpl.html index 7d18436..135b7bc 100644 --- a/ui/pages/user/create.tmpl.html +++ b/ui/pages/user/create.tmpl.html @@ -9,7 +9,7 @@ diff --git a/ui/pages/user/login.tmpl.html b/ui/pages/user/login.tmpl.html index 408dd64..e091322 100644 --- a/ui/pages/user/login.tmpl.html +++ b/ui/pages/user/login.tmpl.html @@ -9,7 +9,7 @@ -- cgit v1.2.3