GetEmailVerificationCode returns the verification code record for the given email and purpose, or (nil, nil) if no row exists.
(ctx context.Context, email string, purpose storepb.EmailVerificationCodePurpose)
| 68 | // GetEmailVerificationCode returns the verification code record for the given email and purpose, |
| 69 | // or (nil, nil) if no row exists. |
| 70 | func (s *Store) GetEmailVerificationCode(ctx context.Context, email string, purpose storepb.EmailVerificationCodePurpose) (*EmailVerificationCodeMessage, error) { |
| 71 | q := qb.Q().Space(` |
| 72 | SELECT email, purpose, code_hash, attempts, expires_at, last_sent_at, workspace |
| 73 | FROM email_verification_code |
| 74 | WHERE email = ? AND purpose = ? |
| 75 | `, email, purpose.String()) |
| 76 | |
| 77 | query, args, err := q.ToSQL() |
| 78 | if err != nil { |
| 79 | return nil, err |
| 80 | } |
| 81 | |
| 82 | msg := &EmailVerificationCodeMessage{} |
| 83 | var purposeStr string |
| 84 | var workspace sql.NullString |
| 85 | if err := s.GetDB().QueryRowContext(ctx, query, args...).Scan( |
| 86 | &msg.Email, &purposeStr, &msg.CodeHash, &msg.Attempts, &msg.ExpiresAt, &msg.LastSentAt, &workspace, |
| 87 | ); err != nil { |
| 88 | if errors.Is(err, sql.ErrNoRows) { |
| 89 | return nil, nil |
| 90 | } |
| 91 | return nil, errors.Wrap(err, "failed to get email verification code") |
| 92 | } |
| 93 | msg.Purpose = storepb.EmailVerificationCodePurpose(storepb.EmailVerificationCodePurpose_value[purposeStr]) |
| 94 | if workspace.Valid { |
| 95 | msg.Workspace = workspace.String |
| 96 | } |
| 97 | return msg, nil |
| 98 | } |
| 99 | |
| 100 | // IncrementEmailVerificationCodeAttempts increments the attempt counter for the given email and purpose. |
| 101 | func (s *Store) IncrementEmailVerificationCodeAttempts(ctx context.Context, email string, purpose storepb.EmailVerificationCodePurpose) error { |