2024-08-28 19:46:45 +00:00
|
|
|
package schemauser
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/api/http"
|
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2024-09-26 07:14:33 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/notification/senders"
|
2024-08-28 19:46:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
phoneEventPrefix = eventPrefix + "phone."
|
|
|
|
PhoneUpdatedType = phoneEventPrefix + "updated"
|
|
|
|
PhoneVerifiedType = phoneEventPrefix + "verified"
|
|
|
|
PhoneVerificationFailedType = phoneEventPrefix + "verification.failed"
|
|
|
|
PhoneCodeAddedType = phoneEventPrefix + "code.added"
|
|
|
|
PhoneCodeSentType = phoneEventPrefix + "code.sent"
|
|
|
|
)
|
|
|
|
|
2024-09-17 08:27:48 +00:00
|
|
|
type PhoneUpdatedEvent struct {
|
|
|
|
*eventstore.BaseEvent `json:"-"`
|
2024-08-28 19:46:45 +00:00
|
|
|
|
|
|
|
PhoneNumber domain.PhoneNumber `json:"phone,omitempty"`
|
|
|
|
}
|
|
|
|
|
2024-09-17 08:27:48 +00:00
|
|
|
func (e *PhoneUpdatedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = event
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *PhoneUpdatedEvent) Payload() interface{} {
|
2024-08-28 19:46:45 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2024-09-17 08:27:48 +00:00
|
|
|
func (e *PhoneUpdatedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2024-08-28 19:46:45 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-09-17 08:27:48 +00:00
|
|
|
func NewPhoneUpdatedEvent(ctx context.Context, aggregate *eventstore.Aggregate, phone domain.PhoneNumber) *PhoneUpdatedEvent {
|
|
|
|
return &PhoneUpdatedEvent{
|
|
|
|
BaseEvent: eventstore.NewBaseEventForPush(
|
2024-08-28 19:46:45 +00:00
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
PhoneUpdatedType,
|
|
|
|
),
|
|
|
|
PhoneNumber: phone,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type PhoneVerifiedEvent struct {
|
2024-09-17 08:27:48 +00:00
|
|
|
*eventstore.BaseEvent `json:"-"`
|
2024-08-28 19:46:45 +00:00
|
|
|
|
|
|
|
IsPhoneVerified bool `json:"-"`
|
|
|
|
}
|
|
|
|
|
2024-09-17 08:27:48 +00:00
|
|
|
func (e *PhoneVerifiedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = event
|
|
|
|
}
|
2024-08-28 19:46:45 +00:00
|
|
|
func (e *PhoneVerifiedEvent) Payload() interface{} {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *PhoneVerifiedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPhoneVerifiedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *PhoneVerifiedEvent {
|
|
|
|
return &PhoneVerifiedEvent{
|
2024-09-17 08:27:48 +00:00
|
|
|
BaseEvent: eventstore.NewBaseEventForPush(
|
2024-08-28 19:46:45 +00:00
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
PhoneVerifiedType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-17 08:27:48 +00:00
|
|
|
type PhoneVerificationFailedEvent struct {
|
|
|
|
*eventstore.BaseEvent `json:"-"`
|
2024-08-28 19:46:45 +00:00
|
|
|
}
|
|
|
|
|
2024-09-17 08:27:48 +00:00
|
|
|
func (e *PhoneVerificationFailedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = event
|
2024-08-28 19:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *PhoneVerificationFailedEvent) Payload() interface{} {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *PhoneVerificationFailedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPhoneVerificationFailedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *PhoneVerificationFailedEvent {
|
|
|
|
return &PhoneVerificationFailedEvent{
|
2024-09-17 08:27:48 +00:00
|
|
|
BaseEvent: eventstore.NewBaseEventForPush(
|
2024-08-28 19:46:45 +00:00
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
PhoneVerificationFailedType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type PhoneCodeAddedEvent struct {
|
2024-09-17 08:27:48 +00:00
|
|
|
*eventstore.BaseEvent `json:"-"`
|
2024-08-28 19:46:45 +00:00
|
|
|
|
|
|
|
Code *crypto.CryptoValue `json:"code,omitempty"`
|
|
|
|
Expiry time.Duration `json:"expiry,omitempty"`
|
|
|
|
CodeReturned bool `json:"code_returned,omitempty"`
|
2024-09-26 07:14:33 +00:00
|
|
|
GeneratorID string `json:"generatorId,omitempty"`
|
2024-08-28 19:46:45 +00:00
|
|
|
TriggeredAtOrigin string `json:"triggerOrigin,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *PhoneCodeAddedEvent) Payload() interface{} {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *PhoneCodeAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *PhoneCodeAddedEvent) TriggerOrigin() string {
|
|
|
|
return e.TriggeredAtOrigin
|
|
|
|
}
|
|
|
|
|
2024-09-17 08:27:48 +00:00
|
|
|
func (e *PhoneCodeAddedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = event
|
|
|
|
}
|
|
|
|
|
2024-08-28 19:46:45 +00:00
|
|
|
func NewPhoneCodeAddedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
code *crypto.CryptoValue,
|
|
|
|
expiry time.Duration,
|
|
|
|
codeReturned bool,
|
2024-09-26 07:14:33 +00:00
|
|
|
generatorID string,
|
2024-08-28 19:46:45 +00:00
|
|
|
) *PhoneCodeAddedEvent {
|
|
|
|
return &PhoneCodeAddedEvent{
|
2024-09-17 08:27:48 +00:00
|
|
|
BaseEvent: eventstore.NewBaseEventForPush(
|
2024-08-28 19:46:45 +00:00
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
PhoneCodeAddedType,
|
|
|
|
),
|
|
|
|
Code: code,
|
|
|
|
Expiry: expiry,
|
|
|
|
CodeReturned: codeReturned,
|
2024-09-26 07:14:33 +00:00
|
|
|
GeneratorID: generatorID,
|
2024-08-28 19:46:45 +00:00
|
|
|
TriggeredAtOrigin: http.DomainContext(ctx).Origin(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type PhoneCodeSentEvent struct {
|
2024-09-17 08:27:48 +00:00
|
|
|
*eventstore.BaseEvent `json:"-"`
|
2024-09-26 07:14:33 +00:00
|
|
|
|
|
|
|
GeneratorInfo *senders.CodeGeneratorInfo `json:"generatorInfo,omitempty"`
|
2024-08-28 19:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *PhoneCodeSentEvent) Payload() interface{} {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *PhoneCodeSentEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-09-17 08:27:48 +00:00
|
|
|
func (e *PhoneCodeSentEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = event
|
|
|
|
}
|
|
|
|
|
2024-09-26 07:14:33 +00:00
|
|
|
func NewPhoneCodeSentEvent(ctx context.Context, aggregate *eventstore.Aggregate, generatorInfo *senders.CodeGeneratorInfo) *PhoneCodeSentEvent {
|
2024-08-28 19:46:45 +00:00
|
|
|
return &PhoneCodeSentEvent{
|
2024-09-17 08:27:48 +00:00
|
|
|
BaseEvent: eventstore.NewBaseEventForPush(
|
2024-08-28 19:46:45 +00:00
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
PhoneCodeSentType,
|
|
|
|
),
|
2024-09-26 07:14:33 +00:00
|
|
|
GeneratorInfo: generatorInfo,
|
2024-08-28 19:46:45 +00:00
|
|
|
}
|
|
|
|
}
|