|
|
@ -827,8 +827,9 @@ func validateUser(u *User) error { |
|
|
|
return ValidateEmail(u.Email) |
|
|
|
return ValidateEmail(u.Email) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func updateUser(ctx context.Context, u *User, changePrimaryEmail bool) error { |
|
|
|
func updateUser(ctx context.Context, u *User, changePrimaryEmail bool, cols ...string) error { |
|
|
|
if err := validateUser(u); err != nil { |
|
|
|
err := validateUser(u) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -860,15 +861,34 @@ func updateUser(ctx context.Context, u *User, changePrimaryEmail bool) error { |
|
|
|
}); err != nil { |
|
|
|
}); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { // check if primary email in email_address table
|
|
|
|
|
|
|
|
primaryEmailExist, err := e.Where("uid=? AND is_primary=?", u.ID, true).Exist(&EmailAddress{}) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !primaryEmailExist { |
|
|
|
|
|
|
|
_, err = e.Insert(&EmailAddress{ |
|
|
|
|
|
|
|
Email: u.Email, |
|
|
|
|
|
|
|
UID: u.ID, |
|
|
|
|
|
|
|
IsActivated: true, |
|
|
|
|
|
|
|
IsPrimary: true, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_, err := e.ID(u.ID).AllCols().Update(u) |
|
|
|
if len(cols) == 0 { |
|
|
|
|
|
|
|
_, err = e.ID(u.ID).AllCols().Update(u) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
_, err = e.ID(u.ID).Cols(cols...).Update(u) |
|
|
|
|
|
|
|
} |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// UpdateUser updates user's information.
|
|
|
|
// UpdateUser updates user's information.
|
|
|
|
func UpdateUser(u *User, emailChanged bool) error { |
|
|
|
func UpdateUser(u *User, emailChanged bool, cols ...string) error { |
|
|
|
return updateUser(db.DefaultContext, u, emailChanged) |
|
|
|
return updateUser(db.DefaultContext, u, emailChanged, cols...) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// UpdateUserCols update user according special columns
|
|
|
|
// UpdateUserCols update user according special columns
|
|
|
|