fix: user creation

This commit is contained in:
d34dscene
2025-04-15 13:07:24 +02:00
parent f53605656e
commit f623bba119
4 changed files with 55 additions and 6 deletions
+29
View File
@@ -55,6 +55,12 @@ func CreateUser(a *config.App) http.HandlerFunc {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
hash, err := util.HashPassword(user.Password)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
user.Password = hash
if err := q.CreateUser(r.Context(), user); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -109,3 +115,26 @@ func DeleteUser(a *config.App) http.HandlerFunc {
w.WriteHeader(http.StatusNoContent)
}
}
func UpdateUserPassword(a *config.App) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
q := a.Conn.GetQuery()
var user db.UpdateUserPasswordParams
if err := json.NewDecoder(r.Body).Decode(&user); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Hash
hash, err := util.HashPassword(user.Password)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
user.Password = hash
if err := q.UpdateUserPassword(r.Context(), user); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusNoContent)
}
}