create password auth skeleton

This commit is contained in:
2025-03-30 20:54:41 -04:00
parent cd4ebf9dc7
commit 824ca781d4
4 changed files with 95 additions and 17 deletions

View File

@@ -19,8 +19,29 @@ func dbGetUser(id string) (*User, error) {
user := u.(map[string]interface{})
if user["ID"].(string) == id {
return &User{
ID: user["ID"].(string),
Name: user["Name"].(string),
ID: user["ID"].(string),
Name: user["Name"].(string),
Password: user["Password"].(string),
}, nil
}
}
return nil, errors.New("User not found")
}
func dbGetUserByName(username string) (*User, error) {
data := db.ExecDB("users")
if data == nil {
return nil, errors.New("failed to load users database")
}
users := data["users"].([]interface{})
for _, u := range users {
user := u.(map[string]interface{})
if user["Name"].(string) == username {
return &User{
ID: user["ID"].(string),
Name: user["Name"].(string),
Password: user["Password"].(string),
}, nil
}
}
@@ -133,8 +154,9 @@ func dbAddUser(user *User) error {
}
dbUser := map[string]interface{}{
"ID": user.ID,
"Name": user.Name,
"ID": user.ID,
"Name": user.Name,
"Password": user.Password,
}
users = append(users, dbUser)