2021-01-04 13:52:13 +00:00
|
|
|
package query
|
2020-12-11 14:49:19 +00:00
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
import (
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
|
|
|
"github.com/caos/zitadel/internal/v2/repository/policy"
|
|
|
|
)
|
2020-12-11 14:49:19 +00:00
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type PasswordLockoutPolicyReadModel struct {
|
2020-12-11 14:49:19 +00:00
|
|
|
eventstore.ReadModel
|
|
|
|
|
|
|
|
MaxAttempts uint64
|
|
|
|
ShowLockOutFailures bool
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func (rm *PasswordLockoutPolicyReadModel) Reduce() error {
|
2020-12-11 14:49:19 +00:00
|
|
|
for _, event := range rm.Events {
|
|
|
|
switch e := event.(type) {
|
2021-01-04 13:52:13 +00:00
|
|
|
case *policy.PasswordLockoutPolicyAddedEvent:
|
2020-12-11 14:49:19 +00:00
|
|
|
rm.MaxAttempts = e.MaxAttempts
|
|
|
|
rm.ShowLockOutFailures = e.ShowLockOutFailures
|
2021-01-04 13:52:13 +00:00
|
|
|
case *policy.PasswordLockoutPolicyChangedEvent:
|
2020-12-11 14:49:19 +00:00
|
|
|
rm.MaxAttempts = e.MaxAttempts
|
|
|
|
rm.ShowLockOutFailures = e.ShowLockOutFailures
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rm.ReadModel.Reduce()
|
|
|
|
}
|