@@ -74,14 +74,15 @@ func GetEmailAddressByID(uid, id int64) (*EmailAddress, error) {
74
74
return email , nil
75
75
}
76
76
77
- func isEmailActive (e Engine , email string , userID , emailID int64 ) (bool , error ) {
77
+ // isEmailActive check if email is activated with a different emailID
78
+ func isEmailActive (e Engine , email string , excludeEmailID int64 ) (bool , error ) {
78
79
if len (email ) == 0 {
79
80
return true , nil
80
81
}
81
82
82
83
// Can't filter by boolean field unless it's explicit
83
84
cond := builder .NewCond ()
84
- cond = cond .And (builder.Eq {"lower_email" : strings .ToLower (email )}, builder.Neq {"id" : emailID })
85
+ cond = cond .And (builder.Eq {"lower_email" : strings .ToLower (email )}, builder.Neq {"id" : excludeEmailID })
85
86
if setting .Service .RegisterEmailConfirm {
86
87
// Inactive (unvalidated) addresses don't count as active if email validation is required
87
88
cond = cond .And (builder.Eq {"is_activated" : true })
@@ -90,7 +91,7 @@ func isEmailActive(e Engine, email string, userID, emailID int64) (bool, error)
90
91
var em EmailAddress
91
92
if has , err := e .Where (cond ).Get (& em ); has || err != nil {
92
93
if has {
93
- log .Info ("isEmailActive('%s',%d,%d ) found duplicate in email ID %d" , email , userID , emailID , em .ID )
94
+ log .Info ("isEmailActive(%q, %d ) found duplicate in email ID %d" , email , excludeEmailID , em .ID )
94
95
}
95
96
return has , err
96
97
}
@@ -387,14 +388,14 @@ func ActivateUserEmail(userID int64, email string, activate bool) (err error) {
387
388
return nil
388
389
}
389
390
if activate {
390
- if used , err := isEmailActive (sess , email , 0 , addr .ID ); err != nil {
391
- return fmt .Errorf ("isEmailActive(): %v" , err )
391
+ if used , err := isEmailActive (sess , email , addr .ID ); err != nil {
392
+ return fmt .Errorf ("unable to check isEmailActive() for %s : %v" , email , err )
392
393
} else if used {
393
394
return ErrEmailAlreadyUsed {Email : email }
394
395
}
395
396
}
396
397
if err = addr .updateActivation (sess , activate ); err != nil {
397
- return fmt .Errorf ("updateActivation(): %v" , err )
398
+ return fmt .Errorf ("unable to updateActivation() for %d:%s: %w" , addr . ID , addr . Email , err )
398
399
}
399
400
400
401
// Activate/deactivate a user's primary email address and account
@@ -403,16 +404,16 @@ func ActivateUserEmail(userID int64, email string, activate bool) (err error) {
403
404
if has , err := sess .Get (& user ); err != nil {
404
405
return err
405
406
} else if ! has {
406
- return fmt .Errorf ("no such user: %d (%s) " , userID , email )
407
+ return fmt .Errorf ("no user with ID : %d and Email: %s " , userID , email )
407
408
}
408
- // The user's activation state should synchronized with the primary email
409
+ // The user's activation state should be synchronized with the primary email
409
410
if user .IsActive != activate {
410
411
user .IsActive = activate
411
412
if user .Rands , err = GetUserSalt (); err != nil {
412
- return fmt .Errorf ("generate salt: %v" , err )
413
+ return fmt .Errorf ("unable to generate salt: %v" , err )
413
414
}
414
415
if err = updateUserCols (sess , & user , "is_active" , "rands" ); err != nil {
415
- return fmt .Errorf ("updateUserCols(): %v" , err )
416
+ return fmt .Errorf ("unable to updateUserCols() for user ID : %d: %v" , userID , err )
416
417
}
417
418
}
418
419
}
0 commit comments