diff options
author | Teddy Wing | 2017-03-11 10:49:45 +0100 |
---|---|---|
committer | Teddy Wing | 2017-03-11 10:49:45 +0100 |
commit | 94d099641cae95724045122de93c826fe054c919 (patch) | |
tree | a96ab6d9ffee1768a29711c5fe71b16fb830f515 /timetask/http.go | |
parent | d14b4bb9be46396843c346b468dada938364c25b (diff) | |
download | timetasker-94d099641cae95724045122de93c826fe054c919.tar.bz2 |
Get login working
Fill in the `Login` function to actually log in to Time Task. Pass
credentials in via test command flags.
Referenced https://gist.github.com/varver/f327ef9087ebf76aa4c4 for the
cookie setup.
Diffstat (limited to 'timetask/http.go')
-rw-r--r-- | timetask/http.go | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/timetask/http.go b/timetask/http.go index ae2fdc4..28e8b10 100644 --- a/timetask/http.go +++ b/timetask/http.go @@ -1,11 +1,33 @@ package timetask import ( - // "mime/multipart" "net/http" + "net/http/cookiejar" + "net/url" + + "golang.org/x/net/publicsuffix" ) -func Login() (resp *http.Response, err error) { - resp, err = http.Get("https://duckduckgo.com") +func Login(username, password string) (resp *http.Response, err error) { + cookies, err := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List}) + if err != nil { + return nil, err + } + + client := http.Client{Jar: cookies} + resp, err = client.PostForm( + "https://af83.timetask.com/index.php", + url.Values{ + "module": {"people"}, + "action": {"loginsubmit"}, + "f_url": {"/"}, + "f_username": {username}, + "f_password": {password}, + }, + ) + if err != nil { + return resp, err + } + return resp, err } |