feat(identity): confirm the email address with a six-digit code from the message
This commit is contained in:
1 parent
c94434cd09
commit
d365a05c96
87 files changed
+4764
-224
No files matched your search
@@ -365,7 +365,9 @@ func (registration *Registration) reRegister(
|
||||
}
|
||||
|
||||
// issueVerification stores a new token bound to the current registration
|
||||
// version and queues its message, in the caller's transaction.
|
||||
// version and queues its message, in the caller's transaction. The message
|
||||
// carries a six-digit code next to the link; storage keeps only the keyed digest
|
||||
// of the code, which ends with the token or after the code lifetime.
|
||||
func (registration *Registration) issueVerification(
|
||||
ctx context.Context,
|
||||
unit outbound.UnitOfWork,
|
||||
@@ -383,6 +385,10 @@ func (registration *Registration) issueVerification(
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s - generate token: %w", location, err)
|
||||
}
|
||||
code, err := domain.NewVerificationCode()
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s - generate code: %w", location, err)
|
||||
}
|
||||
token, err := domain.NewEmailToken(domain.NewEmailTokenInput{
|
||||
UserID: user.ID,
|
||||
Purpose: domain.EmailTokenPurposeEmailVerification,
|
||||
@@ -390,6 +396,8 @@ func (registration *Registration) issueVerification(
|
||||
RegistrationVersion: user.RegistrationVersion,
|
||||
IssuedAt: now,
|
||||
Lifetime: lifetime.Duration(),
|
||||
CodeHash: registration.deps.Keyring.VerificationCodeDigest(code),
|
||||
CodeLifetime: domain.VerificationCodeLifetime,
|
||||
Pending: pending,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -399,10 +407,12 @@ func (registration *Registration) issueVerification(
|
||||
return fmt.Errorf("%s - store token: %w", location, err)
|
||||
}
|
||||
_, err = registration.deps.Mailer.EnqueueVerification(ctx, unit, notification.TokenMailRequest{
|
||||
Recipient: user.Email,
|
||||
Token: token,
|
||||
RawToken: raw,
|
||||
Lifetime: lifetime,
|
||||
Recipient: user.Email,
|
||||
Token: token,
|
||||
RawToken: raw,
|
||||
Lifetime: lifetime,
|
||||
Code: code,
|
||||
CodeLifetime: domain.VerificationCodeLifetime,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s - queue message: %w", location, err)
|
||||
|
||||
Reference in new issue
Block a user