forgotpassword

package
v0.0.0-...-09efcc3 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: Apache-2.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DependencySet = wire.NewSet(
	wire.Struct(new(Service), "*"),
	wire.Struct(new(Sender), "*"),
	NewLogger,
)
View Source
var ErrFeatureDisabled = SendCodeFailed.NewWithCause("forgot password is disabled", apierrors.StringCause("FeatureDisabled"))
View Source
var ErrInvalidCode = PasswordResetFailed.NewWithCause("invalid code", apierrors.StringCause("InvalidCode"))
View Source
var ErrSendPasswordNoTarget = apierrors.Invalid.WithReason("SendPasswordNoTarget").New("no target to send the password")
View Source
var ErrUsedCode = PasswordResetFailed.NewWithCause("used code", apierrors.StringCause("UsedCode"))
View Source
var ErrUserNotFound = SendCodeFailed.NewWithCause("specified user not found", apierrors.StringCause("UserNotFound"))
View Source
var PasswordResetFailed = apierrors.Invalid.WithReason("PasswordResetFailed")
View Source
var SendCodeFailed = apierrors.Invalid.WithReason("ForgotPasswordFailed")

Functions

This section is empty.

Types

type AuthenticatorService

type AuthenticatorService interface {
	New(ctx context.Context, spec *authenticator.Spec) (*authenticator.Info, error)
	UpdatePassword(ctx context.Context, info *authenticator.Info, options *service.UpdatePasswordOptions) (bool, *authenticator.Info, error)

	List(ctx context.Context, userID string, filters ...authenticator.Filter) ([]*authenticator.Info, error)
	Update(ctx context.Context, info *authenticator.Info) error
	Create(ctx context.Context, authenticatorInfo *authenticator.Info, markVerified bool) error
	Delete(ctx context.Context, info *authenticator.Info) error
}

type CodeChannel

type CodeChannel string
const (
	CodeChannelUnknown  CodeChannel = ""
	CodeChannelEmail    CodeChannel = "email"
	CodeChannelWhatsapp CodeChannel = "whatsapp"
	CodeChannelSMS      CodeChannel = "sms"
)

type CodeKind

type CodeKind string
const (
	CodeKindUnknown   CodeKind = ""
	CodeKindLink      CodeKind = "CodeKindLink"
	CodeKindShortCode CodeKind = "CodeKindShortCode"
)

type CodeOptions

type CodeOptions struct {
	AuthenticationFlowType        string
	AuthenticationFlowName        string
	AuthenticationFlowJSONPointer jsonpointer.T
	Kind                          CodeKind
	Channel                       CodeChannel
	IsAdminAPIResetPassword       bool
}

type EventService

type EventService interface {
	DispatchEventOnCommit(ctx context.Context, payload event.Payload) error
}

type IdentityService

type IdentityService interface {
	ListByClaim(ctx context.Context, name string, value string) ([]*identity.Info, error)
	ListByUser(ctx context.Context, userID string) ([]*identity.Info, error)
}

type Logger

type Logger struct{ *log.Logger }

func NewLogger

func NewLogger(lf *log.Factory) Logger

type OTPCodeService

type OTPCodeService interface {
	GenerateOTP(ctx context.Context, kind otp.Kind, target string, form otp.Form, opt *otp.GenerateOptions) (string, error)
	VerifyOTP(ctx context.Context, kind otp.Kind, target string, otp string, opts *otp.VerifyOptions) error
	InspectState(ctx context.Context, kind otp.Kind, target string) (*otp.State, error)
	LookupCode(ctx context.Context, purpose otp.Purpose, code string) (target string, err error)
	ConsumeCode(ctx context.Context, purpose otp.Purpose, target string) error
}

type OTPSender

type OTPSender interface {
	Send(ctx context.Context, opts otp.SendOptions) error
}

type Sender

type Sender struct {
	AppConfg    *config.AppConfig
	Identities  IdentityService
	Sender      SenderService
	Translation TranslationService
}

func (*Sender) Send

func (s *Sender) Send(ctx context.Context, userID string, password string, msgType translation.MessageType) error

type SenderService

type SenderService interface {
	SendEmailInNewGoroutine(ctx context.Context, msgType translation.MessageType, opts *mail.SendOptions) error
}

type Service

type Service struct {
	Logger        Logger
	Config        *config.AppConfig
	FeatureConfig *config.FeatureConfig

	Identities     IdentityService
	Authenticators AuthenticatorService
	OTPCodes       OTPCodeService
	OTPSender      OTPSender
	PasswordSender Sender

	Events EventService
}

func (*Service) ChangePasswordByAdmin

func (s *Service) ChangePasswordByAdmin(ctx context.Context, options *SetPasswordOptions) error

func (*Service) CodeLength

func (s *Service) CodeLength(target string, channel CodeChannel, kind CodeKind) int

func (*Service) InspectState

func (s *Service) InspectState(ctx context.Context, target string, channel CodeChannel, kind CodeKind) (*otp.State, error)

InspectState is for external use. It DOES NOT report dummy code as invalid.

func (*Service) IsRateLimitError

func (s *Service) IsRateLimitError(err error, target string, channel CodeChannel, kind CodeKind) bool

func (*Service) ResetPasswordByEndUser

func (s *Service) ResetPasswordByEndUser(ctx context.Context, code string, newPassword string) error

ResetPasswordByEndUser consumes code and reset password to newPassword. If the code is valid, the password is reset to newPassword. newPassword is checked against the password policy so password policy error may also be returned.

func (*Service) ResetPasswordWithTarget

func (s *Service) ResetPasswordWithTarget(ctx context.Context, target string, code string, newPassword string, channel CodeChannel, kind CodeKind) error

ResetPasswordWithTarget is same as ResetPassword, except target is passed by caller.

func (*Service) SendCode

func (s *Service) SendCode(ctx context.Context, loginID string, options *CodeOptions) error

SendCode uses loginID to look up Email Login IDs and Phone Number Login IDs. For each looked up login ID, a code is generated and delivered asynchronously.

func (*Service) VerifyCode

func (s *Service) VerifyCode(ctx context.Context, code string) (state *otp.State, err error)

func (*Service) VerifyCodeWithTarget

func (s *Service) VerifyCodeWithTarget(ctx context.Context, target string, code string, codeChannel CodeChannel, kind CodeKind) (state *otp.State, err error)

type SetPasswordOptions

type SetPasswordOptions struct {
	UserID         string
	PlainPassword  string
	SetExpireAfter bool
	ExpireAfter    *time.Time
	SendPassword   bool
}

type TranslationService

type TranslationService interface {
	EmailMessageData(ctx context.Context, msg *translation.MessageSpec, variables *translation.PartialTemplateVariables) (*translation.EmailMessageData, error)
}

Jump to

Keyboard shortcuts

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