emailpassword

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PluginID           = "email-password"
	CredentialProvider = "credential"
)
View Source
const (
	// EventSignUpBefore is emitted right before creating a new user record.
	// Payload: *SignUpEventPayload
	EventSignUpBefore = "emailpassword:signup:before"

	// EventSignUpAfter is emitted immediately after successfully registering a user and their account.
	// Payload: *SignUpEventPayload
	EventSignUpAfter = "emailpassword:signup:after"

	// EventSignInBefore is emitted before validating credentials during sign-in.
	// Payload: *SignInEventPayload
	EventSignInBefore = "emailpassword:signin:before"

	// EventSignInAfter is emitted after successfully verifying user credentials.
	// Payload: *SignInEventPayload
	EventSignInAfter = "emailpassword:signin:after"

	// EventPasswordChangeBefore is emitted before updating a user's password.
	// Payload: *PasswordChangeEventPayload
	EventPasswordChangeBefore = "emailpassword:password_change:before"

	// EventPasswordChangeAfter is emitted after successfully updating a user's password.
	// Payload: *PasswordChangeEventPayload
	EventPasswordChangeAfter = "emailpassword:password_change:after"

	// EventPasswordResetRequested is emitted when generating a password reset token.
	// Useful for sending notification emails.
	// Payload: *PasswordResetRequestedEventPayload
	EventPasswordResetRequested = "emailpassword:password_reset:requested"

	// EventPasswordResetCompleted is emitted after changing a password using a valid token.
	// Payload: *PasswordResetCompletedEventPayload
	EventPasswordResetCompleted = "emailpassword:password_reset:completed"
)

Variables

View Source
var (
	ErrPasswordTooShort   = errors.New("emailpassword: la contraseña no cumple con la longitud mínima requerida")
	ErrInvalidCredentials = errors.New("emailpassword: credenciales inválidas")
	ErrEmailNotVerified   = errors.New("emailpassword: el correo electrónico no ha sido verificado")
	ErrInvalidCurrentPass = errors.New("emailpassword: la contraseña actual es incorrecta")
	ErrTokenExpired       = errors.New("emailpassword: el token ha expirado")
)
View Source
var (
	ErrUserAlreadyExists = errors.New("emailpassword: el usuario ya existe")
	ErrUserNotFound      = errors.New("emailpassword: usuario no encontrado")
	ErrAccountNotFound   = errors.New("emailpassword: cuenta credencial no encontrada")
	ErrInvalidToken      = errors.New("emailpassword: token de verificación inválido o expirado")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	MinPasswordLength        int
	RequireEmailVerification bool
	ResetTokenExpiry         time.Duration
}

Config defines the configurable options for the EmailPassword plugin.

type Option

type Option func(*Config)

Option defines a functional option for configuring the EmailPassword plugin.

func WithMinPasswordLength

func WithMinPasswordLength(length int) Option

WithMinPasswordLength sets the minimum required password length.

func WithRequireEmailVerification

func WithRequireEmailVerification(require bool) Option

WithRequireEmailVerification defines whether email verification is required before sign-in.

func WithResetTokenExpiry

func WithResetTokenExpiry(d time.Duration) Option

WithResetTokenExpiry sets the validity duration for password reset tokens.

type PasswordChangeEventPayload

type PasswordChangeEventPayload struct {
	UserID string
}

PasswordChangeEventPayload contains the data for a password change event.

type PasswordResetCompletedEventPayload

type PasswordResetCompletedEventPayload struct {
	UserID string
}

PasswordResetCompletedEventPayload contains confirmation of password reset completion.

type PasswordResetRequestedEventPayload

type PasswordResetRequestedEventPayload struct {
	User      *entity.User
	Token     string
	ExpiresAt time.Time
}

PasswordResetRequestedEventPayload contains the details for sending a password reset email.

type Plugin

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

Plugin implements plugin.Plugin interface for email/password authentication.

func New

func New(repo Repository, opts ...Option) *Plugin

New creates a new EmailPassword plugin instance with the specified repository and functional options.

func (*Plugin) ChangePassword

func (p *Plugin) ChangePassword(ctx context.Context, input dto.ChangePasswordDTO) error

ChangePassword changes the password of an existing user after validating current password.

func (*Plugin) ForgotPassword

func (p *Plugin) ForgotPassword(ctx context.Context, input dto.ForgotPasswordDTO) (*entity.VerificationToken, error)

ForgotPassword generates a secure reset token and publishes notification event.

func (*Plugin) ID

func (p *Plugin) ID() string

ID returns the unique identifier for the plugin ("email-password").

func (*Plugin) Init

func (p *Plugin) Init(ctx *plugin.Context) error

Init initializes the plugin within the global GoModularAuth context.

func (*Plugin) ResetPassword

func (p *Plugin) ResetPassword(ctx context.Context, input dto.ResetPasswordDTO) error

ResetPassword validates the reset token and updates the user's password.

func (*Plugin) SignIn

func (p *Plugin) SignIn(ctx context.Context, input dto.SignInDTO) (*entity.User, error)

SignIn authenticates user credentials.

func (*Plugin) SignUp

func (p *Plugin) SignUp(ctx context.Context, input dto.SignUpDTO) (*entity.User, error)

SignUp registers a new user with email and password credentials.

type Repository

type Repository interface {
	GetUserByEmail(ctx context.Context, email string) (*entity.User, error)
	GetUserByID(ctx context.Context, id string) (*entity.User, error)
	CreateUser(ctx context.Context, user *entity.User) error
	UpdateUser(ctx context.Context, user *entity.User) error
	GetAccountByUserIDAndProvider(ctx context.Context, userID, provider string) (*entity.Account, error)
	CreateAccount(ctx context.Context, account *entity.Account) error
	UpdateAccountPassword(ctx context.Context, accountID, hashedPassword string) error
	CreateVerificationToken(ctx context.Context, token *entity.VerificationToken) error
	GetVerificationToken(ctx context.Context, token string) (*entity.VerificationToken, error)
	DeleteVerificationToken(ctx context.Context, token string) error
}

Repository defines the persistent storage contract required by the EmailPassword plugin.

type SignInEventPayload

type SignInEventPayload struct {
	User *entity.User
}

SignInEventPayload contains the data associated with a sign-in event.

type SignUpEventPayload

type SignUpEventPayload struct {
	User *entity.User
}

SignUpEventPayload contains the data associated with a sign-up event.

Jump to

Keyboard shortcuts

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