discordo/internal/ui/login/password/msg.go

46 lines
1,003 B
Go

package password
import (
"errors"
"github.com/ayn2op/arikawa/v3/utils/httputil"
"github.com/ayn2op/discordo/internal/http"
"github.com/ayn2op/tview"
)
type TokenMsg string
// inputMsg is the text and cursor that typing in an input left.
type inputMsg struct {
text string
cursor int
}
type (
loginMsg inputMsg
passwordMsg inputMsg
focusMsg focus
submitMsg struct{}
)
func submitLogin(login, password string) tview.Cmd {
return func() tview.Msg {
headers := http.Headers()
headers.Set("Referer", "https://discord.com/login")
client := http.NewClient("")
client.OnRequest = append(client.OnRequest, httputil.WithHeaders(headers))
loginResp, err := client.Login(login, password)
if err != nil {
return err
}
if loginResp.Token == "" {
if loginResp.MFA {
return errors.New("multi-factor authentication is required; use token or QR login")
}
return errors.New("login response did not include a token")
}
return TokenMsg(loginResp.Token)
}
}