mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-24 13:48:45 +00:00
new pkg structure (#1150)
* 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]>
This commit is contained in:
co-authored by
Fabiennne
parent
762941f0ea
commit
21ffe1b0cb
@@ -0,0 +1,161 @@
|
||||
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"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
emailEventPrefix = humanEventPrefix + "email."
|
||||
HumanEmailChangedType = emailEventPrefix + "changed"
|
||||
HumanEmailVerifiedType = emailEventPrefix + "verified"
|
||||
HumanEmailVerificationFailedType = emailEventPrefix + "verification.failed"
|
||||
HumanEmailCodeAddedType = emailEventPrefix + "code.added"
|
||||
HumanEmailCodeSentType = emailEventPrefix + "code.sent"
|
||||
)
|
||||
|
||||
type HumanEmailChangedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
EmailAddress string `json:"email,omitempty"`
|
||||
}
|
||||
|
||||
func (e *HumanEmailChangedEvent) Data() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func NewHumanEmailChangedEvent(ctx context.Context) *HumanEmailChangedEvent {
|
||||
return &HumanEmailChangedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
HumanEmailChangedType,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func HumanEmailChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
emailChangedEvent := &HumanEmailChangedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
err := json.Unmarshal(event.Data, emailChangedEvent)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "USER-4M0sd", "unable to unmarshal human password changed")
|
||||
}
|
||||
|
||||
return emailChangedEvent, nil
|
||||
}
|
||||
|
||||
type HumanEmailVerifiedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
IsEmailVerified bool `json:"-"`
|
||||
}
|
||||
|
||||
func (e *HumanEmailVerifiedEvent) Data() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewHumanEmailVerifiedEvent(ctx context.Context) *HumanEmailVerifiedEvent {
|
||||
return &HumanEmailVerifiedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
HumanEmailVerifiedType,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func HumanEmailVerifiedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
emailVerified := &HumanEmailVerifiedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
IsEmailVerified: true,
|
||||
}
|
||||
return emailVerified, nil
|
||||
}
|
||||
|
||||
type HumanEmailVerificationFailedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
}
|
||||
|
||||
func (e *HumanEmailVerificationFailedEvent) Data() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewHumanEmailVerificationFailedEvent(ctx context.Context) *HumanEmailVerificationFailedEvent {
|
||||
return &HumanEmailVerificationFailedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
HumanEmailVerificationFailedType,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func HumanEmailVerificationFailedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
return &HumanEmailVerificationFailedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}, nil
|
||||
}
|
||||
|
||||
type HumanEmailCodeAddedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
Code *crypto.CryptoValue `json:"code,omitempty"`
|
||||
Expiry time.Duration `json:"expiry,omitempty"`
|
||||
}
|
||||
|
||||
func (e *HumanEmailCodeAddedEvent) Data() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func NewHumanEmailCodeAddedEvent(
|
||||
ctx context.Context,
|
||||
code *crypto.CryptoValue,
|
||||
expiry time.Duration) *HumanEmailCodeAddedEvent {
|
||||
return &HumanEmailCodeAddedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
HumanEmailCodeAddedType,
|
||||
),
|
||||
Code: code,
|
||||
Expiry: expiry,
|
||||
}
|
||||
}
|
||||
|
||||
func HumanEmailCodeAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
codeAdded := &HumanEmailCodeAddedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
err := json.Unmarshal(event.Data, codeAdded)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "USER-3M0sd", "unable to unmarshal human email code added")
|
||||
}
|
||||
|
||||
return codeAdded, nil
|
||||
}
|
||||
|
||||
type HumanEmailCodeSentEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
}
|
||||
|
||||
func (e *HumanEmailCodeSentEvent) Data() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewHumanEmailCodeSentEvent(ctx context.Context) *HumanEmailCodeSentEvent {
|
||||
return &HumanEmailCodeSentEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
HumanEmailCodeSentType,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func HumanEmailCodeSentEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
return &HumanEmailCodeSentEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user