login works, but no logout; bookmarks broken
This commit is contained in:
parent
1ef117de29
commit
41649d47c9
@ -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;
|
||||||
|
@ -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
|
||||||
|
@ -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,26 +100,27 @@
|
|||||||
{:href (href last)} (str last)]]]]))
|
{:href (href last)} (str last)]]]]))
|
||||||
|
|
||||||
(defn thread-page [thread]
|
(defn thread-page [thread]
|
||||||
(let [{:keys [id title page page-count content]} thread]
|
(binding [*thread* thread]
|
||||||
(main-template
|
(let [{:keys [id title page page-count content]} thread]
|
||||||
{:title title}
|
(main-template
|
||||||
[:div.container
|
{:title title}
|
||||||
[:h1.is-size-3.mb-4 title]]
|
[:div.container
|
||||||
[:section.thread
|
[:h1.is-size-3.mb-4 title]]
|
||||||
(for [post content]
|
[:section.thread
|
||||||
[:article.container.box
|
(for [post content]
|
||||||
[:div.tile.is-ancestor
|
[:article.container.box
|
||||||
[:aside.userinfo.tile.is-3.is-parent
|
[:div.tile.is-ancestor
|
||||||
(:ui post)]
|
[:aside.userinfo.tile.is-3.is-parent
|
||||||
[:main.postbody.content.tile.is-9.is-parent.is-vertical
|
(:ui post)]
|
||||||
[:div.tile.is-child
|
[:main.postbody.content.tile.is-9.is-parent.is-vertical
|
||||||
(:pb post)]
|
[:div.tile.is-child
|
||||||
[:div.level.tile.is-child.is-12
|
(:pb post)]
|
||||||
[:div.level-right
|
[:div.level.tile.is-child.is-12
|
||||||
[:span.postdate.level-item
|
[:div.level-right
|
||||||
(:pd post)]]]]]])]
|
[:span.postdate.level-item
|
||||||
[:section
|
(:pd post)]]]]]])]
|
||||||
(paginate (str "/thread/" id) page page-count)])))
|
[:section
|
||||||
|
(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]
|
||||||
|
Loading…
Reference in New Issue
Block a user