mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-17 05:18:04 +00:00
fa9f581d56
* chore: move to new org * logging * fix: org rename caos -> zitadel Co-authored-by: adlerhurst <silvan.reusser@gmail.com>
34 lines
974 B
Go
34 lines
974 B
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/ttacon/libphonenumber"
|
|
"github.com/zitadel/zitadel/internal/command/preparation"
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/errors"
|
|
)
|
|
|
|
type Phone struct {
|
|
Number string
|
|
Verified bool
|
|
}
|
|
|
|
func FormatPhoneNumber(number string) (string, error) {
|
|
if number == "" {
|
|
return "", nil
|
|
}
|
|
phoneNr, err := libphonenumber.Parse(number, libphonenumber.UNKNOWN_REGION)
|
|
if err != nil {
|
|
return "", errors.ThrowInvalidArgument(nil, "EVENT-so0wa", "Errors.User.Phone.Invalid")
|
|
}
|
|
number = libphonenumber.Format(phoneNr, libphonenumber.E164)
|
|
return number, nil
|
|
}
|
|
|
|
func newPhoneCode(ctx context.Context, filter preparation.FilterToQueryReducer, alg crypto.EncryptionAlgorithm) (value *crypto.CryptoValue, expiry time.Duration, err error) {
|
|
return newCryptoCodeWithExpiry(ctx, filter, domain.SecretGeneratorTypeVerifyPhoneCode, alg)
|
|
}
|