summaryrefslogtreecommitdiffstats
path: root/models/user_mail.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-06-18 01:50:11 +0800
committerGitHub <noreply@github.com>2020-06-17 20:50:11 +0300
commit1645d4a5d8def3cc5451e068aa0a321e028a889b (patch)
tree99e1f29ec2dbb568cfee090ea4a2e49dfca02280 /models/user_mail.go
parent61cd0ce86601a0bffb625ae27a7b76ee8a15cb36 (diff)
downloadgitea-1645d4a5d8def3cc5451e068aa0a321e028a889b.tar.gz
gitea-1645d4a5d8def3cc5451e068aa0a321e028a889b.zip
Use ID or Where to instead directly use Get when load object from database (#11925)
* Use ID or Where to instead directly use Get when load object from database * Apply suggestions from code review Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'models/user_mail.go')
-rw-r--r--models/user_mail.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/models/user_mail.go b/models/user_mail.go
index af9602e714..60354e23ff 100644
--- a/models/user_mail.go
+++ b/models/user_mail.go
@@ -71,8 +71,8 @@ func GetEmailAddresses(uid int64) ([]*EmailAddress, error) {
// GetEmailAddressByID gets a user's email address by ID
func GetEmailAddressByID(uid, id int64) (*EmailAddress, error) {
// User ID is required for security reasons
- email := &EmailAddress{ID: id, UID: uid}
- if has, err := x.Get(email); err != nil {
+ email := &EmailAddress{UID: uid}
+ if has, err := x.ID(id).Get(email); err != nil {
return nil, err
} else if !has {
return nil, nil
@@ -126,7 +126,7 @@ func isEmailUsed(e Engine, email string) (bool, error) {
return true, nil
}
- return e.Get(&EmailAddress{Email: email})
+ return e.Where("email=?", email).Get(&EmailAddress{})
}
// IsEmailUsed returns true if the email has been used.
@@ -251,8 +251,8 @@ func MakeEmailPrimary(email *EmailAddress) error {
return ErrEmailNotActivated
}
- user := &User{ID: email.UID}
- has, err = x.Get(user)
+ user := &User{}
+ has, err = x.ID(email.UID).Get(user)
if err != nil {
return err
} else if !has {