2022-04-12 14:20:17 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/command/preparation"
|
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2022-04-12 14:20:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Phone struct {
|
2023-03-14 19:20:38 +00:00
|
|
|
Number domain.PhoneNumber
|
2022-04-12 14:20:17 +00:00
|
|
|
Verified bool
|
2023-08-03 04:42:59 +00:00
|
|
|
|
|
|
|
// ReturnCode is used if the Verified field is false
|
|
|
|
ReturnCode bool
|
2022-04-12 14:20:17 +00:00
|
|
|
}
|
|
|
|
|
2024-09-26 07:14:33 +00:00
|
|
|
// newPhoneCode generates a new code to be sent out to via SMS or
|
|
|
|
// returns the ID of the external code provider (e.g. when using Twilio verification API)
|
|
|
|
func (c *Commands) newPhoneCode(ctx context.Context, filter preparation.FilterToQueryReducer, secretGeneratorType domain.SecretGeneratorType, alg crypto.EncryptionAlgorithm, defaultConfig *crypto.GeneratorConfig) (*EncryptedCode, string, error) {
|
|
|
|
externalID, err := c.activeSMSProvider(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, "", err
|
|
|
|
}
|
|
|
|
if externalID != "" {
|
|
|
|
return nil, externalID, nil
|
|
|
|
}
|
|
|
|
code, err := c.newEncryptedCodeWithDefault(ctx, filter, secretGeneratorType, alg, defaultConfig)
|
|
|
|
return code, "", err
|
2022-04-12 14:20:17 +00:00
|
|
|
}
|