MCPcopy Index your code
hub / github.com/gogs/gogs / GetEmail

Method GetEmail

internal/database/users.go:1069–1088  ·  view source on GitHub ↗

GetEmail returns the email address of the given user. If `needsActivated` is true, only activated email will be returned, otherwise, it may return inactivated email addresses. It returns ErrEmailNotExist when no qualified email is not found.

(ctx context.Context, userID int64, email string, needsActivated bool)

Source from the content-addressed store, hash-verified

1067// inactivated email addresses. It returns ErrEmailNotExist when no qualified
1068// email is not found.
1069func (s *UsersStore) GetEmail(ctx context.Context, userID int64, email string, needsActivated bool) (*EmailAddress, error) {
1070 tx := s.db.WithContext(ctx).Where("uid = ? AND email = ?", userID, email)
1071 if needsActivated {
1072 tx = tx.Where("is_activated = ?", true)
1073 }
1074
1075 emailAddress := new(EmailAddress)
1076 err := tx.First(emailAddress).Error
1077 if err != nil {
1078 if errors.Is(err, gorm.ErrRecordNotFound) {
1079 return nil, ErrEmailNotExist{
1080 args: errutil.Args{
1081 "email": email,
1082 },
1083 }
1084 }
1085 return nil, err
1086 }
1087 return emailAddress, nil
1088}
1089
1090// ListEmails returns all email addresses of the given user. It always includes
1091// a primary email address.

Callers 5

usersGetEmailFunction · 0.80
usersMarkEmailActivatedFunction · 0.80
usersMarkEmailPrimaryFunction · 0.80
usersDeleteEmailFunction · 0.80
verifyActiveEmailCodeFunction · 0.80

Calls 1

WhereMethod · 0.80

Tested by 4

usersGetEmailFunction · 0.64
usersMarkEmailActivatedFunction · 0.64
usersMarkEmailPrimaryFunction · 0.64
usersDeleteEmailFunction · 0.64