2021-01-04 13:52:13 +00:00
|
|
|
package command
|
2020-12-11 14:49:19 +00:00
|
|
|
|
|
|
|
import (
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/policy"
|
2020-12-11 14:49:19 +00:00
|
|
|
)
|
|
|
|
|
2021-08-11 06:36:32 +00:00
|
|
|
type LockoutPolicyWriteModel struct {
|
2020-12-11 14:49:19 +00:00
|
|
|
eventstore.WriteModel
|
|
|
|
|
2021-08-11 06:36:32 +00:00
|
|
|
MaxPasswordAttempts uint64
|
2020-12-11 14:49:19 +00:00
|
|
|
ShowLockOutFailures bool
|
2021-01-07 15:06:45 +00:00
|
|
|
State domain.PolicyState
|
2020-12-11 14:49:19 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 06:36:32 +00:00
|
|
|
func (wm *LockoutPolicyWriteModel) Reduce() error {
|
2020-12-11 14:49:19 +00:00
|
|
|
for _, event := range wm.Events {
|
|
|
|
switch e := event.(type) {
|
2021-08-11 06:36:32 +00:00
|
|
|
case *policy.LockoutPolicyAddedEvent:
|
|
|
|
wm.MaxPasswordAttempts = e.MaxPasswordAttempts
|
2020-12-11 14:49:19 +00:00
|
|
|
wm.ShowLockOutFailures = e.ShowLockOutFailures
|
2021-01-07 15:06:45 +00:00
|
|
|
wm.State = domain.PolicyStateActive
|
2021-08-11 06:36:32 +00:00
|
|
|
case *policy.LockoutPolicyChangedEvent:
|
|
|
|
if e.MaxPasswordAttempts != nil {
|
|
|
|
wm.MaxPasswordAttempts = *e.MaxPasswordAttempts
|
2021-01-06 10:12:56 +00:00
|
|
|
}
|
|
|
|
if e.ShowLockOutFailures != nil {
|
|
|
|
wm.ShowLockOutFailures = *e.ShowLockOutFailures
|
|
|
|
}
|
2021-08-11 06:36:32 +00:00
|
|
|
case *policy.LockoutPolicyRemovedEvent:
|
2021-01-07 15:06:45 +00:00
|
|
|
wm.State = domain.PolicyStateRemoved
|
2020-12-11 14:49:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return wm.WriteModel.Reduce()
|
|
|
|
}
|