From e365e8c2fd4e3a595c696849734236008fc67e1f Mon Sep 17 00:00:00 2001 From: sanine-a Date: Tue, 2 May 2023 14:15:25 -0500 Subject: implement basic user operations --- conf/user.go | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'conf/user.go') 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, + ) + } + }, + } +} -- cgit v1.2.1