accept username
parent
9de98bf2ab
commit
8716140b40
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue