cmd/sojuctl: read user from DB before updating it

This makes sure we don't overwrite other fields, such as Admin.

Closes: https://todo.sr.ht/~emersion/soju/85
This commit is contained in:
Simon Ser 2020-08-11 10:21:49 +02:00
parent ccc8768435
commit c1f8002428
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -94,12 +94,12 @@ func main() {
log.Fatalf("failed to hash password: %v", err)
}
user := soju.User{
Created: true,
Username: username,
Password: string(hashed),
user, err := db.GetUser(username)
if err != nil {
log.Fatalf("failed to get user: %v", err)
}
if err := db.StoreUser(&user); err != nil {
user.Password = string(hashed)
if err := db.StoreUser(user); err != nil {
log.Fatalf("failed to update password: %v", err)
}
default: