feat: hash user's password on register
This commit is contained in:
@ -6,6 +6,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"gitea.local/admin/hspguard/internal/repository"
|
"gitea.local/admin/hspguard/internal/repository"
|
||||||
|
"gitea.local/admin/hspguard/internal/util"
|
||||||
"gitea.local/admin/hspguard/internal/web"
|
"gitea.local/admin/hspguard/internal/web"
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
)
|
)
|
||||||
@ -51,10 +52,16 @@ func (h *UserHandler) register(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
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{
|
id, err := h.repo.InsertUser(context.Background(), repository.InsertUserParams{
|
||||||
FullName: params.FullName,
|
FullName: params.FullName,
|
||||||
Email: params.Email,
|
Email: params.Email,
|
||||||
PasswordHash: params.Password,
|
PasswordHash: hash,
|
||||||
IsAdmin: false,
|
IsAdmin: false,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user