fixed multipart form issue

This commit is contained in:
Fran Jurmanović
2021-06-05 00:10:23 +02:00
parent 1406c74e67
commit 636a367d3e
12 changed files with 66 additions and 35 deletions

View File

@@ -20,13 +20,14 @@ func NewAuthController(rs *services.UsersService, s *gin.RouterGroup) *AuthContr
s.POST("login", rc.PostLogin)
s.POST("register", rc.PostRegister)
s.DELETE("deactivate", middleware.Auth, rc.Delete)
s.GET("check-token", rc.CheckToken)
return rc
}
func (rc *AuthController) PostLogin(c *gin.Context) {
body := new(models.Login)
if err := c.ShouldBindJSON(&body); err != nil {
if err := c.ShouldBind(&body); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
@@ -43,7 +44,7 @@ func (rc *AuthController) PostRegister(c *gin.Context) {
body := new(models.User)
body.Init()
body.IsActive = true
if err := c.ShouldBindJSON(body); err != nil {
if err := c.ShouldBind(body); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
@@ -68,3 +69,19 @@ func (rc *AuthController) Delete(c *gin.Context) {
c.JSON(200, mr)
}
}
func (rc *AuthController) CheckToken(c *gin.Context) {
token, _ := c.GetQuery("token")
re := new(models.CheckToken)
valid, err := middleware.CheckToken(token)
if err != nil && valid.Valid {
re.Valid = false
c.AbortWithStatusJSON(400, re)
}
re.Valid = true
c.JSON(200, re)
}

View File

@@ -24,7 +24,7 @@ func NewTransactionTypeController(as *services.TransactionTypeService, s *gin.Ro
func (wc *TransactionTypeController) New(c *gin.Context) {
body := new(models.NewTransactionTypeBody)
if err := c.ShouldBindJSON(body); err != nil {
if err := c.ShouldBind(body); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

View File

@@ -24,7 +24,7 @@ func NewTransactionController(as *services.TransactionService, s *gin.RouterGrou
func (wc *TransactionController) New(c *gin.Context) {
body := new(models.NewTransactionBody)
if err := c.ShouldBindJSON(body); err != nil {
if err := c.ShouldBind(body); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

View File

@@ -25,7 +25,7 @@ func NewWalletsController(as *services.WalletService, s *gin.RouterGroup) *Walle
func (wc *WalletsController) New(c *gin.Context) {
body := new(models.NewWalletBody)
if err := c.ShouldBindJSON(body); err != nil {
if err := c.ShouldBind(body); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}