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)
| 1067 | // inactivated email addresses. It returns ErrEmailNotExist when no qualified |
| 1068 | // email is not found. |
| 1069 | func (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. |