mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 20:38:00 +00:00
e00cc187fa
* fix: make user creation errors helpful * fix linting and unit testing errors * fix linting * make zitadel config reusable * fix human validations * translate ssr errors * make zitadel config reusable * cover more translations for ssr * handle email validation message centrally * fix unit tests * fix linting * align signatures * use more precise wording * handle phone validation message centrally * fix: return specific profile errors * docs: edit comments * fix unit tests --------- Co-authored-by: Silvan <silvan.reusser@gmail.com>
46 lines
901 B
Go
46 lines
901 B
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
|
)
|
|
|
|
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) GeneratePhoneCodeIfNeeded(phoneGenerator crypto.Generator) (*PhoneCode, error) {
|
|
var phoneCode *PhoneCode
|
|
if p.IsPhoneVerified {
|
|
return phoneCode, nil
|
|
}
|
|
phoneCode = new(PhoneCode)
|
|
return phoneCode, phoneCode.GeneratePhoneCode(phoneGenerator)
|
|
}
|
|
|
|
func (code *PhoneCode) GeneratePhoneCode(phoneGenerator crypto.Generator) error {
|
|
phoneCodeCrypto, _, err := crypto.NewCode(phoneGenerator)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
code.Code = phoneCodeCrypto
|
|
code.Expiry = phoneGenerator.Expiry()
|
|
return nil
|
|
}
|