diff options
Diffstat (limited to 'conf/user.go')
-rw-r--r-- | conf/user.go | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/conf/user.go b/conf/user.go index e4a0169..5ceaefb 100644 --- a/conf/user.go +++ b/conf/user.go @@ -40,14 +40,16 @@ func GetPassword(prompt string) (string, error) { func ConfirmPassword() string { password, err := GetPassword("Enter Password: ") if err != nil { log.Fatal(err) } + fmt.Println() password1, err := GetPassword("Confirm Password: ") if err != nil { log.Fatal(err) } + fmt.Println() if password != password1 { log.Fatal("passwords do not match!") } return password } -func GetUser() User { +func GetUser() db.User { OpenDb() username, err := GetUsername("Username: ") if err != nil { log.Fatal(err) } @@ -68,7 +70,7 @@ func CreateUser() *Command { if err != nil { log.Fatal(err) } password := ConfirmPassword() - _, err = p.CreateUser(username, password1) + _, err = p.CreateUser(username, password) if err != nil { log.Fatal(err) } fmt.Printf("created user %v\n", username) }, @@ -97,9 +99,29 @@ func UpdatePassword() *Command { Invoke: func() { user := GetUser() password := ConfirmPassword() - err := SetPassword(user, password) + err := p.SetPassword(user, password) if err != nil { log.Fatal(err) } fmt.Printf("updated password for user %v\n", user.Name) }, } } + + +func ListUsers() *Command { + return &Command{ + Flag: "list-users", + Usage: "list all users", + Invoke: func() { + OpenDb() + users, err := p.AllUsers() + if err != nil { log.Fatal(err) } + fmt.Println("id\t\tname") + fmt.Println("========================================") + for _, user := range users { + fmt.Printf( + "%v\t\t%v\n", user.Id, user.Name, + ) + } + }, + } +} |