use embedded validation
This commit is contained in:
parent
9b2a795e5c
commit
c453422cac
@ -8,7 +8,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gopkg.in/validator.v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@ -52,8 +51,8 @@ func NewAccount(login string, password string) *Account {
|
||||
|
||||
// Service
|
||||
type SignupOrLoginRequest struct {
|
||||
Login string `validate:"min=3,max=40,regexp=^[a-zA-Z0-9]*$"`
|
||||
Password string `validate:"min=8,max=40"`
|
||||
Login string `binding:"min=3,max=40,alphanum"`
|
||||
Password string `binding:"min=8,max=40"`
|
||||
}
|
||||
|
||||
func (s *Service) Signup(c *gin.Context) {
|
||||
@ -62,10 +61,6 @@ func (s *Service) Signup(c *gin.Context) {
|
||||
if c.BindJSON(&account) != nil {
|
||||
return
|
||||
}
|
||||
if err := validator.Validate(account); err != nil {
|
||||
c.AbortWithError(http.StatusExpectationFailed, err)
|
||||
return
|
||||
}
|
||||
|
||||
var accountExists int64
|
||||
if err := s.DB.Model(&Account{}).Where("login = ?", account.Login).Count(&accountExists).Error; err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user