summaryrefslogtreecommitdiff
path: root/conf/user.go
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2023-05-02 14:15:25 -0500
committersanine-a <sanine.not@pm.me>2023-05-02 14:15:25 -0500
commite365e8c2fd4e3a595c696849734236008fc67e1f (patch)
tree072316b0ff99dd94d698090b6ad3b02ab7852d95 /conf/user.go
parent9fe48ae66c2cc8d6b46e44ae35e9447ab51d9dd6 (diff)
implement basic user operations
Diffstat (limited to 'conf/user.go')
-rw-r--r--conf/user.go28
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,
+ )
+ }
+ },
+ }
+}