forked from kevadesu/forgejo
[GITEA] Allow changing the email address before activation (squash)
See https://codeberg.org/forgejo/forgejo/pulls/2300
This commit is contained in:
parent
ecfc3cb3f0
commit
030cdd6ae2
5 changed files with 52 additions and 52 deletions
|
@ -145,6 +145,33 @@ func AddEmailAddresses(ctx context.Context, u *user_model.User, emails []string)
|
|||
return nil
|
||||
}
|
||||
|
||||
// ReplaceInactivePrimaryEmail replaces the primary email of a given user, even if the primary is not yet activated.
|
||||
func ReplaceInactivePrimaryEmail(ctx context.Context, oldEmail string, email *user_model.EmailAddress) error {
|
||||
user := &user_model.User{}
|
||||
has, err := db.GetEngine(ctx).ID(email.UID).Get(user)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !has {
|
||||
return user_model.ErrUserNotExist{
|
||||
UID: email.UID,
|
||||
Name: "",
|
||||
KeyID: 0,
|
||||
}
|
||||
}
|
||||
|
||||
err = AddEmailAddresses(ctx, user, []string{email.Email})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = user_model.MakeEmailPrimaryWithUser(ctx, user, email)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return DeleteEmailAddresses(ctx, user, []string{oldEmail})
|
||||
}
|
||||
|
||||
func DeleteEmailAddresses(ctx context.Context, u *user_model.User, emails []string) error {
|
||||
for _, emailStr := range emails {
|
||||
// Check if address exists
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue