mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-22 07:47:29 +00:00
3f345b1ade
* fix: org tests * fix: org tests * fix: user grant test * fix: user grant test * fix: project and project role test * fix: project grant test * fix: project grant test * fix: project member, grant member, app changed tests * fix: application tests * fix: application tests * fix: add oidc app test * fix: add oidc app test * fix: add api keys test * fix: iam policies * fix: iam and org member tests * fix: idp config tests * fix: iam tests * fix: user tests * fix: user tests * fix: user tests * fix: user tests * fix: user tests * fix: user tests * fix: user tests * fix: user tests * fix: user tests * fix: user tests * fix: org domain test * fix: org tests * fix: org tests * fix: implement org idps * fix: pr requests * fix: email tests * fix: fix idp check * fix: fix user profile
219 lines
5.6 KiB
Go
219 lines
5.6 KiB
Go
package user
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
"time"
|
|
|
|
"github.com/caos/zitadel/internal/crypto"
|
|
"github.com/caos/zitadel/internal/errors"
|
|
"github.com/caos/zitadel/internal/eventstore/repository"
|
|
)
|
|
|
|
const (
|
|
phoneEventPrefix = humanEventPrefix + "phone."
|
|
HumanPhoneChangedType = phoneEventPrefix + "changed"
|
|
HumanPhoneRemovedType = phoneEventPrefix + "removed"
|
|
HumanPhoneVerifiedType = phoneEventPrefix + "verified"
|
|
HumanPhoneVerificationFailedType = phoneEventPrefix + "verification.failed"
|
|
HumanPhoneCodeAddedType = phoneEventPrefix + "code.added"
|
|
HumanPhoneCodeSentType = phoneEventPrefix + "code.sent"
|
|
)
|
|
|
|
type HumanPhoneChangedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
PhoneNumber string `json:"phone,omitempty"`
|
|
}
|
|
|
|
func (e *HumanPhoneChangedEvent) Data() interface{} {
|
|
return e
|
|
}
|
|
|
|
func (e *HumanPhoneChangedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
return nil
|
|
}
|
|
|
|
func NewHumanPhoneChangedEvent(ctx context.Context, aggregate *eventstore.Aggregate, phone string) *HumanPhoneChangedEvent {
|
|
return &HumanPhoneChangedEvent{
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
ctx,
|
|
aggregate,
|
|
HumanPhoneChangedType,
|
|
),
|
|
PhoneNumber: phone,
|
|
}
|
|
}
|
|
|
|
func HumanPhoneChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
phoneChangedEvent := &HumanPhoneChangedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}
|
|
err := json.Unmarshal(event.Data, phoneChangedEvent)
|
|
if err != nil {
|
|
return nil, errors.ThrowInternal(err, "USER-5M0pd", "unable to unmarshal human phone changed")
|
|
}
|
|
|
|
return phoneChangedEvent, nil
|
|
}
|
|
|
|
type HumanPhoneRemovedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
}
|
|
|
|
func (e *HumanPhoneRemovedEvent) Data() interface{} {
|
|
return nil
|
|
}
|
|
|
|
func (e *HumanPhoneRemovedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
return nil
|
|
}
|
|
|
|
func NewHumanPhoneRemovedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanPhoneRemovedEvent {
|
|
return &HumanPhoneRemovedEvent{
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
ctx,
|
|
aggregate,
|
|
HumanPhoneRemovedType,
|
|
),
|
|
}
|
|
}
|
|
|
|
func HumanPhoneRemovedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
return &HumanPhoneChangedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}, nil
|
|
}
|
|
|
|
type HumanPhoneVerifiedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
IsPhoneVerified bool `json:"-"`
|
|
}
|
|
|
|
func (e *HumanPhoneVerifiedEvent) Data() interface{} {
|
|
return nil
|
|
}
|
|
|
|
func (e *HumanPhoneVerifiedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
return nil
|
|
}
|
|
|
|
func NewHumanPhoneVerifiedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanPhoneVerifiedEvent {
|
|
return &HumanPhoneVerifiedEvent{
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
ctx,
|
|
aggregate,
|
|
HumanPhoneVerifiedType,
|
|
),
|
|
}
|
|
}
|
|
|
|
func HumanPhoneVerifiedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
return &HumanPhoneVerifiedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
IsPhoneVerified: true,
|
|
}, nil
|
|
}
|
|
|
|
type HumanPhoneVerificationFailedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
}
|
|
|
|
func (e *HumanPhoneVerificationFailedEvent) Data() interface{} {
|
|
return nil
|
|
}
|
|
|
|
func (e *HumanPhoneVerificationFailedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
return nil
|
|
}
|
|
|
|
func NewHumanPhoneVerificationFailedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanPhoneVerificationFailedEvent {
|
|
return &HumanPhoneVerificationFailedEvent{
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
ctx,
|
|
aggregate,
|
|
HumanPhoneVerificationFailedType,
|
|
),
|
|
}
|
|
}
|
|
|
|
func HumanPhoneVerificationFailedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
return &HumanPhoneVerificationFailedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}, nil
|
|
}
|
|
|
|
type HumanPhoneCodeAddedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
Code *crypto.CryptoValue `json:"code,omitempty"`
|
|
Expiry time.Duration `json:"expiry,omitempty"`
|
|
}
|
|
|
|
func (e *HumanPhoneCodeAddedEvent) Data() interface{} {
|
|
return e
|
|
}
|
|
|
|
func (e *HumanPhoneCodeAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
return nil
|
|
}
|
|
|
|
func NewHumanPhoneCodeAddedEvent(
|
|
ctx context.Context,
|
|
aggregate *eventstore.Aggregate,
|
|
code *crypto.CryptoValue,
|
|
expiry time.Duration,
|
|
) *HumanPhoneCodeAddedEvent {
|
|
return &HumanPhoneCodeAddedEvent{
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
ctx,
|
|
aggregate,
|
|
HumanPhoneCodeAddedType,
|
|
),
|
|
Code: code,
|
|
Expiry: expiry,
|
|
}
|
|
}
|
|
|
|
func HumanPhoneCodeAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
codeAdded := &HumanPhoneCodeAddedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}
|
|
err := json.Unmarshal(event.Data, codeAdded)
|
|
if err != nil {
|
|
return nil, errors.ThrowInternal(err, "USER-6Ms9d", "unable to unmarshal human phone code added")
|
|
}
|
|
|
|
return codeAdded, nil
|
|
}
|
|
|
|
type HumanPhoneCodeSentEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
}
|
|
|
|
func (e *HumanPhoneCodeSentEvent) Data() interface{} {
|
|
return e
|
|
}
|
|
|
|
func (e *HumanPhoneCodeSentEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
return nil
|
|
}
|
|
|
|
func NewHumanPhoneCodeSentEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanPhoneCodeSentEvent {
|
|
return &HumanPhoneCodeSentEvent{
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
ctx,
|
|
aggregate,
|
|
HumanPhoneCodeSentType,
|
|
),
|
|
}
|
|
}
|
|
|
|
func HumanPhoneCodeSentEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
return &HumanPhoneCodeSentEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}, nil
|
|
}
|