You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
725 B
40 lines
725 B
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
|
|
|
|
}
|
|
|