Documentation ¶
Index ¶
- Constants
- Variables
- func WithConfig(config *Config) func(*FormConfig)
- func WithLogger(logger *slog.Logger) func(*Config)
- func WithPasswordHasher(hasher password.PasswordHasher) func(*Config)
- type Config
- type FormConfig
- type FormHandler
- type Handler
- type PasswordResetRequestMessagePayload
- type PasswordResetSuccessMessagePayload
Constants ¶
const ( FieldNameEmail = "email" FieldNameResetToken = "reset_token" FieldNamePassword = "password" )
const ( ResetTokenExpiry = time.Duration(12 * time.Hour) ResetTokenLength = 32 )
Variables ¶
var ( // ErrUsedPasswordResetToken is returned when the password reset token has already been used. ErrUsedPasswordResetToken = errors.New("password/reset: used password reset token") )
Functions ¶
func WithConfig ¶
func WithConfig(config *Config) func(*FormConfig)
WithConfig sets the configuration for the underlying Handler for FormHandler.
func WithLogger ¶
WithLogger configures the logger.
func WithPasswordHasher ¶
func WithPasswordHasher(hasher password.PasswordHasher) func(*Config)
WithPasswordHasher configures the password hasher.
When setting a password hasher make sure to set it across all modules, such as user registrration, password reset and password verification.
Types ¶
type Config ¶
type Config struct { PasswordHasher password.PasswordHasher // optional Logger *slog.Logger // optional // TokenLength set the length of the reset token. // // Defaults to ResetTokenExpiry. TokenLength int // optinal // TokenExpiryIn set the expiry time of the reset token. TokenExpiryIn time.Duration // optional }
Config is the configuration for the password handler.
Make sure to use the NewConfig function to create a new config, instead of instatiating the struct directly.
type FormConfig ¶
type FormConfig struct { *Config EmailFieldName string ResetTokenFieldName string PasswordFieldName string }
FormConfig is the configuration for form-based password reset.
func NewFormConfig ¶
func NewFormConfig( config ...func(*FormConfig), ) *FormConfig
NewFormConfig creates a new FormConfig with the given configuration options.
type FormHandler ¶
type FormHandler struct {
// contains filtered or unexported fields
}
FormHandler is a wrapper around Handler handling HTTP form requests.
func NewFormHandler ¶
func NewFormHandler( driver driver.Driver, sender sender.Sender, config *FormConfig, ) *FormHandler
NewFormHandler creates a new FormHandler with the given configuration.
func (*FormHandler) HandlePasswordReset ¶
func (h *FormHandler) HandlePasswordReset(req *http.Request) error
HandlePasswordReset handles a password reset request.
func (*FormHandler) HandlePasswordResetConfirm ¶
func (h *FormHandler) HandlePasswordResetConfirm(req *http.Request) error
HandlePasswordResetConfirm handles a password reset confirmation.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles password reset requests.
It is a general enough implementation so it can be used for different communication methods.
Check out the FormHandler for a ready to use implementation that handles HTTP form requests.
func (*Handler) HandlePasswordReset ¶
HandlePasswordReset handles a password reset request.
type PasswordResetRequestMessagePayload ¶
type PasswordResetRequestMessagePayload struct {
Token string
}
ResetTokenMessagePayload is the payload for the reset token message.
type PasswordResetSuccessMessagePayload ¶
type PasswordResetSuccessMessagePayload struct{}
PasswordResetSuccessMessagePayload is the payload for the password reset success message.