From 8716140b4093da93dab57653f8d74fdf0d29d14e Mon Sep 17 00:00:00 2001 From: vilmibm Date: Tue, 28 Feb 2023 23:18:11 +0000 Subject: [PATCH] accept username --- cmd/welcome/main.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/cmd/welcome/main.go b/cmd/welcome/main.go index 2bf426d..bb4d008 100644 --- a/cmd/welcome/main.go +++ b/cmd/welcome/main.go @@ -7,6 +7,7 @@ import ( "strings" "git.tilde.town/tildetown/town/invites" + "git.tilde.town/tildetown/town/stats" "github.com/AlecAivazis/survey/v2" "github.com/charmbracelet/lipgloss" @@ -41,7 +42,7 @@ func promptCode() (code string, err error) { return } -func promptUsername() (un string, err error) { +func promptUsername(townData stats.TildeData) (un string, err error) { unPrompt := &survey.Input{ Message: "desired username?", } @@ -50,9 +51,11 @@ func promptUsername() (un string, err error) { survey.WithIcons(surveyIconSet), survey.WithValidator(func(val interface{}) error { un := val.(string) - // TODO check for exising username - fmt.Println(un) - + for _, v := range townData.Users { + if v.Username == un { + return errors.New("that username is already in use, sorry") + } + } return nil })) @@ -60,6 +63,11 @@ func promptUsername() (un string, err error) { } func _main() error { + townData, err := stats.Stats() + if err != nil { + return err + } + inviteDB, err := invites.ConnectDB() if err != nil { return err @@ -94,7 +102,7 @@ func _main() error { fmt.Println(s) - data.Username, err = promptUsername() + data.Username, err = promptUsername(townData) if err != nil { return err }