mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-01 16:38:52 +00:00
* fix: use domain models for v2 eventstore * fix: user domain model * Update internal/api/grpc/admin/login_policy_converter.go Co-authored-by: Livio Amstutz <[email protected]> * fix: converter Co-authored-by: Livio Amstutz <[email protected]>
42 lines
860 B
Go
42 lines
860 B
Go
package domain
|
|
|
|
import (
|
|
"github.com/caos/zitadel/internal/crypto"
|
|
caos_errs "github.com/caos/zitadel/internal/errors"
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
|
"github.com/ttacon/libphonenumber"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
defaultRegion = "CH"
|
|
)
|
|
|
|
type Phone struct {
|
|
es_models.ObjectRoot
|
|
|
|
PhoneNumber string
|
|
IsPhoneVerified bool
|
|
}
|
|
|
|
type PhoneCode struct {
|
|
es_models.ObjectRoot
|
|
|
|
Code *crypto.CryptoValue
|
|
Expiry time.Duration
|
|
}
|
|
|
|
func (p *Phone) IsValid() bool {
|
|
err := p.formatPhone()
|
|
return p.PhoneNumber != "" && err == nil
|
|
}
|
|
|
|
func (p *Phone) formatPhone() error {
|
|
phoneNr, err := libphonenumber.Parse(p.PhoneNumber, defaultRegion)
|
|
if err != nil {
|
|
return caos_errs.ThrowPreconditionFailed(nil, "EVENT-so0wa", "Errors.User.Phone.Invalid")
|
|
}
|
|
p.PhoneNumber = libphonenumber.Format(phoneNr, libphonenumber.E164)
|
|
return nil
|
|
}
|