main: remove "login via token" method
This commit is contained in:
parent
044e48da2e
commit
71cc017f0e
3 changed files with 16 additions and 69 deletions
44
discordo.go
44
discordo.go
|
|
@ -28,7 +28,6 @@ var (
|
|||
messageInputField *tview.InputField
|
||||
mainFlex *tview.Flex
|
||||
|
||||
loginVia string
|
||||
kr keyring.Keyring
|
||||
config *util.Config
|
||||
discordSession *session.Session
|
||||
|
|
@ -55,7 +54,6 @@ func main() {
|
|||
config = util.NewConfig()
|
||||
|
||||
app = ui.NewApp(onAppInputCapture)
|
||||
loginModal = ui.NewLoginModal(onLoginModalDone)
|
||||
guildsDropDown = ui.NewGuildsDropDown(onGuildsDropDownSelected, config.Theme)
|
||||
channelsTreeNode = tview.NewTreeNode("")
|
||||
channelsTreeView = ui.NewChannelsTreeView(channelsTreeNode, onChannelsTreeViewSelected, config.Theme)
|
||||
|
|
@ -70,7 +68,8 @@ func main() {
|
|||
|
||||
discordSession = newSession("", "", token)
|
||||
} else {
|
||||
app.SetRoot(loginModal, true)
|
||||
loginForm = ui.NewLoginForm(onLoginFormLoginButtonSelected)
|
||||
app.SetRoot(loginForm, true)
|
||||
}
|
||||
|
||||
if err := app.Run(); err != nil {
|
||||
|
|
@ -95,18 +94,6 @@ func onAppInputCapture(e *tcell.EventKey) *tcell.EventKey {
|
|||
return e
|
||||
}
|
||||
|
||||
func onLoginModalDone(i int, label string) {
|
||||
if label == ui.LoginViaEmailPasswordLoginModalButton {
|
||||
loginVia = "emailpassword"
|
||||
loginForm = ui.NewLoginForm(loginVia, onLoginFormLoginButtonSelected)
|
||||
app.SetRoot(loginForm, true)
|
||||
} else if label == ui.LoginViaTokenLoginModalButton {
|
||||
loginVia = "token"
|
||||
loginForm = ui.NewLoginForm(loginVia, onLoginFormLoginButtonSelected)
|
||||
app.SetRoot(loginForm, true)
|
||||
}
|
||||
}
|
||||
|
||||
func newSession(email string, password string, token string) *session.Session {
|
||||
api.UserAgent = "" +
|
||||
"Mozilla/5.0 (X11; Linux x86_64) " +
|
||||
|
|
@ -224,28 +211,17 @@ func onChannelsTreeViewSelected(n *tview.TreeNode) {
|
|||
}
|
||||
|
||||
func onLoginFormLoginButtonSelected() {
|
||||
if loginVia == "emailpassword" {
|
||||
email := loginForm.GetFormItemByLabel("Email").(*tview.InputField).GetText()
|
||||
password := loginForm.GetFormItemByLabel("Password").(*tview.InputField).GetText()
|
||||
if email == "" || password == "" {
|
||||
return
|
||||
}
|
||||
|
||||
discordSession = newSession(email, password, "")
|
||||
|
||||
go util.SetItem(kr, "token", discordSession.Token)
|
||||
} else if loginVia == "token" {
|
||||
token := loginForm.GetFormItemByLabel("Token").(*tview.InputField).GetText()
|
||||
if token == "" {
|
||||
return
|
||||
}
|
||||
|
||||
discordSession = newSession("", "", token)
|
||||
|
||||
go util.SetItem(kr, "token", token)
|
||||
email := loginForm.GetFormItemByLabel("Email").(*tview.InputField).GetText()
|
||||
password := loginForm.GetFormItemByLabel("Password").(*tview.InputField).GetText()
|
||||
if email == "" || password == "" {
|
||||
return
|
||||
}
|
||||
|
||||
app.
|
||||
SetRoot(mainFlex, true).
|
||||
SetFocus(guildsDropDown)
|
||||
|
||||
discordSession = newSession(email, password, "")
|
||||
|
||||
go util.SetItem(kr, "token", discordSession.Token)
|
||||
}
|
||||
|
|
|
|||
19
ui/forms.go
19
ui/forms.go
|
|
@ -5,23 +5,16 @@ import (
|
|||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
func NewLoginForm(via string, onLoginFormLoginButtonSelected func()) *tview.Form {
|
||||
loginForm := tview.NewForm()
|
||||
|
||||
loginForm.
|
||||
func NewLoginForm(onLoginFormLoginButtonSelected func()) *tview.Form {
|
||||
f := tview.NewForm()
|
||||
f.
|
||||
AddInputField("Email", "", 0, nil, nil).
|
||||
AddPasswordField("Password", "", 0, 0, nil).
|
||||
AddButton("Login", onLoginFormLoginButtonSelected).
|
||||
SetButtonsAlign(tview.AlignCenter).
|
||||
SetButtonBackgroundColor(tcell.GetColor("#5865F2")).
|
||||
SetBorder(true).
|
||||
SetBorderPadding(0, 0, 1, 1)
|
||||
|
||||
if via == "token" {
|
||||
loginForm.AddPasswordField("Token", "", 0, 0, nil)
|
||||
} else if via == "emailpassword" {
|
||||
loginForm.
|
||||
AddInputField("Email", "", 0, nil, nil).
|
||||
AddPasswordField("Password", "", 0, 0, nil)
|
||||
}
|
||||
|
||||
return loginForm
|
||||
return f
|
||||
}
|
||||
|
|
|
|||
22
ui/modals.go
22
ui/modals.go
|
|
@ -1,22 +0,0 @@
|
|||
package ui
|
||||
|
||||
import (
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
const (
|
||||
LoginViaTokenLoginModalButton = "Login via token"
|
||||
LoginViaEmailPasswordLoginModalButton = "Login via email and password"
|
||||
)
|
||||
|
||||
func NewLoginModal(onLoginModalDone func(buttonIndex int, buttonLabel string)) *tview.Modal {
|
||||
m := tview.NewModal()
|
||||
m.
|
||||
SetText("Choose a login method:").
|
||||
AddButtons([]string{LoginViaTokenLoginModalButton, LoginViaEmailPasswordLoginModalButton}).
|
||||
SetDoneFunc(onLoginModalDone).
|
||||
SetBorder(true).
|
||||
SetBorderPadding(0, 0, 1, 1)
|
||||
|
||||
return m
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue