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 {
|
||||
verify, err := getEmailVerfier().Verify(u.Email)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !verify.Syntax.Valid {
|
||||
return errors.New("email is invalid")
|
||||
if tx.Statement.Changed("Email") {
|
||||
verify, err := getEmailVerfier().Verify(u.Email)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !verify.Syntax.Valid {
|
||||
return errors.New("email is invalid")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue