summaryrefslogtreecommitdiff
path: root/conf
diff options
context:
space:
mode:
Diffstat (limited to 'conf')
-rw-r--r--conf/go.mod6
-rw-r--r--conf/go.sum4
-rw-r--r--conf/main.go3
-rw-r--r--conf/user.go28
4 files changed, 37 insertions, 4 deletions
diff --git a/conf/go.mod b/conf/go.mod
index 7349d9f..7ec1d45 100644
--- a/conf/go.mod
+++ b/conf/go.mod
@@ -4,9 +4,13 @@ go 1.19
replace sanine.net/git/phlox/db => ../db
-require sanine.net/git/phlox/db v0.0.0-00010101000000-000000000000
+require (
+ golang.org/x/term v0.7.0
+ sanine.net/git/phlox/db v0.0.0-00010101000000-000000000000
+)
require (
github.com/mattn/go-sqlite3 v1.14.16 // indirect
golang.org/x/crypto v0.8.0 // indirect
+ golang.org/x/sys v0.7.0 // indirect
)
diff --git a/conf/go.sum b/conf/go.sum
index 48de3bc..bd19da9 100644
--- a/conf/go.sum
+++ b/conf/go.sum
@@ -2,3 +2,7 @@ github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwp
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
+golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
+golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ=
+golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
diff --git a/conf/main.go b/conf/main.go
index f3a321e..dcd9737 100644
--- a/conf/main.go
+++ b/conf/main.go
@@ -47,6 +47,9 @@ func main() {
2: SchemaVersion(),
3: CreateUser(),
+ 4: DeleteUser(),
+ 5: UpdatePassword(),
+ 6: ListUsers(),
}
for val, cmd := range cmds {
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,
+ )
+ }
+ },
+ }
+}