MCPcopy Create free account
hub / github.com/bytebase/bytebase / GetEmailVerificationCode

Method GetEmailVerificationCode

backend/store/email_verification_code.go:70–98  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

68// GetEmailVerificationCode returns the verification code record for the given email and purpose,
69// or (nil, nil) if no row exists.
70func (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.
101func (s *Store) IncrementEmailVerificationCodeAttempts(ctx context.Context, email string, purpose storepb.EmailVerificationCodePurpose) error {

Callers 1

verifyEmailCodeMethod · 0.80

Calls 6

GetDBMethod · 0.95
QFunction · 0.92
SpaceMethod · 0.80
ToSQLMethod · 0.80
ScanMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected