login
This commit is contained in:
parent
442c80ea98
commit
1ea948dc27
@ -16,16 +16,26 @@
|
|||||||
(parser/thread-map id page tresp)))
|
(parser/thread-map id page tresp)))
|
||||||
|
|
||||||
(defroutes app-routes
|
(defroutes app-routes
|
||||||
|
|
||||||
(GET "/" request (views/index-page request))
|
(GET "/" request (views/index-page request))
|
||||||
|
|
||||||
|
(GET "/login" [] (views/login-page))
|
||||||
|
(POST "/login" [username password :as {session :session}]
|
||||||
|
(let [resp-cookies (client/login-response username password session)]
|
||||||
|
{:headers {"Content-Type" "text/plain; charset=utf-8"}
|
||||||
|
:body (with-out-str (clojure.pprint/pprint resp-cookies))
|
||||||
|
:session (assoc session :cookies resp-cookies)}))
|
||||||
|
|
||||||
(GET "/thread/:id" [id :<< as-int
|
(GET "/thread/:id" [id :<< as-int
|
||||||
page :<< as-int
|
page :<< as-int
|
||||||
:as {session :session}]
|
:as {session :session}]
|
||||||
(let [thread (get-thread session id page)]
|
(let [thread (get-thread session id page)]
|
||||||
(views/thread-page thread)))
|
(views/thread-page thread)))
|
||||||
|
|
||||||
(route/not-found "Not Found"))
|
(route/not-found "Not Found"))
|
||||||
|
|
||||||
(def app
|
(def app
|
||||||
(-> app-routes
|
(-> app-routes
|
||||||
(wrap-defaults site-defaults)
|
(wrap-defaults site-defaults)
|
||||||
(wrap-session {:cookie-attrs {:max-age 3600}
|
(wrap-session {:cookie-attrs {:max-age (* 7 24 3600)}
|
||||||
:store (cookie-store {:key "12345678abcdefgh"})})))
|
:store (cookie-store {:key "699a7e4bd79b3f56"})})))
|
||||||
|
@ -14,19 +14,24 @@
|
|||||||
:pagenumber page}]
|
:pagenumber page}]
|
||||||
{:href base-url :params query})))
|
{:href base-url :params query})))
|
||||||
|
|
||||||
(defn do-login []
|
(defn login-response [username password session]
|
||||||
|
(with-open [client (http/create-client)]
|
||||||
(let [login-url (str url "account.php")
|
(let [login-url (str url "account.php")
|
||||||
cs (clj-http.cookies/cookie-store)]
|
params {:action "login"
|
||||||
(client/post login-url {:form-params {:action "login"
|
:username username
|
||||||
:username "xf86enodev"
|
:password password}
|
||||||
:password "triebhaftigke1t"}
|
resp (http/POST client login-url :body params)
|
||||||
:cookie-store cs})
|
status (http/status resp)
|
||||||
(clj-http.cookies/get-cookies cs)))
|
headers (http/headers resp)]
|
||||||
|
(-> resp
|
||||||
|
http/await
|
||||||
|
http/cookies))))
|
||||||
|
|
||||||
(defn thread-response [session url]
|
(defn thread-response [session url]
|
||||||
(with-open [client (http/create-client)]
|
(with-open [client (http/create-client)]
|
||||||
(let [{:keys [href params]} url
|
(let [{:keys [href params]} url
|
||||||
resp (http/GET client href :query params)
|
req-cookies (:cookies session)
|
||||||
|
resp (http/GET client href :query params :cookies req-cookies)
|
||||||
status (http/status resp)
|
status (http/status resp)
|
||||||
headers (http/headers resp)]
|
headers (http/headers resp)]
|
||||||
(-> resp
|
(-> resp
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
|
|
||||||
(defn parse-title [htree]
|
(defn parse-title [htree]
|
||||||
(-> (s/select (s/child (s/tag :title)) htree)
|
(-> (s/select (s/child (s/tag :title)) htree)
|
||||||
first :content first))
|
first :content first
|
||||||
|
(string/replace #" - The Something Awful Forums" "")))
|
||||||
|
|
||||||
(defn parse-pagecount [htree]
|
(defn parse-pagecount [htree]
|
||||||
(-> (s/select (s/descendant
|
(-> (s/select (s/descendant
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
(:require [clojure.string :as string]
|
(:require [clojure.string :as string]
|
||||||
[clojure.pprint]
|
[clojure.pprint]
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[cheshire.core :as json]))
|
[cheshire.core :as json]
|
||||||
|
[ring.util.anti-forgery :refer [anti-forgery-field]]))
|
||||||
|
|
||||||
|
|
||||||
(defn header-fragment []
|
(defn header-fragment []
|
||||||
@ -31,11 +32,31 @@
|
|||||||
|
|
||||||
(defn index-page [req]
|
(defn index-page [req]
|
||||||
(main-template
|
(main-template
|
||||||
{}
|
{:title "Index"}
|
||||||
[:div.container
|
[:div.container
|
||||||
[:pre.output
|
[:pre.output
|
||||||
[:code (with-out-str (clojure.pprint/pprint req))]]]))
|
[:code (with-out-str (clojure.pprint/pprint req))]]]))
|
||||||
|
|
||||||
|
(defn login-page []
|
||||||
|
(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"]]]]]))
|
||||||
|
|
||||||
(defn paginate [id cur last]
|
(defn paginate [id cur last]
|
||||||
[:nav.container.box.pagination {:hx-boot "false"}
|
[:nav.container.box.pagination {:hx-boot "false"}
|
||||||
[:a.pagination-previous
|
[:a.pagination-previous
|
||||||
|
Loading…
Reference in New Issue
Block a user