otp

package
v0.0.26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (

	//PINSMS is the sms formart to be send
	PINSMS = "" /* 144-byte string literal not displayed */

	//PINWhatsApp is the whatsapp formart to be send
	PINWhatsApp = "" /* 142-byte string literal not displayed */
)
View Source
const (
	ITCode        = "123456"
	ITPhoneNumber = "0798000000"
	ITEmail       = "test@healthcloud.co.ke"
)

These constants are here to support Integration Testing done by the Frontend team. IT is shorthand for Integration Tests

View Source
const SendOtpToEmailTemplate = `` /* 8409-byte string literal not displayed */

SendOtpToEmailTemplate generates an email template

Variables

This section is empty.

Functions

func GenerateEmailFunc

func GenerateEmailFunc(code string) string

GenerateEmailFunc generates the custom email to be sent to the user when sending the OTP through email

func ValidateGenerateRetryOTPPayload

func ValidateGenerateRetryOTPPayload(w http.ResponseWriter, r *http.Request) (*dto.GenerateRetryOTP, error)

ValidateGenerateRetryOTPPayload checks the validity of the request payload

func ValidateSendOTPPayload

func ValidateSendOTPPayload(w http.ResponseWriter, r *http.Request) (*dto.Msisdn, error)

ValidateSendOTPPayload checks the validity of the request payload

func ValidateVerifyOTPPayload

func ValidateVerifyOTPPayload(w http.ResponseWriter, r *http.Request, isEmail bool) (*dto.VerifyOTP, error)

ValidateVerifyOTPPayload checks the validity of the request payload

Types

type ServiceOTP

type ServiceOTP interface {
	GenerateAndSendOTP(ctx context.Context, msisdn string, appID *string) (string, error)
	SendOTPToEmail(ctx context.Context, msisdn, email *string, appID *string) (string, error)
	SaveOTPToFirestore(otp dto.OTP) error
	VerifyOtp(ctx context.Context, msisdn, verificationCode *string) (bool, error)
	VerifyEmailOtp(ctx context.Context, email, verificationCode *string) (bool, error)
	GenerateRetryOTP(ctx context.Context, msisdn *string, retryStep int, appID *string) (string, error)
	EmailVerificationOtp(ctx context.Context, email *string) (string, error)
	GenerateOTP(ctx context.Context) (string, error)
	SendTemporaryPIN(ctx context.Context, input dto.TemporaryPIN) error
}

ServiceOTP is an interface that defines all interactions with OTP service

type ServiceOTPImpl

type ServiceOTPImpl struct {
	// contains filtered or unexported fields
}

ServiceOTPImpl is an OTP generation and validation service

func NewService

func NewService(
	mail mail.ServiceMail,
	sms sms.ServiceSMS,
	twilio twilio.ServiceTwilio,
) *ServiceOTPImpl

NewService initializes a valid OTP service First we fetch the dependencies from dep.yaml file. Since this service has a predefined set of dependencies, the same dependecies defined in the yaml should be defined in the service struct definition explicitly, No guess work.

func (ServiceOTPImpl) EmailVerificationOtp

func (s ServiceOTPImpl) EmailVerificationOtp(ctx context.Context, email *string) (string, error)

EmailVerificationOtp generates an OTP to the supplied email for verification

func (ServiceOTPImpl) GenerateAndSendOTP

func (s ServiceOTPImpl) GenerateAndSendOTP(ctx context.Context, msisdn string, appID *string) (string, error)

GenerateAndSendOTP creates an OTP and sends it to the supplied phone number as a text message

func (ServiceOTPImpl) GenerateOTP

func (s ServiceOTPImpl) GenerateOTP(ctx context.Context) (string, error)

GenerateOTP generates an OTP

func (ServiceOTPImpl) GenerateRetryOTP

func (s ServiceOTPImpl) GenerateRetryOTP(
	ctx context.Context,
	msisdn *string,
	retryStep int,
	appID *string,
) (string, error)

GenerateRetryOTP generates fallback OTPs when Africa is talking sms fails

func (ServiceOTPImpl) SaveOTPToFirestore

func (s ServiceOTPImpl) SaveOTPToFirestore(otp dto.OTP) error

SaveOTPToFirestore persists the supplied OTP

func (ServiceOTPImpl) SendOTP

func (s ServiceOTPImpl) SendOTP(
	ctx context.Context,
	normalizedPhoneNumber string,
	code string,
	appID *string,
) (string, error)

SendOTP sends otp code message to specified number

func (ServiceOTPImpl) SendOTPToEmail

func (s ServiceOTPImpl) SendOTPToEmail(ctx context.Context, msisdn, email *string, appID *string) (string, error)

SendOTPToEmail is a companion to GenerateAndSendOTP function It will send the generated OTP to the provided email address

func (ServiceOTPImpl) SendTemporaryPIN

func (s ServiceOTPImpl) SendTemporaryPIN(ctx context.Context, input dto.TemporaryPIN) error

SendTemporaryPIN sends a temporary PIN message to user via whatsapp and SMS

func (ServiceOTPImpl) VerifyEmailOtp

func (s ServiceOTPImpl) VerifyEmailOtp(
	ctx context.Context,
	email, verificationCode *string,
) (bool, error)

VerifyEmailOtp checks for the validity of the supplied OTP but does not invalidate it

func (ServiceOTPImpl) VerifyOtp

func (s ServiceOTPImpl) VerifyOtp(ctx context.Context, msisdn, verificationCode *string) (bool, error)

VerifyOtp checks for the validity of the supplied OTP but does not invalidate it

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL