Allow passing embedded "ReturnHeaders" object to get response headers in handlers if necessary e.g. captcha cookie?
Parse set-cookie header and store session cookie in client if set-cookie contains connect.sid cookie Remove some json definitions for option arguments to client methodsmaster
parent
0bd911d6bf
commit
3fac0d046f
5 changed files with 110 additions and 27 deletions
@ -0,0 +1,40 @@ |
||||
package jschan |
||||
|
||||
import ( |
||||
"context" |
||||
"fmt" |
||||
"net/http" |
||||
"net/url" |
||||
"strings" |
||||
) |
||||
|
||||
type PostLoginOptions struct { |
||||
Username string |
||||
Password string |
||||
Twofactor string |
||||
} |
||||
|
||||
func (c *Client) Login(ctx context.Context, options *PostLoginOptions) error { |
||||
|
||||
formData := url.Values{} |
||||
formData.Set("username", options.Username) |
||||
formData.Set("password", options.Password) |
||||
formData.Set("twofactor", options.Twofactor) |
||||
endodedBody := strings.NewReader(formData.Encode()) |
||||
|
||||
url := fmt.Sprintf("%s/forms/login", c.BaseURL) |
||||
|
||||
req, err := http.NewRequest(http.MethodPost, url, endodedBody) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
|
||||
req = req.WithContext(ctx) |
||||
|
||||
if err := c.sendRequest(req, nil, nil); err != nil { |
||||
return err |
||||
} |
||||
|
||||
return nil |
||||
|
||||
} |
Loading…
Reference in new issue