diff --git a/http/session.go b/http/session.go
index 197b9d5..e82c467 100644
--- a/http/session.go
+++ b/http/session.go
@@ -98,27 +98,37 @@ func (h *Handler) loginPost(c *gin.Context) {
})
}
-func (h *Handler) registerPost(c *gin.Context) {
- email, _ := c.GetPostForm("email")
- password, _ := c.GetPostForm("password")
- name, _ := c.GetPostForm("name")
+type registerInformation struct {
+ Password string `json:"password"`
+ Email string `json:"email"`
+ Name string `json:"name"`
+}
- _, err := h.Service.GetUserByUsername(c.Request.Context(), email)
- if err == nil {
- c.AbortWithStatus(http.StatusUnauthorized)
+func (h *Handler) registerPost(c *gin.Context) {
+ var register registerInformation
+ c.BindJSON(®ister)
+
+ if register.Email == "" || register.Password == "" || register.Name == "" {
+ c.AbortWithError(http.StatusBadRequest, fmt.Errorf("e-mail, password and name are required"))
return
}
- hash, err := h.CredentialsVerifier.Hash(password)
+ _, err := h.Service.GetUserByUsername(c.Request.Context(), register.Email)
+ if err == nil {
+ c.AbortWithError(http.StatusUnauthorized, err)
+ return
+ }
+
+ hash, err := h.CredentialsVerifier.Hash(register.Password)
if err != nil {
c.AbortWithError(http.StatusUnauthorized, err)
return
}
createUser := postgres.CreateUserParams{
- Name: name,
+ Name: register.Name,
Password: hash,
- Email: email,
+ Email: register.Email,
}
_, err = h.Service.CreateUser(c.Request.Context(), createUser)
if err != nil {
diff --git a/web/src/App.vue b/web/src/App.vue
index 9f7b9eb..cdcca6f 100644
--- a/web/src/App.vue
+++ b/web/src/App.vue
@@ -19,13 +19,19 @@ export default {
-
- - Login
- - Logout
- - Dashboard
-
+
+
+
+ - Login
+ - Logout
+ - Dashboard
+
+
-
+
+
+
+