summaryrefslogtreecommitdiff
path: root/client/login_prompt.go
diff options
context:
space:
mode:
Diffstat (limited to 'client/login_prompt.go')
-rw-r--r--client/login_prompt.go96
1 files changed, 84 insertions, 12 deletions
diff --git a/client/login_prompt.go b/client/login_prompt.go
index c19d987..ec5b36b 100644
--- a/client/login_prompt.go
+++ b/client/login_prompt.go
@@ -7,7 +7,11 @@ import (
type loginPrompt struct {
input tui.TextInput
+ uid string
username string
+ customPrompt string
+ waiting bool
+ callback func(ok bool)
}
func newLoginPrompt(completeName string) *loginPrompt {
@@ -21,28 +25,96 @@ func newLoginPrompt(completeName string) *loginPrompt {
}
func (p *loginPrompt) Input() *tui.TextInput {
- return &p.input
+ if !p.waiting {
+ return &p.input
+ } else {
+ return &tui.TextInput {}
+ }
}
func (p *loginPrompt) Send(text string) {
- if p.username != "" {
- return
- }
- p.username = text
- globalApp.auth(text, func(success bool) {
- if success {
+ if p.uid == "" {
+ p.username = text
+ globalApp.authAnon(text, func(success bool, uid string) {
+ if success {
+ globalApp.removePrompt(p)
+ globalApp.cmdWindow.warn(
+ "you have created a temporary account. " +
+ "set a password to keep it.",
+ )
+ } else if uid == "" {
+ p.username = ""
+ } else {
+ p.uid = uid
+ p.input.SetText("")
+ p.input.Private = true
+ }
+ })
+ } else {
+ p.input.SetText("")
+ p.waiting = true
+ globalApp.authPassword(p.uid, text, func(success bool) {
+ p.waiting = false
+ if !globalApp.authenticated {
+ p.uid = ""
+ p.input.SetText(p.username)
+ p.input.Private = false
+ return
+ }
globalApp.removePrompt(p)
+ if p.callback != nil {
+ p.callback(success)
+ }
+ })
+ }
+}
+
+func (p *loginPrompt) ShowStatusLine() {
+ tui.Text("[", nil)
+ tui.Text("login", &tui.Style {
+ Bg: tui.White, Fg: tui.Blue, Bold: true,
+ })
+ tui.Text("] ", nil)
+ if p.customPrompt == "" {
+ if p.uid == "" {
+ tui.Text("username", nil)
} else {
- p.username = ""
+ tui.Text("password", nil)
}
- })
+ } else {
+ tui.Text(p.customPrompt, nil)
+ }
+ tui.Text(":", nil)
}
-func (p *loginPrompt) ShowStatusLine() {
+type passwordChangePrompt struct {
+ input tui.TextInput
+ password string
+}
+
+func (p *passwordChangePrompt) Input() *tui.TextInput {
+ p.input.Private = true
+ return &p.input
+}
+
+func (p *passwordChangePrompt) Send(text string) {
+ if text != p.password {
+ globalApp.cmdWindow.err("passwords do not match")
+ } else {
+ globalApp.setPassword(text, func(ok bool) {
+ if ok {
+ globalApp.cmdWindow.info("password changed")
+ }
+ })
+ }
+ globalApp.removePrompt(p)
+}
+
+func (p *passwordChangePrompt) ShowStatusLine() {
tui.Text("[", nil)
tui.Text("login", &tui.Style {
Bg: tui.White, Fg: tui.Blue, Bold: true,
})
- tui.Text("]", nil)
- tui.Text(" username:", nil)
+ tui.Text("] ", nil)
+ tui.Text("confirm new password:", nil)
}