refactor: move checking of users name to api layer
This commit is contained in:
parent
a546089378
commit
c076d219d0
|
@ -109,6 +109,11 @@ func (a AccountAPI) register(jc jape.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if len(request.FirstName) == 0 || len(request.LastName) == 0 {
|
||||
_ = jc.Error(account.NewAccountError(account.ErrKeyAccountCreationFailed, nil), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
user, err := a.accounts.CreateAccount(request.Email, request.Password)
|
||||
if err != nil {
|
||||
_ = jc.Error(err, http.StatusUnauthorized)
|
||||
|
|
|
@ -2,9 +2,10 @@ package models
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
emailverifier "github.com/AfterShip/email-verifier"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
|
@ -26,14 +27,6 @@ type User struct {
|
|||
}
|
||||
|
||||
func (u *User) BeforeUpdate(tx *gorm.DB) error {
|
||||
if len(u.FirstName) == 0 {
|
||||
return errors.New("first name is empty")
|
||||
}
|
||||
|
||||
if len(u.LastName) == 0 {
|
||||
return errors.New("last name is empty")
|
||||
}
|
||||
|
||||
verify, err := getEmailVerfier().Verify(u.Email)
|
||||
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue