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 (
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
|
|
"github.com/caos/zitadel/internal/repository/policy"
|
2021-01-04 13:52:13 +00:00
|
|
|
)
|
2020-12-11 14:49:19 +00:00
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type PasswordComplexityPolicyReadModel struct {
|
2020-12-11 14:49:19 +00:00
|
|
|
eventstore.ReadModel
|
|
|
|
|
|
|
|
MinLength uint64
|
|
|
|
HasLowercase bool
|
|
|
|
HasUpperCase bool
|
|
|
|
HasNumber bool
|
|
|
|
HasSymbol bool
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func (rm *PasswordComplexityPolicyReadModel) 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.PasswordComplexityPolicyAddedEvent:
|
2020-12-11 14:49:19 +00:00
|
|
|
rm.MinLength = e.MinLength
|
|
|
|
rm.HasLowercase = e.HasLowercase
|
2021-01-18 10:24:15 +00:00
|
|
|
rm.HasUpperCase = e.HasUppercase
|
2020-12-11 14:49:19 +00:00
|
|
|
rm.HasNumber = e.HasNumber
|
|
|
|
rm.HasSymbol = e.HasSymbol
|
2021-01-04 13:52:13 +00:00
|
|
|
case *policy.PasswordComplexityPolicyChangedEvent:
|
2021-01-06 10:12:56 +00:00
|
|
|
if e.MinLength != nil {
|
|
|
|
rm.MinLength = *e.MinLength
|
|
|
|
}
|
|
|
|
if e.HasLowercase != nil {
|
|
|
|
rm.HasLowercase = *e.HasLowercase
|
|
|
|
}
|
2021-01-18 10:24:15 +00:00
|
|
|
if e.HasUppercase != nil {
|
|
|
|
rm.HasUpperCase = *e.HasUppercase
|
2021-01-06 10:12:56 +00:00
|
|
|
}
|
|
|
|
if e.HasNumber != nil {
|
|
|
|
rm.HasNumber = *e.HasNumber
|
|
|
|
}
|
|
|
|
if e.HasSymbol != nil {
|
|
|
|
rm.HasSymbol = *e.HasSymbol
|
|
|
|
}
|
2020-12-11 14:49:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rm.ReadModel.Reduce()
|
|
|
|
}
|