try to fix login by formatting the form correctly

This commit is contained in:
Milo Turner 2020-04-11 14:50:41 -04:00
parent 8c4b525cbf
commit bdcfead62c
1 changed files with 9 additions and 5 deletions

View File

@ -86,12 +86,16 @@
;; Logs in with the given username and password ;; Logs in with the given username and password
(define (crawler-login username password) (define (crawler-login username password)
(void (crawler-fetch 'POST LOGIN-PATH
(form-alist->http-body
`([username . ,username]
[password . ,password]
[csrfmiddlewaretoken . ,(crawler-get-csrf-token!)])))))
;; -> string?
(define (crawler-get-csrf-token!)
(crawler-fetch 'GET LOGIN-PATH) (crawler-fetch 'GET LOGIN-PATH)
(define form-body (cookie-jar-ref (current-cookie-jar) "csrftoken"))
(format "username=~a&password=~a&csrfmiddlewaretoken=~a&next="
username password (cookie-jar-ref (current-cookie-jar) "csrftoken")))
(crawler-fetch 'POST LOGIN-PATH (string->bytes/utf-8 form-body))
(void))
;; Checks if this is a URL we should crawl ;; Checks if this is a URL we should crawl
(define (crawler-valid-url? page-url) (define (crawler-valid-url? page-url)