feat: hash user's password on register

This commit is contained in:
2025-05-21 21:17:50 +02:00
parent 55eb4c9862
commit 0b8c03e8c5

View File

@ -6,6 +6,7 @@ import (
"net/http"
"gitea.local/admin/hspguard/internal/repository"
"gitea.local/admin/hspguard/internal/util"
"gitea.local/admin/hspguard/internal/web"
"github.com/go-chi/chi/v5"
)
@ -51,10 +52,16 @@ func (h *UserHandler) register(w http.ResponseWriter, r *http.Request) {
return
}
hash, err := util.HashPassword(params.Password)
if err != nil {
web.Error(w, "failed to create user account", http.StatusInternalServerError)
return
}
id, err := h.repo.InsertUser(context.Background(), repository.InsertUserParams{
FullName: params.FullName,
Email: params.Email,
PasswordHash: params.Password,
PasswordHash: hash,
IsAdmin: false,
})
if err != nil {