2021-01-04 13:52:13 +00:00
|
|
|
package command
|
2020-12-11 14:49:19 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
2021-01-04 13:52:13 +00:00
|
|
|
"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 PasswordComplexityPolicyWriteModel struct {
|
2020-12-11 14:49:19 +00:00
|
|
|
eventstore.WriteModel
|
|
|
|
|
|
|
|
MinLength uint64
|
|
|
|
HasLowercase bool
|
|
|
|
HasUpperCase bool
|
|
|
|
HasNumber bool
|
|
|
|
HasSymbol bool
|
2021-01-04 13:52:13 +00:00
|
|
|
IsActive bool
|
2020-12-11 14:49:19 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func (wm *PasswordComplexityPolicyWriteModel) Reduce() error {
|
2020-12-11 14:49:19 +00:00
|
|
|
for _, event := range wm.Events {
|
|
|
|
switch e := event.(type) {
|
2021-01-04 13:52:13 +00:00
|
|
|
case *policy.PasswordComplexityPolicyAddedEvent:
|
2020-12-11 14:49:19 +00:00
|
|
|
wm.MinLength = e.MinLength
|
|
|
|
wm.HasLowercase = e.HasLowercase
|
|
|
|
wm.HasUpperCase = e.HasUpperCase
|
|
|
|
wm.HasNumber = e.HasNumber
|
|
|
|
wm.HasSymbol = e.HasSymbol
|
2021-01-04 13:52:13 +00:00
|
|
|
wm.IsActive = true
|
|
|
|
case *policy.PasswordComplexityPolicyChangedEvent:
|
2020-12-11 14:49:19 +00:00
|
|
|
wm.MinLength = e.MinLength
|
|
|
|
wm.HasLowercase = e.HasLowercase
|
|
|
|
wm.HasUpperCase = e.HasUpperCase
|
|
|
|
wm.HasNumber = e.HasNumber
|
|
|
|
wm.HasSymbol = e.HasSymbol
|
2021-01-04 13:52:13 +00:00
|
|
|
case *policy.PasswordComplexityPolicyRemovedEvent:
|
|
|
|
wm.IsActive = false
|
2020-12-11 14:49:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return wm.WriteModel.Reduce()
|
|
|
|
}
|