From add10cb754183819d33a1316266455950420733f Mon Sep 17 00:00:00 2001 From: vilmibm Date: Wed, 1 Mar 2023 00:10:45 +0000 Subject: [PATCH] email collection --- cmd/welcome/main.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/cmd/welcome/main.go b/cmd/welcome/main.go index d9f196c..88695ad 100644 --- a/cmd/welcome/main.go +++ b/cmd/welcome/main.go @@ -3,6 +3,7 @@ package main import ( "errors" "fmt" + "net/mail" "os" "regexp" "strings" @@ -80,6 +81,27 @@ func promptUsername(townData stats.TildeData) (un string, err error) { return "", nil } +func promptEmail(defaultEmail string) (email string, err error) { + emailPrompt := &survey.Input{ + Message: "e-mail (for account recovery only)?", + Default: defaultEmail, + } + err = survey.AskOne(emailPrompt, &email, + survey.WithValidator(survey.Required), + survey.WithIcons(surveyIconSet), + survey.WithValidator(func(val interface{}) error { + email := val.(string) + _, err := mail.ParseAddress(email) + if err != nil { + return fmt.Errorf("could not understand that email: %w", err) + } + + return nil + })) + + return "", nil +} + func _main() error { townData, err := stats.Stats() if err != nil { @@ -125,8 +147,11 @@ func _main() error { return err } - // TODO collect username - // TODO collect email + data.Email, err = promptEmail(invite.Email) + if err != nil { + return err + } + // TODO collect public key // TODO have enough to make account; can now do that // TODO assuming account creation succeeded, mark invite as used