zitadel/internal/v2/repository/policy/password_lockout.go

121 lines
2.6 KiB
Go
Raw Normal View History

2020-11-06 17:25:07 +01:00
package policy
import (
"context"
"github.com/caos/zitadel/internal/eventstore/v2"
)
const (
2020-11-11 17:51:44 +01:00
PasswordLockoutPolicyAddedEventType = "policy.password.lockout.added"
PasswordLockoutPolicyChangedEventType = "policy.password.lockout.changed"
PasswordLockoutPolicyRemovedEventType = "policy.password.lockout.removed"
2020-11-06 17:25:07 +01:00
)
2020-11-11 17:51:44 +01:00
type PasswordLockoutPolicyAggregate struct {
2020-11-06 22:09:19 +01:00
eventstore.Aggregate
MaxAttempts int
ShowLockOutFailures bool
}
2020-11-11 17:51:44 +01:00
type PasswordLockoutPolicyReadModel struct {
eventstore.ReadModel
MaxAttempts int
ShowLockOutFailures bool
}
2020-11-06 17:25:07 +01:00
type PasswordLockoutPolicyAddedEvent struct {
eventstore.BaseEvent `json:"-"`
MaxAttempts int `json:"maxAttempts"`
ShowLockOutFailures bool `json:"showLockOutFailures"`
}
func (e *PasswordLockoutPolicyAddedEvent) CheckPrevious() bool {
return true
}
func (e *PasswordLockoutPolicyAddedEvent) Data() interface{} {
return e
}
func NewPasswordLockoutPolicyAddedEvent(
ctx context.Context,
maxAttempts int,
showLockOutFailures bool,
) *PasswordLockoutPolicyAddedEvent {
return &PasswordLockoutPolicyAddedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
2020-11-11 17:51:44 +01:00
PasswordLockoutPolicyAddedEventType,
2020-11-06 17:25:07 +01:00
),
MaxAttempts: maxAttempts,
ShowLockOutFailures: showLockOutFailures,
}
}
2020-11-06 22:09:19 +01:00
type PasswordLockoutPolicyChangedEvent struct {
eventstore.BaseEvent `json:"-"`
2020-11-11 17:51:44 +01:00
MaxAttempts int `json:"maxAttempts,omitempty"`
ShowLockOutFailures bool `json:"showLockOutFailures,omitempty"`
2020-11-06 22:09:19 +01:00
}
func (e *PasswordLockoutPolicyChangedEvent) CheckPrevious() bool {
return true
}
func (e *PasswordLockoutPolicyChangedEvent) Data() interface{} {
2020-11-11 17:51:44 +01:00
return e
2020-11-06 22:09:19 +01:00
}
func NewPasswordLockoutPolicyChangedEvent(
ctx context.Context,
current,
2020-11-11 17:51:44 +01:00
changed *PasswordLockoutPolicyAggregate,
2020-11-06 22:09:19 +01:00
) *PasswordLockoutPolicyChangedEvent {
2020-11-11 17:51:44 +01:00
e := &PasswordLockoutPolicyChangedEvent{
2020-11-06 22:09:19 +01:00
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
2020-11-11 17:51:44 +01:00
PasswordLockoutPolicyChangedEventType,
2020-11-06 22:09:19 +01:00
),
}
2020-11-11 17:51:44 +01:00
if current.MaxAttempts != changed.MaxAttempts {
e.MaxAttempts = changed.MaxAttempts
}
if current.ShowLockOutFailures != changed.ShowLockOutFailures {
e.ShowLockOutFailures = changed.ShowLockOutFailures
}
return e
2020-11-06 22:09:19 +01:00
}
type PasswordLockoutPolicyRemovedEvent struct {
eventstore.BaseEvent `json:"-"`
}
func (e *PasswordLockoutPolicyRemovedEvent) CheckPrevious() bool {
return true
}
func (e *PasswordLockoutPolicyRemovedEvent) Data() interface{} {
return nil
}
func NewPasswordLockoutPolicyRemovedEvent(
ctx context.Context,
) *PasswordLockoutPolicyRemovedEvent {
return &PasswordLockoutPolicyRemovedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
2020-11-11 17:51:44 +01:00
PasswordLockoutPolicyRemovedEventType,
2020-11-06 22:09:19 +01:00
),
}
}