145 lines
3.5 KiB
Go
Raw Normal View History

package authenticator
import (
"context"
2024-09-24 14:26:48 +02:00
"time"
"github.com/zitadel/zitadel/internal/api/http"
2024-09-24 14:26:48 +02:00
"github.com/zitadel/zitadel/internal/crypto"
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/eventstore"
)
const (
2024-09-24 14:26:48 +02:00
passwordPrefix = eventPrefix + "password."
PasswordCreatedType = passwordPrefix + "created"
PasswordDeletedType = passwordPrefix + "deleted"
PasswordCodeAddedType = passwordPrefix + "code.added"
)
type PasswordCreatedEvent struct {
*eventstore.BaseEvent `json:"-"`
2024-09-24 14:26:48 +02:00
UserID string `json:"userID"`
EncodedHash string `json:"encodedHash,omitempty"`
ChangeRequired bool `json:"changeRequired,omitempty"`
TriggeredAtOrigin string `json:"triggerOrigin,omitempty"`
}
func (e *PasswordCreatedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
e.BaseEvent = event
}
func (e *PasswordCreatedEvent) Payload() interface{} {
return e
}
func (e *PasswordCreatedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return nil
}
2024-09-24 14:26:48 +02:00
func (e *PasswordCreatedEvent) TriggerOrigin() string {
return e.TriggeredAtOrigin
}
func NewPasswordCreatedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
userID string,
encodeHash string,
changeRequired bool,
) *PasswordCreatedEvent {
return &PasswordCreatedEvent{
BaseEvent: eventstore.NewBaseEventForPush(
ctx,
aggregate,
PasswordCreatedType,
),
2024-09-24 14:26:48 +02:00
UserID: userID,
EncodedHash: encodeHash,
ChangeRequired: changeRequired,
TriggeredAtOrigin: http.DomainContext(ctx).Origin(),
}
}
type PasswordDeletedEvent struct {
*eventstore.BaseEvent `json:"-"`
}
func (e *PasswordDeletedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
e.BaseEvent = event
}
func (e *PasswordDeletedEvent) Payload() interface{} {
return e
}
func (e *PasswordDeletedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return nil
}
func NewPasswordDeletedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
) *PasswordDeletedEvent {
return &PasswordDeletedEvent{
BaseEvent: eventstore.NewBaseEventForPush(
ctx,
aggregate,
PasswordDeletedType,
),
}
}
2024-09-24 14:26:48 +02:00
type PasswordCodeAddedEvent struct {
*eventstore.BaseEvent `json:"-"`
Code *crypto.CryptoValue `json:"code,omitempty"`
Expiry time.Duration `json:"expiry,omitempty"`
NotificationType domain.NotificationType `json:"notificationType,omitempty"`
URLTemplate string `json:"url_template,omitempty"`
CodeReturned bool `json:"code_returned,omitempty"`
TriggeredAtOrigin string `json:"triggerOrigin,omitempty"`
}
func (e *PasswordCodeAddedEvent) Payload() interface{} {
return e
}
func (e *PasswordCodeAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return nil
}
func (e *PasswordCodeAddedEvent) TriggerOrigin() string {
return e.TriggeredAtOrigin
}
func NewPasswordCodeAddedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
code *crypto.CryptoValue,
expiry time.Duration,
notificationType domain.NotificationType,
urlTemplate string,
codeReturned bool,
) *PasswordCodeAddedEvent {
return &PasswordCodeAddedEvent{
BaseEvent: eventstore.NewBaseEventForPush(
ctx,
aggregate,
PasswordCodeAddedType,
),
Code: code,
Expiry: expiry,
NotificationType: notificationType,
URLTemplate: urlTemplate,
CodeReturned: codeReturned,
TriggeredAtOrigin: http.DomainContext(ctx).Origin(),
}
}
func (e *PasswordCodeAddedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
e.BaseEvent = event
}