40 lines
805 B
Go
40 lines
805 B
Go
package auth
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.tek.govt.hu/dowerx/szoe-pontok/database/auth"
|
|
"git.tek.govt.hu/dowerx/szoe-pontok/model"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin/binding"
|
|
"github.com/go-playground/validator/v10"
|
|
)
|
|
|
|
func Register(c *gin.Context) {
|
|
var user model.User
|
|
if c.MustBindWith(&user, binding.Form) != nil {
|
|
return
|
|
}
|
|
|
|
val := validator.New(validator.WithRequiredStructEnabled())
|
|
if err := val.Struct(user); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{
|
|
"status": http.StatusBadRequest,
|
|
"error": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
|
|
if err := auth.Register(user); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{
|
|
"status": http.StatusBadRequest,
|
|
"error": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"status": http.StatusOK,
|
|
})
|
|
}
|