diff options
| author | Alexander Kavon <me+git@alexkavon.com> | 2024-01-22 20:46:39 -0500 |
|---|---|---|
| committer | Alexander Kavon <me+git@alexkavon.com> | 2024-01-22 20:46:39 -0500 |
| commit | 481b799f9eced5432fdc0c66d2bf04226cdc723b (patch) | |
| tree | 554d4c3c02c5e455f45ee8ace642022694358337 | |
| parent | 5e3ae22cc745c4166c2c941047f9b485185cf0ea (diff) | |
remove unneccessary Request.ParseForm() calls and update password placeholder on user create/auth pages
| -rw-r--r-- | src/post/routes.go | 43 | ||||
| -rw-r--r-- | src/user/routes.go | 3 | ||||
| -rw-r--r-- | ui/pages/user/create.tmpl.html | 2 | ||||
| -rw-r--r-- | ui/pages/user/login.tmpl.html | 2 |
4 files changed, 45 insertions, 5 deletions
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 @@ </label> <label> Secret - <input type="password" placeholder="secret" name="secret" /> + <input type="password" placeholder="psspsspsspss" name="secret" /> </label> <button type="submit">Create</button> </form> 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 @@ </label> <label> Secret - <input type="password" placeholder="secret" name="secret" /> + <input type="password" placeholder="psspsspsspss" name="secret" /> </label> <button type="submit">Login</button> </form> |
