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; margin: 0 auto;
} }
#login-form .control {
min-width: 20rem;
max-width: 30vw;
}
nav.pagination { nav.pagination {
background-color: #fff; background-color: #fff;
margin-top: 2rem; margin-top: 2rem;

View File

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

View File

@ -1,12 +1,46 @@
(ns clojsa.views (ns clojsa.views
(:use [hiccup core page]) (:require [hiccup.core :refer [html]]
(:require [clojure.pprint] [hiccup.page :refer [html5 include-css include-js]]
[clojure.pprint]
[ring.util.anti-forgery :refer [anti-forgery-field]])) [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 [] (defn header-fragment []
(html (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] (defn main-template [opts & insert-body-here]
(html5 (html5
@ -38,23 +72,7 @@
(main-template (main-template
{:title "login"} {:title "login"}
[:div.container.box [:div.container.box
[:form#login-form {:action "/login" :method "post"} (login-form "")]))
(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"]]]]]))
(defn paginate [base cur last] (defn paginate [base cur last]
(let [page-fstring "%s?page=%d" (let [page-fstring "%s?page=%d"
@ -82,6 +100,7 @@
{:href (href last)} (str last)]]]])) {:href (href last)} (str last)]]]]))
(defn thread-page [thread] (defn thread-page [thread]
(binding [*thread* thread]
(let [{:keys [id title page page-count content]} thread] (let [{:keys [id title page page-count content]} thread]
(main-template (main-template
{:title title} {:title title}
@ -101,7 +120,7 @@
[:span.postdate.level-item [:span.postdate.level-item
(:pd post)]]]]]])] (:pd post)]]]]]])]
[:section [:section
(paginate (str "/thread/" id) page page-count)]))) (paginate (str "/thread/" id) page page-count)]))))
(defn bookmarks-page [beems] (defn bookmarks-page [beems]
(let [{:keys [title page page-count content]} beems] (let [{:keys [title page page-count content]} beems]