2020-01-19 21:54:16 +00:00
|
|
|
package api
|
|
|
|
|
2021-06-02 02:53:19 +00:00
|
|
|
import "github.com/diamondburned/arikawa/v3/utils/httputil"
|
2020-01-19 21:54:16 +00:00
|
|
|
|
2020-04-19 16:30:12 +00:00
|
|
|
var (
|
2020-01-19 21:54:16 +00:00
|
|
|
EndpointAuth = Endpoint + "auth/"
|
|
|
|
EndpointLogin = EndpointAuth + "login"
|
|
|
|
EndpointTOTP = EndpointAuth + "mfa/totp"
|
|
|
|
)
|
|
|
|
|
|
|
|
type LoginResponse struct {
|
|
|
|
MFA bool `json:"mfa"`
|
|
|
|
SMS bool `json:"sms"`
|
|
|
|
Ticket string `json:"ticket"`
|
|
|
|
Token string `json:"token"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) Login(email, password string) (*LoginResponse, error) {
|
|
|
|
var param struct {
|
|
|
|
Email string `json:"email"`
|
|
|
|
Password string `json:"password"`
|
|
|
|
}
|
|
|
|
param.Email = email
|
|
|
|
param.Password = password
|
|
|
|
|
|
|
|
var r *LoginResponse
|
2020-05-08 03:43:46 +00:00
|
|
|
return r, c.RequestJSON(&r, "POST", EndpointLogin, httputil.WithJSONBody(param))
|
2020-01-19 21:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) TOTP(code, ticket string) (*LoginResponse, error) {
|
|
|
|
var param struct {
|
|
|
|
Code string `json:"code"`
|
|
|
|
Ticket string `json:"ticket"`
|
|
|
|
}
|
|
|
|
param.Code = code
|
|
|
|
param.Ticket = ticket
|
|
|
|
|
|
|
|
var r *LoginResponse
|
2020-05-08 03:43:46 +00:00
|
|
|
return r, c.RequestJSON(&r, "POST", EndpointTOTP, httputil.WithJSONBody(param))
|
2020-01-19 21:54:16 +00:00
|
|
|
}
|