2018-12-18 13:19:32 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
2018-12-19 11:06:58 +02:00
|
|
|
"strings"
|
|
|
|
|
2018-12-18 13:19:32 +02:00
|
|
|
"github.com/jesseduffield/gocui"
|
2020-10-04 02:00:48 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
2018-12-18 13:19:32 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type credentials chan string
|
|
|
|
|
2020-10-10 02:43:59 +02:00
|
|
|
// promptUserForCredential wait for a username, password or passphrase input from the credentials popup
|
2020-08-11 12:29:05 +02:00
|
|
|
func (gui *Gui) promptUserForCredential(passOrUname string) string {
|
2018-12-18 13:19:32 +02:00
|
|
|
gui.credentials = make(chan string)
|
2020-08-11 12:25:36 +02:00
|
|
|
gui.g.Update(func(g *gocui.Gui) error {
|
2021-04-04 16:31:52 +02:00
|
|
|
credentialsView := gui.Views.Credentials
|
2020-11-16 11:38:26 +02:00
|
|
|
switch passOrUname {
|
|
|
|
case "username":
|
2020-10-04 02:00:48 +02:00
|
|
|
credentialsView.Title = gui.Tr.CredentialsUsername
|
2018-12-18 13:19:32 +02:00
|
|
|
credentialsView.Mask = 0
|
2020-11-16 11:38:26 +02:00
|
|
|
case "password":
|
2020-10-04 02:00:48 +02:00
|
|
|
credentialsView.Title = gui.Tr.CredentialsPassword
|
2018-12-18 13:19:32 +02:00
|
|
|
credentialsView.Mask = '*'
|
2020-11-16 11:38:26 +02:00
|
|
|
default:
|
2020-10-10 02:43:59 +02:00
|
|
|
credentialsView.Title = gui.Tr.CredentialsPassphrase
|
|
|
|
credentialsView.Mask = '*'
|
2018-12-18 13:19:32 +02:00
|
|
|
}
|
2020-08-16 05:58:29 +02:00
|
|
|
|
2021-04-03 06:56:11 +02:00
|
|
|
if err := gui.pushContext(gui.State.Contexts.Credentials); err != nil {
|
2018-12-18 13:19:32 +02:00
|
|
|
return err
|
|
|
|
}
|
2020-08-16 05:58:29 +02:00
|
|
|
|
2018-12-18 13:19:32 +02:00
|
|
|
gui.RenderCommitLength()
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
2020-10-10 02:43:59 +02:00
|
|
|
// wait for username/passwords/passphrase input
|
2018-12-18 13:19:32 +02:00
|
|
|
userInput := <-gui.credentials
|
2018-12-18 13:23:17 +02:00
|
|
|
return userInput + "\n"
|
2018-12-18 13:19:32 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleSubmitCredential() error {
|
2021-04-04 15:51:59 +02:00
|
|
|
credentialsView := gui.Views.Credentials
|
2021-10-17 04:00:44 +02:00
|
|
|
message := strings.TrimSpace(credentialsView.TextArea.GetContent())
|
2018-12-18 13:19:32 +02:00
|
|
|
gui.credentials <- message
|
2021-10-17 08:38:59 +02:00
|
|
|
credentialsView.ClearTextArea()
|
2020-08-16 05:58:29 +02:00
|
|
|
if err := gui.returnFromContext(); err != nil {
|
2018-12-18 13:19:32 +02:00
|
|
|
return err
|
|
|
|
}
|
2020-08-16 05:58:29 +02:00
|
|
|
|
2021-04-08 16:33:39 +02:00
|
|
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
2018-12-18 13:19:32 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleCloseCredentialsView() error {
|
2018-12-18 13:23:17 +02:00
|
|
|
gui.credentials <- ""
|
2020-08-16 05:58:29 +02:00
|
|
|
return gui.returnFromContext()
|
2018-12-18 13:19:32 +02:00
|
|
|
}
|
|
|
|
|
2020-08-15 09:01:43 +02:00
|
|
|
func (gui *Gui) handleCredentialsViewFocused() error {
|
2020-10-03 06:54:55 +02:00
|
|
|
keybindingConfig := gui.Config.GetUserConfig().Keybinding
|
|
|
|
|
2020-10-04 02:00:48 +02:00
|
|
|
message := utils.ResolvePlaceholderString(
|
|
|
|
gui.Tr.CloseConfirm,
|
|
|
|
map[string]string{
|
2020-10-03 06:54:55 +02:00
|
|
|
"keyBindClose": gui.getKeyDisplay(keybindingConfig.Universal.Return),
|
|
|
|
"keyBindConfirm": gui.getKeyDisplay(keybindingConfig.Universal.Confirm),
|
2018-12-18 13:19:32 +02:00
|
|
|
},
|
|
|
|
)
|
2020-10-04 02:00:48 +02:00
|
|
|
|
2021-04-04 16:31:52 +02:00
|
|
|
gui.renderString(gui.Views.Options, message)
|
2020-03-09 02:34:10 +02:00
|
|
|
return nil
|
2018-12-18 13:19:32 +02:00
|
|
|
}
|
|
|
|
|
2020-08-11 13:41:32 +02:00
|
|
|
// handleCredentialsPopup handles the views after executing a command that might ask for credentials
|
|
|
|
func (gui *Gui) handleCredentialsPopup(cmdErr error) {
|
2018-12-18 13:19:32 +02:00
|
|
|
if cmdErr != nil {
|
2018-12-19 11:12:35 +02:00
|
|
|
errMessage := cmdErr.Error()
|
2020-10-10 02:43:59 +02:00
|
|
|
if strings.Contains(errMessage, "Invalid username, password or passphrase") {
|
2020-10-04 02:00:48 +02:00
|
|
|
errMessage = gui.Tr.PassUnameWrong
|
2018-12-19 11:06:58 +02:00
|
|
|
}
|
2021-04-08 16:33:39 +02:00
|
|
|
_ = gui.returnFromContext()
|
2020-10-10 02:43:59 +02:00
|
|
|
// we are not logging this error because it may contain a password or a passphrase
|
2020-11-16 11:38:26 +02:00
|
|
|
_ = gui.createErrorPanel(errMessage)
|
2020-08-11 13:29:18 +02:00
|
|
|
} else {
|
2020-08-23 05:16:44 +02:00
|
|
|
_ = gui.closeConfirmationPrompt(false)
|
2018-12-18 13:19:32 +02:00
|
|
|
}
|
|
|
|
}
|