Documentation
¶
Index ¶
- Constants
- Variables
- type Config
- type Option
- type PasswordChangeEventPayload
- type PasswordResetCompletedEventPayload
- type PasswordResetRequestedEventPayload
- type Plugin
- func (p *Plugin) ChangePassword(ctx context.Context, input dto.ChangePasswordDTO) error
- func (p *Plugin) ForgotPassword(ctx context.Context, input dto.ForgotPasswordDTO) (*entity.VerificationToken, error)
- func (p *Plugin) ID() string
- func (p *Plugin) Init(ctx *plugin.Context) error
- func (p *Plugin) ResetPassword(ctx context.Context, input dto.ResetPasswordDTO) error
- func (p *Plugin) SignIn(ctx context.Context, input dto.SignInDTO) (*entity.User, error)
- func (p *Plugin) SignUp(ctx context.Context, input dto.SignUpDTO) (*entity.User, error)
- type Repository
- type SignInEventPayload
- type SignUpEventPayload
Constants ¶
const ( PluginID = "email-password" CredentialProvider = "credential" )
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 ¶
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") )
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 ¶
WithMinPasswordLength sets the minimum required password length.
func WithRequireEmailVerification ¶
WithRequireEmailVerification defines whether email verification is required before sign-in.
func WithResetTokenExpiry ¶
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 ¶
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) ResetPassword ¶
ResetPassword validates the reset token and updates the user's password.
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 ¶
SignInEventPayload contains the data associated with a sign-in event.
type SignUpEventPayload ¶
SignUpEventPayload contains the data associated with a sign-up event.