diff options
| author | Alexander Kavon <me+git@alexkavon.com> | 2024-01-23 06:33:20 -0500 |
|---|---|---|
| committer | Alexander Kavon <me+git@alexkavon.com> | 2024-01-23 06:33:20 -0500 |
| commit | 8d92bdf7da95e1085485c0e60b9dac19c246e235 (patch) | |
| tree | 5c346f8bdb10b3b8084a3b9e95c727f7fa3914be /src | |
| parent | 8510c36ded85740885e67b59ee2ec2360986c0a9 (diff) | |
move ui templates into src, update conf to handle other paths, export User Insert Hooks
Diffstat (limited to 'src')
| -rw-r--r-- | src/conf/conf.go | 14 | ||||
| -rw-r--r-- | src/db/db.go | 1 | ||||
| -rw-r--r-- | src/ui/pages/post/create.tmpl.html | 20 | ||||
| -rw-r--r-- | src/ui/pages/post/get.tmpl.html | 26 | ||||
| -rw-r--r-- | src/ui/pages/user/create.tmpl.html | 16 | ||||
| -rw-r--r-- | src/ui/pages/user/login.tmpl.html | 16 | ||||
| -rw-r--r-- | src/ui/pages/user/me.tmpl.html | 5 | ||||
| -rw-r--r-- | src/ui/templates/base.tmpl.html | 14 | ||||
| -rw-r--r-- | src/ui/templates/comments.tmpl.html | 16 | ||||
| -rw-r--r-- | src/ui/templates/messages.tmpl.html | 9 | ||||
| -rw-r--r-- | src/user/hooks.go | 2 | ||||
| -rw-r--r-- | src/user/routes.go | 5 |
12 files changed, 135 insertions, 9 deletions
diff --git a/src/conf/conf.go b/src/conf/conf.go index 62ffb57..a0852dc 100644 --- a/src/conf/conf.go +++ b/src/conf/conf.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "os" + "path/filepath" "github.com/BurntSushi/toml" ) @@ -39,15 +40,16 @@ func NewConf() *Conf { if err != nil { log.Fatal(err) } - filepath := os.Getenv("NEWSSTAND_CONFIG_PATH") - if filepath == "" { - filepath = cwd + "/.newsstandrc.toml" + configpath := os.Getenv("NEWSSTAND_CONFIG_PATH") + if configpath == "" { + configpath = "./.newsstandrc.toml" } - log.Printf("Config file path: %s", filepath) + confpath := filepath.Clean(filepath.Join(cwd, configpath)) + log.Printf("Config file path: %s", confpath) c := Conf{ cwd, - filepath, + confpath, Db{ Hostname: "localhost", }, @@ -55,7 +57,7 @@ func NewConf() *Conf { UiPath: cwd + "/ui", }, } - _, err = toml.DecodeFile(filepath, &c) + _, err = toml.DecodeFile(confpath, &c) if err != nil { log.Fatalln(err) } diff --git a/src/db/db.go b/src/db/db.go index 198b2be..1a5b9ab 100644 --- a/src/db/db.go +++ b/src/db/db.go @@ -28,7 +28,6 @@ func NewDb(config *conf.Conf) *Db { } log.Println("Database connection pool created.", testquery) return &Db{pool} - } func (d *Db) Conn() *pgxpool.Pool { diff --git a/src/ui/pages/post/create.tmpl.html b/src/ui/pages/post/create.tmpl.html new file mode 100644 index 0000000..385ed22 --- /dev/null +++ b/src/ui/pages/post/create.tmpl.html @@ -0,0 +1,20 @@ +{{define "title"}}Create Post{{end}} + +{{define "main"}} + <h1>Whatcha Got?</h1> + <form action="/p" method="POST"> + <label> + Title + <input type="text" placeholder="NYC Voted Best Place to Live By NYers" name="title" /> + <span>Title will be automatically pulled from URL if not provided.</span> + </label> + <label> + Description + <textarea placeholder="Spit it out already." name="description"></textarea> + </label> + <label> + URL + <input type="url" placeholder="https://cheesy.pizza/01/01/1970/first-post" name="url" /> + <button type="submit">Yup</button> + </form> +{{end}} diff --git a/src/ui/pages/post/get.tmpl.html b/src/ui/pages/post/get.tmpl.html new file mode 100644 index 0000000..b32bd1c --- /dev/null +++ b/src/ui/pages/post/get.tmpl.html @@ -0,0 +1,26 @@ +{{define "title"}}{{.post.Title}}{{end}} + +{{define "main"}} + <a class="title" href="{{.post.URL.String}}" target="_blank">{{.post.Title}}</a> + <span class="post-tags"> + {{range $tag := .post.R.Tags}} + <span class="post-tag-{{$tag.Tag}}">{{$tag.Tag}}</span> + {{end}} + </span> + <span class="post-domain">{{.post.URL.String}} (Pretty URL)</span> + <span class="post-author">by <a href="u/{{.post.R.User.ID}}">{{.post.R.User.Username}}</a></span> + <span class="post-date">{{.post.CreatedAt.Format "Jan 02, 2006 15:04"}}</span> + <span class="actions"> + <span class="action-flag">Flag</span> + <span class="action-hide">Hide</span> + </span> + {{ if .post.Description.Valid }} + <p>{{.post.Description.String}}</p> + {{end}} + <form action="/p/{{.post.ID}}/comment" method="POST"> + <textarea placeholder="This better be good." name="comment"></textarea> + <button type="submit">Yup</button> + <button class="preview" type="button">Preview</button> + </form> + {{template "comments" .}} +{{end}} diff --git a/src/ui/pages/user/create.tmpl.html b/src/ui/pages/user/create.tmpl.html new file mode 100644 index 0000000..135b7bc --- /dev/null +++ b/src/ui/pages/user/create.tmpl.html @@ -0,0 +1,16 @@ +{{define "title"}}Create User{{end}} + +{{define "main"}} + <h1>Create User</h1> + <form action="/u" method="POST"> + <label> + Username + <input type="text" placeholder="username" name="username" /> + </label> + <label> + Secret + <input type="password" placeholder="psspsspsspss" name="secret" /> + </label> + <button type="submit">Create</button> + </form> +{{end}} diff --git a/src/ui/pages/user/login.tmpl.html b/src/ui/pages/user/login.tmpl.html new file mode 100644 index 0000000..e091322 --- /dev/null +++ b/src/ui/pages/user/login.tmpl.html @@ -0,0 +1,16 @@ +{{define "title"}}Login{{end}} + +{{define "main"}} + <h1>Login</h1> + <form action="/u/auth" method="POST"> + <label> + Username + <input type="text" placeholder="username" name="username" /> + </label> + <label> + Secret + <input type="password" placeholder="psspsspsspss" name="secret" /> + </label> + <button type="submit">Login</button> + </form> +{{end}} diff --git a/src/ui/pages/user/me.tmpl.html b/src/ui/pages/user/me.tmpl.html new file mode 100644 index 0000000..be66beb --- /dev/null +++ b/src/ui/pages/user/me.tmpl.html @@ -0,0 +1,5 @@ +{{define "title"}}Profile{{end}} + +{{define "main"}} +<h1>Welcome, {{ .session.Get "username" }}</h1> +{{end}} diff --git a/src/ui/templates/base.tmpl.html b/src/ui/templates/base.tmpl.html new file mode 100644 index 0000000..a080925 --- /dev/null +++ b/src/ui/templates/base.tmpl.html @@ -0,0 +1,14 @@ +{{define "base"}} +<!DOCTYPE html> +<html lang="en"> +<head> + <title>{{template "title" .}} | newsstand.nyc</title> + <link rel="stylesheet" href="https://unpkg.com/@blaze/css@x.x.x/dist/blaze/blaze.css"> + <script src="https://unpkg.com/htmx.org@1.9.9" integrity="sha384-QFjmbokDn2DjBjq+fM+8LUIVrAgqcNW2s0PjAxHETgRn9l4fvX31ZxDxvwQnyMOX" crossorigin="anonymous"></script> +</head> +<body> + {{template "messages" .}} + {{template "main" .}} +</body> +</html> +{{end}} diff --git a/src/ui/templates/comments.tmpl.html b/src/ui/templates/comments.tmpl.html new file mode 100644 index 0000000..b069bbd --- /dev/null +++ b/src/ui/templates/comments.tmpl.html @@ -0,0 +1,16 @@ +{{define "comments"}} +<div id="post-comments"> + {{range $comment := .comments }} + <span class="comment-author">by <a href="/u/{{$comment.username}}">{{$comment.username}}</a></span> + <span class="comment-created-at">{{$comment.created_at}}</span> + <span class="actions"> + <span class="action-flag">Flag</span> + <span class="action-hide">Hide</span> + <span class="action-reply">Reply</span> + </span> + <div class="c-alert c-alert--info" role="alert"> + {{ $comment.body }} + </div> + {{ end }} +</div> +{{end}} diff --git a/src/ui/templates/messages.tmpl.html b/src/ui/templates/messages.tmpl.html new file mode 100644 index 0000000..dd5bfb1 --- /dev/null +++ b/src/ui/templates/messages.tmpl.html @@ -0,0 +1,9 @@ +{{define "messages"}} +<div id="messages"> + {{ if .message }} + <div class="c-alert c-alert--info" role="alert"> + {{ .message }} + </div> + {{ end }} +</div> +{{end}} diff --git a/src/user/hooks.go b/src/user/hooks.go index 61e24bc..c7b7632 100644 --- a/src/user/hooks.go +++ b/src/user/hooks.go @@ -8,7 +8,7 @@ import ( "gitlab.com/alexkavon/newsstand/src/models" ) -func init() { +func InitHooks() { models.AddUserHook(boil.BeforeInsertHook, validateNew) // should always be last models.AddUserHook(boil.BeforeInsertHook, hashSecretBeforeInsert) diff --git a/src/user/routes.go b/src/user/routes.go index 862545a..eaf4582 100644 --- a/src/user/routes.go +++ b/src/user/routes.go @@ -10,6 +10,10 @@ import ( "gitlab.com/alexkavon/newsstand/src/sessions" ) +func init() { + InitHooks() +} + var Routes = server.Routes{ server.Route{ Name: "Create", @@ -73,7 +77,6 @@ func Store(s *server.Server) http.HandlerFunc { if err != nil { log.Fatal("Insert Error", err) } - // Send email validation // Create cookie session sessions.NewSession(w, sessions.SessionValues{"uid": user.ID, "username": user.Username}) // Redirect to user profile |
