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