login works, but no logout; bookmarks broken

This commit is contained in:
rdiedrich 2020-06-26 14:38:37 +02:00
parent 1ef117de29
commit 41649d47c9
3 changed files with 67 additions and 43 deletions

View File

@ -14,6 +14,11 @@ body {
margin: 0 auto;
}
#login-form .control {
min-width: 20rem;
max-width: 30vw;
}
nav.pagination {
background-color: #fff;
margin-top: 2rem;

View File

@ -2,7 +2,7 @@
(:require [clojsa.views :as views]
[clojsa.saclient :as client]
[clojsa.saparser :as parser]
[compojure.core :refer :all]
[compojure.core :refer [defroutes GET POST]]
[compojure.route :as route]
[compojure.coercions :refer [as-int]]
[ring.middleware.defaults :refer [wrap-defaults site-defaults]]
@ -27,10 +27,10 @@
(GET "/login" [] (views/login-page))
(POST "/login" [username password :as {session :session}]
(POST "/login" [username password next :as {session :session}]
(let [resp-cookies (client/login-response username password session)]
{:status 302
:headers {"Location" "/bookmarks"}
:headers {"Location" next}
:session (assoc session :cookies resp-cookies)}))
(GET "/bookmarks" [page :<< as-int

View File

@ -1,12 +1,46 @@
(ns clojsa.views
(:use [hiccup core page])
(:require [clojure.pprint]
(:require [hiccup.core :refer [html]]
[hiccup.page :refer [html5 include-css include-js]]
[clojure.pprint]
[ring.util.anti-forgery :refer [anti-forgery-field]]))
(def ^:dynamic *thread* {})
(defn login-form []
[:form#login-form {:action "/login" :method "post"}
(anti-forgery-field)
[:input {:type "hidden" :name "next"
:value (format "/thread/%d?page=%d" (:id *thread*) (:page *thread*))}]
[:div.field
[:label.label {:for "username"} "username"]
[:div.control
[:input#username.input {:name "username" :type "text"
:placeholder "enter your username"}]]]
[:div.field
[:label.label {:for "password"} "password"]
[:div.control
[:input#password.input {:name "password" :type "password"
:placeholder "enter your password"}]]]
[:div.field
[:div.control
[:button.button.is-primary "Submit"]]]])
(defn header-fragment []
(html
[:nav]))
[:nav.navbar
[:div.navbar-brand
[:a.burger.navbar-burger {:role "button" :data-target "mainNav"}
(repeat 3 [:span {:aria-hidden "true"}])]]
[:div#mainNav.navbar-menu
[:div.navbar-start
[:a.navbar-item {:href "/bookmarks"} "Bookmarks"]]
[:div.navbar-end
[:div.navbar-item.has-dropdown.is-hoverable
[:a.navbar-link "Login"]
[:div.navbar-dropdown.is-right
[:div.navbar-item
(login-form)]]]]]]))
(defn main-template [opts & insert-body-here]
(html5
@ -38,23 +72,7 @@
(main-template
{:title "login"}
[:div.container.box
[:form#login-form {:action "/login" :method "post"}
(anti-forgery-field)
[:div.field
[:label.label {:for "username"}
"username"]
[:div.control
[:input#username.input {:name "username" :type "text"
:placeholder "enter your username"}]]]
[:div.field
[:label.label {:for "password"}
"password"]
[:div.control
[:input#password.input {:name "password" :type "password"
:placeholder "enter your password"}]]]
[:div.field
[:div.control
[:button.button.is-primary "Submit"]]]]]))
(login-form "")]))
(defn paginate [base cur last]
(let [page-fstring "%s?page=%d"
@ -82,26 +100,27 @@
{:href (href last)} (str last)]]]]))
(defn thread-page [thread]
(let [{:keys [id title page page-count content]} thread]
(main-template
{:title title}
[:div.container
[:h1.is-size-3.mb-4 title]]
[:section.thread
(for [post content]
[:article.container.box
[:div.tile.is-ancestor
[:aside.userinfo.tile.is-3.is-parent
(:ui post)]
[:main.postbody.content.tile.is-9.is-parent.is-vertical
[:div.tile.is-child
(:pb post)]
[:div.level.tile.is-child.is-12
[:div.level-right
[:span.postdate.level-item
(:pd post)]]]]]])]
[:section
(paginate (str "/thread/" id) page page-count)])))
(binding [*thread* thread]
(let [{:keys [id title page page-count content]} thread]
(main-template
{:title title}
[:div.container
[:h1.is-size-3.mb-4 title]]
[:section.thread
(for [post content]
[:article.container.box
[:div.tile.is-ancestor
[:aside.userinfo.tile.is-3.is-parent
(:ui post)]
[:main.postbody.content.tile.is-9.is-parent.is-vertical
[:div.tile.is-child
(:pb post)]
[:div.level.tile.is-child.is-12
[:div.level-right
[:span.postdate.level-item
(:pd post)]]]]]])]
[:section
(paginate (str "/thread/" id) page page-count)]))))
(defn bookmarks-page [beems]
(let [{:keys [title page page-count content]} beems]