Implement register and login using vuetify

This commit is contained in:
2022-01-24 16:00:01 +00:00
parent d59b9bdbec
commit 3de0447eba
7 changed files with 5841 additions and 43 deletions

View File

@ -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(&register)
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 {