mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 13:37:35 +00:00
chore: move the go code into a subfolder
This commit is contained in:
40
apps/api/internal/notification/channels/twilio/config.go
Normal file
40
apps/api/internal/notification/channels/twilio/config.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package twilio
|
||||
|
||||
import (
|
||||
newTwilio "github.com/twilio/twilio-go"
|
||||
verify "github.com/twilio/twilio-go/rest/verify/v2"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
SID string
|
||||
Token string
|
||||
SenderNumber string
|
||||
VerifyServiceSID string
|
||||
}
|
||||
|
||||
func (t *Config) IsValid() bool {
|
||||
return t.SID != "" && t.Token != "" && t.SenderNumber != ""
|
||||
}
|
||||
|
||||
func (t *Config) VerifyCode(verificationID, code string) error {
|
||||
client := newTwilio.NewRestClientWithParams(newTwilio.ClientParams{Username: t.SID, Password: t.Token})
|
||||
checkParams := &verify.CreateVerificationCheckParams{}
|
||||
checkParams.SetVerificationSid(verificationID)
|
||||
checkParams.SetCode(code)
|
||||
resp, err := client.VerifyV2.CreateVerificationCheck(t.VerifyServiceSID, checkParams)
|
||||
if err != nil || resp.Status == nil {
|
||||
return zerrors.ThrowInvalidArgument(err, "TWILI-JK3ta", "Errors.User.Code.NotFound")
|
||||
}
|
||||
switch *resp.Status {
|
||||
case "approved":
|
||||
return nil
|
||||
case "expired":
|
||||
return zerrors.ThrowInvalidArgument(nil, "TWILI-SF3ba", "Errors.User.Code.Expired")
|
||||
case "max_attempts_reached":
|
||||
return zerrors.ThrowInvalidArgument(nil, "TWILI-Ok39a", "Errors.User.Code.NotFound")
|
||||
default:
|
||||
return zerrors.ThrowInvalidArgument(nil, "TWILI-Skwe4", "Errors.User.Code.Invalid")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user