fixed verification code

This commit is contained in:
Stephan D
2026-02-09 16:40:52 +01:00
parent f8a3bef2e6
commit eda6b75f74
78 changed files with 1118 additions and 487 deletions

View File

@@ -12,12 +12,14 @@ import (
type AccountNotification struct {
messaging.Envelope
accountRef bson.ObjectID
accountRef bson.ObjectID
verificationToken string
}
func (acn *AccountNotification) Serialize() ([]byte, error) {
var msg gmessaging.AccountCreatedEvent
msg.AccountRef = acn.accountRef.Hex()
msg.VerificationToken = acn.verificationToken
data, err := proto.Marshal(&msg)
if err != nil {
return nil, err
@@ -29,9 +31,10 @@ func NewAccountNotification(action nm.NotificationAction) model.NotificationEven
return model.NewNotification(mservice.Accounts, action)
}
func NewAccountImp(sender string, accountRef bson.ObjectID, action nm.NotificationAction) messaging.Envelope {
func NewAccountImp(sender string, accountRef bson.ObjectID, action nm.NotificationAction, verificationToken string) messaging.Envelope {
return &AccountNotification{
Envelope: messaging.CreateEnvelope(sender, NewAccountNotification(action)),
accountRef: accountRef,
Envelope: messaging.CreateEnvelope(sender, NewAccountNotification(action)),
accountRef: accountRef,
verificationToken: verificationToken,
}
}

View File

@@ -34,12 +34,13 @@ func (acnp *AccoountNotificaionProcessor) Process(ctx context.Context, envelope
acnp.logger.Warn("Failed to restore object ID", zap.Error(err), zap.String("topic", acnp.event.ToString()), zap.String("account_ref", msg.AccountRef))
return err
}
verificationToken := msg.GetVerificationToken()
var account model.Account
if err := acnp.db.Get(ctx, accountRef, &account); err != nil {
acnp.logger.Warn("Failed to fetch account", zap.Error(err), zap.String("topic", acnp.event.ToString()), zap.String("account_ref", msg.AccountRef))
return err
}
return acnp.handler(ctx, &account)
return acnp.handler(ctx, &account, verificationToken)
}
func (acnp *AccoountNotificaionProcessor) GetSubject() model.NotificationEvent {

View File

@@ -1,8 +1,8 @@
package notifications
import (
messaging "github.com/tech/sendico/pkg/messaging/envelope"
gmessaging "github.com/tech/sendico/pkg/generated/gmessaging"
messaging "github.com/tech/sendico/pkg/messaging/envelope"
"github.com/tech/sendico/pkg/model"
nm "github.com/tech/sendico/pkg/model/notification"
"github.com/tech/sendico/pkg/mservice"
@@ -16,10 +16,10 @@ type NResultNotification struct {
func (nrn *NResultNotification) Serialize() ([]byte, error) {
msg := gmessaging.NotificationSentEvent{
UserID: nrn.result.UserID,
UserId: nrn.result.UserID,
Channel: nrn.result.Channel,
Locale: nrn.result.Locale,
TemplateID: nrn.result.TemplateID,
TemplateId: nrn.result.TemplateID,
Status: &gmessaging.OperationResult{
IsSuccessful: nrn.result.Result.IsSuccessful,
ErrorDescription: nrn.result.Result.Error,

View File

@@ -3,8 +3,8 @@ package notifications
import (
"context"
me "github.com/tech/sendico/pkg/messaging/envelope"
gmessaging "github.com/tech/sendico/pkg/generated/gmessaging"
me "github.com/tech/sendico/pkg/messaging/envelope"
nh "github.com/tech/sendico/pkg/messaging/notifications/notification/handler"
np "github.com/tech/sendico/pkg/messaging/notifications/processor"
"github.com/tech/sendico/pkg/mlogger"
@@ -27,10 +27,10 @@ func (nrp *NResultNotificaionProcessor) Process(ctx context.Context, envelope me
}
nresult := &model.NotificationResult{
AmpliEvent: model.AmpliEvent{
UserID: msg.UserID,
UserID: msg.UserId,
},
Channel: msg.Channel,
TemplateID: msg.TemplateID,
TemplateID: msg.TemplateId,
Locale: msg.Locale,
Result: model.OperationResult{
IsSuccessful: msg.Status.IsSuccessful,

View File

@@ -7,10 +7,10 @@ import (
"go.mongodb.org/mongo-driver/v2/bson"
)
func Account(sender string, accountRef bson.ObjectID, action nm.NotificationAction) messaging.Envelope {
return an.NewAccountImp(sender, accountRef, action)
func Account(sender string, accountRef bson.ObjectID, action nm.NotificationAction, verificationToken string) messaging.Envelope {
return an.NewAccountImp(sender, accountRef, action, verificationToken)
}
func AccountCreated(sender string, accountRef bson.ObjectID) messaging.Envelope {
return Account(sender, accountRef, nm.NACreated)
func AccountCreated(sender string, accountRef bson.ObjectID, verificationToken string) messaging.Envelope {
return Account(sender, accountRef, nm.NACreated, verificationToken)
}

View File

@@ -6,6 +6,6 @@ import (
"github.com/tech/sendico/pkg/model"
)
type AccountHandler = func(context.Context, *model.Account) error
type AccountHandler = func(context.Context, *model.Account, string) error
type PasswordResetHandler = func(context.Context, *model.Account, string) error