mirror of
https://github.com/zitadel/zitadel.git
synced 2025-01-11 07:03:40 +00:00
145 lines
3.5 KiB
Go
145 lines
3.5 KiB
Go
package authenticator
|
|
|
|
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"
|
|
)
|
|
|
|
const (
|
|
passwordPrefix = eventPrefix + "password."
|
|
PasswordCreatedType = passwordPrefix + "created"
|
|
PasswordDeletedType = passwordPrefix + "deleted"
|
|
PasswordCodeAddedType = passwordPrefix + "code.added"
|
|
)
|
|
|
|
type PasswordCreatedEvent struct {
|
|
*eventstore.BaseEvent `json:"-"`
|
|
|
|
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
|
|
}
|
|
|
|
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,
|
|
),
|
|
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,
|
|
),
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|