blob: 320f535f515837ffb907bf482d01905404b25f0d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
package gui
import (
"strings"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/utils"
)
type credentials chan string
// promptUserForCredential wait for a username, password or passphrase input from the credentials popup
func (gui *Gui) promptUserForCredential(passOrUname string) string {
gui.credentials = make(chan string)
gui.g.Update(func(g *gocui.Gui) error {
credentialsView := gui.Views.Credentials
switch passOrUname {
case "username":
credentialsView.Title = gui.Tr.CredentialsUsername
credentialsView.Mask = 0
case "password":
credentialsView.Title = gui.Tr.CredentialsPassword
credentialsView.Mask = '*'
default:
credentialsView.Title = gui.Tr.CredentialsPassphrase
credentialsView.Mask = '*'
}
if err := gui.pushContext(gui.State.Contexts.Credentials); err != nil {
return err
}
gui.RenderCommitLength()
return nil
})
// wait for username/passwords/passphrase input
userInput := <-gui.credentials
return userInput + "\n"
}
func (gui *Gui) handleSubmitCredential() error {
credentialsView := gui.Views.Credentials
message := strings.TrimSpace(credentialsView.TextArea.GetContent())
gui.credentials <- message
credentialsView.ClearTextArea()
if err := gui.returnFromContext(); err != nil {
return err
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
}
func (gui *Gui) handleCloseCredentialsView() error {
gui.credentials <- ""
return gui.returnFromContext()
}
func (gui *Gui) handleCredentialsViewFocused() error {
keybindingConfig := gui.Config.GetUserConfig().Keybinding
message := utils.ResolvePlaceholderString(
gui.Tr.CloseConfirm,
map[string]string{
"keyBindClose": gui.getKeyDisplay(keybindingConfig.Universal.Return),
"keyBindConfirm": gui.getKeyDisplay(keybindingConfig.Universal.Confirm),
},
)
gui.renderString(gui.Views.Options, message)
return nil
}
// handleCredentialsPopup handles the views after executing a command that might ask for credentials
func (gui *Gui) handleCredentialsPopup(cmdErr error) {
if cmdErr != nil {
errMessage := cmdErr.Error()
if strings.Contains(errMessage, "Invalid username, password or passphrase") {
errMessage = gui.Tr.PassUnameWrong
}
_ = gui.returnFromContext()
// we are not logging this error because it may contain a password or a passphrase
_ = gui.createErrorPanel(errMessage)
} else {
_ = gui.closeConfirmationPrompt(false)
}
}
|