2021-01-04 14:52:13 +01:00
|
|
|
package command
|
2020-12-11 15:49:19 +01:00
|
|
|
|
|
|
|
import (
|
2021-02-23 15:13:04 +01:00
|
|
|
"github.com/caos/zitadel/internal/domain"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
|
|
"github.com/caos/zitadel/internal/repository/policy"
|
2020-12-11 15:49:19 +01:00
|
|
|
)
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
type PasswordComplexityPolicyWriteModel struct {
|
2020-12-11 15:49:19 +01:00
|
|
|
eventstore.WriteModel
|
|
|
|
|
|
|
|
MinLength uint64
|
|
|
|
HasLowercase bool
|
2021-01-18 11:24:15 +01:00
|
|
|
HasUppercase bool
|
2020-12-11 15:49:19 +01:00
|
|
|
HasNumber bool
|
|
|
|
HasSymbol bool
|
2021-01-07 16:06:45 +01:00
|
|
|
State domain.PolicyState
|
2020-12-11 15:49:19 +01:00
|
|
|
}
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
func (wm *PasswordComplexityPolicyWriteModel) Reduce() error {
|
2020-12-11 15:49:19 +01:00
|
|
|
for _, event := range wm.Events {
|
|
|
|
switch e := event.(type) {
|
2021-01-04 14:52:13 +01:00
|
|
|
case *policy.PasswordComplexityPolicyAddedEvent:
|
2020-12-11 15:49:19 +01:00
|
|
|
wm.MinLength = e.MinLength
|
|
|
|
wm.HasLowercase = e.HasLowercase
|
2021-01-18 11:24:15 +01:00
|
|
|
wm.HasUppercase = e.HasUppercase
|
2020-12-11 15:49:19 +01:00
|
|
|
wm.HasNumber = e.HasNumber
|
|
|
|
wm.HasSymbol = e.HasSymbol
|
2021-01-07 16:06:45 +01:00
|
|
|
wm.State = domain.PolicyStateActive
|
2021-01-04 14:52:13 +01:00
|
|
|
case *policy.PasswordComplexityPolicyChangedEvent:
|
2021-01-06 11:12:56 +01:00
|
|
|
if e.MinLength != nil {
|
|
|
|
wm.MinLength = *e.MinLength
|
|
|
|
}
|
|
|
|
if e.HasLowercase != nil {
|
|
|
|
wm.HasLowercase = *e.HasLowercase
|
|
|
|
}
|
2021-01-18 11:24:15 +01:00
|
|
|
if e.HasUppercase != nil {
|
|
|
|
wm.HasUppercase = *e.HasUppercase
|
2021-01-06 11:12:56 +01:00
|
|
|
}
|
|
|
|
if e.HasNumber != nil {
|
|
|
|
wm.HasNumber = *e.HasNumber
|
|
|
|
}
|
|
|
|
if e.HasSymbol != nil {
|
|
|
|
wm.HasSymbol = *e.HasSymbol
|
|
|
|
}
|
2021-01-04 14:52:13 +01:00
|
|
|
case *policy.PasswordComplexityPolicyRemovedEvent:
|
2021-01-07 16:06:45 +01:00
|
|
|
wm.State = domain.PolicyStateRemoved
|
2020-12-11 15:49:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return wm.WriteModel.Reduce()
|
|
|
|
}
|