MCPcopy
hub / github.com/gogs/gogs / GetByEmail

Method GetByEmail

internal/database/users.go:693–728  ·  view source on GitHub ↗

GetByEmail returns the user (not organization) with given email. It ignores records with unverified emails and returns ErrUserNotExist when not found.

(ctx context.Context, email string)

Source from the content-addressed store, hash-verified

691// GetByEmail returns the user (not organization) with given email. It ignores
692// records with unverified emails and returns ErrUserNotExist when not found.
693func (s *UsersStore) GetByEmail(ctx context.Context, email string) (*User, error) {
694 if email == "" {
695 return nil, ErrUserNotExist{args: errutil.Args{"email": email}}
696 }
697 email = strings.ToLower(email)
698
699 /*
700 Equivalent SQL for PostgreSQL:
701
702 SELECT * FROM "user"
703 LEFT JOIN email_address ON email_address.uid = "user".id
704 WHERE
705 "user".type = @userType
706 AND (
707 "user".email = @email AND "user".is_active = TRUE
708 OR email_address.email = @email AND email_address.is_activated = TRUE
709 )
710 */
711 user := new(User)
712 err := s.db.WithContext(ctx).
713 Joins(dbutil.Quote("LEFT JOIN email_address ON email_address.uid = %s.id", "user"), true).
714 Where(dbutil.Quote("%s.type = ?", "user"), UserTypeIndividual).
715 Where(s.db.
716 Where(dbutil.Quote("%[1]s.email = ? AND %[1]s.is_active = ?", "user"), email, true).
717 Or("email_address.email = ? AND email_address.is_activated = ?", email, true),
718 ).
719 First(&user).
720 Error
721 if err != nil {
722 if errors.Is(err, gorm.ErrRecordNotFound) {
723 return nil, ErrUserNotExist{args: errutil.Args{"email": email}}
724 }
725 return nil, err
726 }
727 return user, nil
728}
729
730// GetByID returns the user with given ID. It returns ErrUserNotExist when not
731// found.

Callers 13

CreateMethod · 0.95
UpdateMethod · 0.95
AddEmailMethod · 0.95
APIFormatMethod · 0.80
AvatarLinkMethod · 0.80
usersGetByEmailFunction · 0.80
ForgotPasswdPostFunction · 0.80
Email2UserFunction · 0.80
TestWebhookFunction · 0.80
tryGetUserByEmailFunction · 0.80
ToCommitFunction · 0.80

Calls 2

QuoteFunction · 0.92
WhereMethod · 0.80

Tested by 2

usersGetByEmailFunction · 0.64
TestWebhookFunction · 0.64