aboutsummaryrefslogtreecommitdiff
path: root/src/user/routes.go
diff options
context:
space:
mode:
authorAlexander Kavon <me+git@alexkavon.com>2024-01-22 14:56:36 -0500
committerAlexander Kavon <me+git@alexkavon.com>2024-01-22 14:56:36 -0500
commita1df83e8b5737a198a3fba4de23ca2c80828f623 (patch)
tree95ae9bc9a87b945e149373d9753c8e158f003a6f /src/user/routes.go
parent4f15e271f541ecd525268efa40992e0f5c057e12 (diff)
added validation for user fields on sqlboiler.BeforeInsertHook, added hashing of secret before insert
Diffstat (limited to 'src/user/routes.go')
-rw-r--r--src/user/routes.go20
1 files changed, 3 insertions, 17 deletions
diff --git a/src/user/routes.go b/src/user/routes.go
index b163fb7..7cbd3fb 100644
--- a/src/user/routes.go
+++ b/src/user/routes.go
@@ -4,7 +4,6 @@ import (
"log"
"net/http"
- "github.com/go-playground/validator/v10"
"github.com/volatiletech/sqlboiler/v4/boil"
"gitlab.com/alexkavon/newsstand/src/models"
"gitlab.com/alexkavon/newsstand/src/server"
@@ -70,23 +69,10 @@ func Store(s *server.Server) http.HandlerFunc {
user.Username = r.PostFormValue("username")
user.Secret = r.PostFormValue("secret")
user.Email = r.PostFormValue("email")
- // Validate User Input
- v := validator.New()
- err := v.Struct(user)
- if err != nil {
- log.Fatal("Validator failed", err.(validator.ValidationErrors))
- }
-
- // Hash secret
- secret := &Secret{Raw: user.Secret}
- err = secret.HashSecret()
- if err != nil {
- log.Fatal("Hash failure", err)
- }
- user.Secret = secret.Hash()
- // Store user
- err = user.Insert(r.Context(), s.Db.ToSqlDb(), boil.Infer())
+ // Store user, this package (user) will init
+ // a validation hook to check values and hash secret
+ err := user.Insert(r.Context(), s.Db.ToSqlDb(), boil.Infer())
if err != nil {
log.Fatal("Insert Error", err)
}