summaryrefslogtreecommitdiffstats
path: root/models/user/email_address.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/user/email_address.go')
-rw-r--r--models/user/email_address.go27
1 files changed, 11 insertions, 16 deletions
diff --git a/models/user/email_address.go b/models/user/email_address.go
index 564d018dac..c931db9c16 100644
--- a/models/user/email_address.go
+++ b/models/user/email_address.go
@@ -207,7 +207,8 @@ func IsEmailUsed(ctx context.Context, email string) (bool, error) {
return db.GetEngine(ctx).Where("lower_email=?", strings.ToLower(email)).Get(&EmailAddress{})
}
-func addEmailAddress(ctx context.Context, email *EmailAddress) error {
+// AddEmailAddress adds an email address to given user.
+func AddEmailAddress(ctx context.Context, email *EmailAddress) error {
email.Email = strings.TrimSpace(email.Email)
used, err := IsEmailUsed(ctx, email.Email)
if err != nil {
@@ -223,11 +224,6 @@ func addEmailAddress(ctx context.Context, email *EmailAddress) error {
return db.Insert(ctx, email)
}
-// AddEmailAddress adds an email address to given user.
-func AddEmailAddress(email *EmailAddress) error {
- return addEmailAddress(db.DefaultContext, email)
-}
-
// AddEmailAddresses adds an email address to given user.
func AddEmailAddresses(emails []*EmailAddress) error {
if len(emails) == 0 {
@@ -311,14 +307,14 @@ func ActivateEmail(email *EmailAddress) error {
return err
}
defer committer.Close()
- if err := updateActivation(db.GetEngine(ctx), email, true); err != nil {
+ if err := updateActivation(ctx, email, true); err != nil {
return err
}
return committer.Commit()
}
-func updateActivation(e db.Engine, email *EmailAddress, activate bool) error {
- user, err := GetUserByIDEngine(e, email.UID)
+func updateActivation(ctx context.Context, email *EmailAddress, activate bool) error {
+ user, err := GetUserByIDCtx(ctx, email.UID)
if err != nil {
return err
}
@@ -326,10 +322,10 @@ func updateActivation(e db.Engine, email *EmailAddress, activate bool) error {
return err
}
email.IsActivated = activate
- if _, err := e.ID(email.ID).Cols("is_activated").Update(email); err != nil {
+ if _, err := db.GetEngine(ctx).ID(email.ID).Cols("is_activated").Update(email); err != nil {
return err
}
- return UpdateUserColsEngine(e, user, "rands")
+ return UpdateUserCols(ctx, user, "rands")
}
// MakeEmailPrimary sets primary email address of given user.
@@ -500,12 +496,11 @@ func ActivateUserEmail(userID int64, email string, activate bool) (err error) {
return err
}
defer committer.Close()
- sess := db.GetEngine(ctx)
// Activate/deactivate a user's secondary email address
// First check if there's another user active with the same address
addr := EmailAddress{UID: userID, LowerEmail: strings.ToLower(email)}
- if has, err := sess.Get(&addr); err != nil {
+ if has, err := db.GetByBean(ctx, &addr); err != nil {
return err
} else if !has {
return fmt.Errorf("no such email: %d (%s)", userID, email)
@@ -521,14 +516,14 @@ func ActivateUserEmail(userID int64, email string, activate bool) (err error) {
return ErrEmailAlreadyUsed{Email: email}
}
}
- if err = updateActivation(sess, &addr, activate); err != nil {
+ if err = updateActivation(ctx, &addr, activate); err != nil {
return fmt.Errorf("unable to updateActivation() for %d:%s: %w", addr.ID, addr.Email, err)
}
// Activate/deactivate a user's primary email address and account
if addr.IsPrimary {
user := User{ID: userID, Email: email}
- if has, err := sess.Get(&user); err != nil {
+ if has, err := db.GetByBean(ctx, &user); err != nil {
return err
} else if !has {
return fmt.Errorf("no user with ID: %d and Email: %s", userID, email)
@@ -539,7 +534,7 @@ func ActivateUserEmail(userID int64, email string, activate bool) (err error) {
if user.Rands, err = GetUserSalt(); err != nil {
return fmt.Errorf("unable to generate salt: %v", err)
}
- if err = UpdateUserColsEngine(sess, &user, "is_active", "rands"); err != nil {
+ if err = UpdateUserCols(ctx, &user, "is_active", "rands"); err != nil {
return fmt.Errorf("unable to updateUserCols() for user ID: %d: %v", userID, err)
}
}