accept username

pull/1/head
vilmibm 2023-02-28 23:18:11 +00:00
parent 9de98bf2ab
commit 8716140b40
1 changed files with 13 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import (
"strings" "strings"
"git.tilde.town/tildetown/town/invites" "git.tilde.town/tildetown/town/invites"
"git.tilde.town/tildetown/town/stats"
"github.com/AlecAivazis/survey/v2" "github.com/AlecAivazis/survey/v2"
"github.com/charmbracelet/lipgloss" "github.com/charmbracelet/lipgloss"
@ -41,7 +42,7 @@ func promptCode() (code string, err error) {
return return
} }
func promptUsername() (un string, err error) { func promptUsername(townData stats.TildeData) (un string, err error) {
unPrompt := &survey.Input{ unPrompt := &survey.Input{
Message: "desired username?", Message: "desired username?",
} }
@ -50,9 +51,11 @@ func promptUsername() (un string, err error) {
survey.WithIcons(surveyIconSet), survey.WithIcons(surveyIconSet),
survey.WithValidator(func(val interface{}) error { survey.WithValidator(func(val interface{}) error {
un := val.(string) un := val.(string)
// TODO check for exising username for _, v := range townData.Users {
fmt.Println(un) if v.Username == un {
return errors.New("that username is already in use, sorry")
}
}
return nil return nil
})) }))
@ -60,6 +63,11 @@ func promptUsername() (un string, err error) {
} }
func _main() error { func _main() error {
townData, err := stats.Stats()
if err != nil {
return err
}
inviteDB, err := invites.ConnectDB() inviteDB, err := invites.ConnectDB()
if err != nil { if err != nil {
return err return err
@ -94,7 +102,7 @@ func _main() error {
fmt.Println(s) fmt.Println(s)
data.Username, err = promptUsername() data.Username, err = promptUsername(townData)
if err != nil { if err != nil {
return err return err
} }