fix: use tx.Statement.Changed to ensure email is being changed before validating it
This commit is contained in:
parent
c076d219d0
commit
11f30700c3
|
@ -27,14 +27,14 @@ type User struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) BeforeUpdate(tx *gorm.DB) error {
|
func (u *User) BeforeUpdate(tx *gorm.DB) error {
|
||||||
verify, err := getEmailVerfier().Verify(u.Email)
|
if tx.Statement.Changed("Email") {
|
||||||
|
verify, err := getEmailVerfier().Verify(u.Email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if !verify.Syntax.Valid {
|
||||||
if !verify.Syntax.Valid {
|
return errors.New("email is invalid")
|
||||||
return errors.New("email is invalid")
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue