Implement register and login using vuetify
This commit is contained in:
@ -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 {
|
||||
|
Reference in New Issue
Block a user