mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-13 09:25:12 +00:00
* fix: split command query side * fix: split command query side * fix: members in correct pkg structure * fix: label policy in correct pkg structure * fix: structure * fix: structure of login policy * fix: identityprovider structure * fix: org iam policy structure * fix: password age policy structure * fix: password complexity policy structure * fix: password lockout policy structure * fix: idp structure * fix: user events structure * fix: user write model * fix: profile email changed command * fix: address changed command * fix: user states * fix: user * fix: org structure and add human * begin iam setup command side * setup * step2 * step2 * fix: add user * step2 * isvalid * fix: folder structure v2 business Co-authored-by: Fabiennne <[email protected]>
170 lines
4.6 KiB
Go
170 lines
4.6 KiB
Go
package user
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"github.com/caos/zitadel/internal/crypto"
|
|
"github.com/caos/zitadel/internal/errors"
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
|
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
|
"github.com/caos/zitadel/internal/v2/domain"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
passwordEventPrefix = humanEventPrefix + "password."
|
|
HumanPasswordChangedType = passwordEventPrefix + "changed"
|
|
HumanPasswordCodeAddedType = passwordEventPrefix + "code.added"
|
|
HumanPasswordCodeSentType = passwordEventPrefix + "code.sent"
|
|
HumanPasswordCheckSucceededType = passwordEventPrefix + "check.succeeded"
|
|
HumanPasswordCheckFailedType = passwordEventPrefix + "check.failed"
|
|
)
|
|
|
|
type HumanPasswordChangedChangedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
Secret *crypto.CryptoValue `json:"secret,omitempty"`
|
|
ChangeRequired bool `json:"changeRequired,omitempty"`
|
|
}
|
|
|
|
func (e *HumanPasswordChangedChangedEvent) Data() interface{} {
|
|
return e
|
|
}
|
|
|
|
func NewHumanPasswordChangedEvent(
|
|
ctx context.Context,
|
|
secret *crypto.CryptoValue,
|
|
changeRequired bool,
|
|
) *HumanPasswordChangedChangedEvent {
|
|
return &HumanPasswordChangedChangedEvent{
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
ctx,
|
|
HumanPasswordChangedType,
|
|
),
|
|
Secret: secret,
|
|
ChangeRequired: changeRequired,
|
|
}
|
|
}
|
|
|
|
func HumanPasswordChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
humanAdded := &HumanPasswordChangedChangedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}
|
|
err := json.Unmarshal(event.Data, humanAdded)
|
|
if err != nil {
|
|
return nil, errors.ThrowInternal(err, "USER-4M0sd", "unable to unmarshal human password changed")
|
|
}
|
|
|
|
return humanAdded, nil
|
|
}
|
|
|
|
type HumanPasswordCodeAddedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
Code *crypto.CryptoValue `json:"code,omitempty"`
|
|
Expiry time.Duration `json:"expiry,omitempty"`
|
|
NotificationType domain.NotificationType `json:"notificationType,omitempty"`
|
|
}
|
|
|
|
func (e *HumanPasswordCodeAddedEvent) Data() interface{} {
|
|
return e
|
|
}
|
|
|
|
func NewHumanPasswordCodeAddedEvent(
|
|
ctx context.Context,
|
|
code *crypto.CryptoValue,
|
|
expiry time.Duration,
|
|
notificationType domain.NotificationType,
|
|
) *HumanPasswordCodeAddedEvent {
|
|
return &HumanPasswordCodeAddedEvent{
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
ctx,
|
|
HumanPasswordCodeAddedType,
|
|
),
|
|
Code: code,
|
|
Expiry: expiry,
|
|
NotificationType: notificationType,
|
|
}
|
|
}
|
|
|
|
func HumanPasswordCodeAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
humanAdded := &HumanPasswordCodeAddedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}
|
|
err := json.Unmarshal(event.Data, humanAdded)
|
|
if err != nil {
|
|
return nil, errors.ThrowInternal(err, "USER-Ms90d", "unable to unmarshal human password code added")
|
|
}
|
|
|
|
return humanAdded, nil
|
|
}
|
|
|
|
type HumanPasswordCodeSentEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
}
|
|
|
|
func (e *HumanPasswordCodeSentEvent) Data() interface{} {
|
|
return nil
|
|
}
|
|
|
|
func NewHumanPasswordCodeSentEvent(ctx context.Context) *HumanPasswordCodeSentEvent {
|
|
return &HumanPasswordCodeSentEvent{
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
ctx,
|
|
HumanPasswordCodeSentType,
|
|
),
|
|
}
|
|
}
|
|
|
|
func HumanPasswordCodeSentEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
return &HumanPasswordCodeSentEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}, nil
|
|
}
|
|
|
|
type HumanPasswordCheckSucceededEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
}
|
|
|
|
func (e *HumanPasswordCheckSucceededEvent) Data() interface{} {
|
|
return nil
|
|
}
|
|
|
|
func NewHumanPasswordCheckSucceededEvent(ctx context.Context) *HumanPasswordCheckSucceededEvent {
|
|
return &HumanPasswordCheckSucceededEvent{
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
ctx,
|
|
HumanPasswordCheckSucceededType,
|
|
),
|
|
}
|
|
}
|
|
|
|
func HumanPasswordCheckSucceededEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
return &HumanPasswordCheckSucceededEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}, nil
|
|
}
|
|
|
|
type HumanPasswordCheckFailedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
}
|
|
|
|
func (e *HumanPasswordCheckFailedEvent) Data() interface{} {
|
|
return nil
|
|
}
|
|
|
|
func NewHumanPasswordCheckFailedEvent(ctx context.Context) *HumanPasswordCheckFailedEvent {
|
|
return &HumanPasswordCheckFailedEvent{
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
ctx,
|
|
HumanPasswordCheckFailedType,
|
|
),
|
|
}
|
|
}
|
|
|
|
func HumanPasswordCheckFailedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
return &HumanPasswordCheckFailedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}, nil
|
|
}
|