Remove login functionality (#202)

This commit is contained in:
ayntgl 2022-08-31 19:40:13 +05:30 • committed by GitHub
parent fcd52c361e
commit 35458a7e3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 85 deletions

View file

@ -62,13 +62,13 @@ sudo mv ./discordo /usr/local/bin
## Usage
1. Run the `discordo` executable with no arguments to log in using email and password. If you are using a token to log in, set the `token` flag to the token that you want to log in with.
1. Run the `discordo` executable with no arguments.
- Note: If you are logging in with a bot account, prefix the token with `Bot ` (eg: `discordo --token "Bot OTI2MDU5NTQxNDE2Nzc5ODA2.Yc2KKA.2iZ-5JxgxG-9Ub8GHzBSn-NJjNg"`). Furthermore, it is strongly recommended to change the user agent for HTTP requests from the configuration file if you are using a bot account to log in since the default user agent is that of a browser.
2. Enter your client authentication token (first-time login) and click on the "Login" button to continue.
2. If you are logging in with your email and password, enter your email and password (first-time login) and click on the "Login" button to continue.
- If you are logging in with a bot account, prefix the token with `Bot ` (eg: `discordo --token "Bot OTI2MDU5NTQxNDE2Nzc5ODA2.Yc2KKA.2iZ-5JxgxG-9Ub8GHzBSn-NJjNg"`). Furthermore, it is strongly recommended to change the user agent for HTTP requests from the configuration file if you are using a bot account to log in since the default user agent is that of a browser.
- Note: Your email and password are not stored locally. Most of the Discord third-party clients store the token in a configuration file unencrypted. Discordo securely stores the token in the default OS-specific keyring.
- Most of the Discord third-party clients store the token in a configuration file unencrypted. Discordo securely stores the token in the default OS-specific keyring.
### Configuration

View file

@ -19,7 +19,7 @@ type Config struct {
State *lua.LState
}
func NewConfig(path string) *Config {
func New(path string) *Config {
return &Config{
Path: path,
State: lua.NewState(),

67
main.go
View file

@ -55,59 +55,29 @@ func main() {
c.Application.SetRoot(c.MainFlex, true)
c.Application.SetFocus(c.GuildsTree)
} else {
loginForm := ui.NewLoginForm(false)
loginForm := tview.NewForm()
loginForm.AddPasswordField("Token", "", 0, 0, nil)
loginForm.SetButtonsAlign(tview.AlignCenter)
loginForm.SetTitle("Login")
loginForm.SetTitleAlign(tview.AlignLeft)
loginForm.SetBorder(true)
loginForm.SetBorderPadding(0, 0, 1, 1)
loginForm.AddButton("Login", func() {
email := loginForm.GetFormItem(0).(*tview.InputField).GetText()
password := loginForm.GetFormItem(1).(*tview.InputField).GetText()
if email == "" || password == "" {
tkn := loginForm.GetFormItem(0).(*tview.InputField).GetText()
if tkn == "" {
return
}
// Login using the email and password only
lr, err := c.State.Login(email, password)
err := c.Run(tkn)
if err != nil {
log.Fatal(err)
}
if lr.Token != "" && !lr.MFA {
err = c.Run(lr.Token)
if err != nil {
log.Fatal(err)
}
c.DrawMainFlex()
c.Application.SetRoot(c.MainFlex, true)
c.Application.SetFocus(c.GuildsTree)
go keyring.Set(name, "token", lr.Token)
} else {
// The account has MFA enabled, reattempt login with MFA code and ticket.
mfaLoginForm := ui.NewLoginForm(true)
mfaLoginForm.AddButton("Login", func() {
code := mfaLoginForm.GetFormItem(0).(*tview.InputField).GetText()
if code == "" {
return
}
lr, err = c.State.TOTP(code, lr.Ticket)
if err != nil {
log.Fatal(err)
}
err = c.Run(lr.Token)
if err != nil {
log.Fatal(err)
}
c.DrawMainFlex()
c.Application.SetRoot(c.MainFlex, true)
c.Application.SetFocus(c.GuildsTree)
go keyring.Set(name, "token", lr.Token)
})
c.Application.SetRoot(mfaLoginForm, true)
}
c.DrawMainFlex()
c.Application.SetRoot(c.MainFlex, true)
c.Application.SetFocus(c.GuildsTree)
})
c.Application.SetRoot(loginForm, true)
@ -126,11 +96,6 @@ func main() {
tview.Borders.Horizontal = 0
tview.Borders.Vertical = 0
err := c.Config.Load()
if err != nil {
return
}
themeTable, ok := c.Config.State.GetGlobal("theme").(*lua.LTable)
if !ok {
themeTable = c.Config.State.NewTable()
@ -144,7 +109,7 @@ func main() {
tview.Styles.BorderColor = tcell.GetColor(lua.LVAsString(border))
tview.Styles.TitleColor = tcell.GetColor(lua.LVAsString(title))
err = c.Application.Run()
err := c.Application.Run()
if err != nil {
log.Fatal(err)
}

View file

@ -47,7 +47,7 @@ func NewCore(path string) *Core {
Application: tview.NewApplication(),
MainFlex: tview.NewFlex(),
Config: config.NewConfig(path),
Config: config.New(path),
}
c.MainFlex.SetInputCapture(c.onInputCapture)

View file

@ -1,28 +0,0 @@
package ui
import "github.com/rivo/tview"
type LoginForm struct {
*tview.Form
}
func NewLoginForm(mfa bool) *LoginForm {
lf := &LoginForm{
Form: tview.NewForm(),
}
if mfa {
lf.AddPasswordField("Authentication/Backup Code", "", 0, 0, nil)
} else {
lf.
AddInputField("Email", "", 0, nil, nil).
AddPasswordField("Password", "", 0, 0, nil)
}
lf.SetButtonsAlign(tview.AlignCenter)
lf.SetTitle("Login")
lf.SetTitleAlign(tview.AlignLeft)
lf.SetBorder(true)
lf.SetBorderPadding(0, 0, 1, 1)
return lf
}