Переглянути джерело

Remove login functionality (#202)

ayntgl 3 роки тому
батько
коміт
35458a7e3a
5 змінених файлів з 22 додано та 85 видалено
  1. 4 4
      README.md
  2. 1 1
      config/config.go
  3. 16 51
      main.go
  4. 1 1
      ui/core.go
  5. 0 28
      ui/login_form.go

+ 4 - 4
README.md

@@ -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
 

+ 1 - 1
config/config.go

@@ -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(),

+ 16 - 51
main.go

@@ -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)
 	}

+ 1 - 1
ui/core.go

@@ -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)

+ 0 - 28
ui/login_form.go

@@ -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
-}