Documentation
¶
Index ¶
- Constants
- func CanRecoverAccount(u *happydns.UserAuth, key string) error
- func GenAccountRecoveryHash(recoveryKey []byte, previous bool) string
- func GenRegistrationHash(u *happydns.UserAuth, previous bool) string
- type AuthUserStorage
- type CanRegisterUsecase
- type ChangePasswordUsecase
- func (uc *ChangePasswordUsecase) Change(user *happydns.UserAuth, password string) error
- func (uc *ChangePasswordUsecase) CheckNewPassword(user *happydns.UserAuth, form happydns.ChangePasswordForm) error
- func (uc *ChangePasswordUsecase) CheckResetPassword(user *happydns.UserAuth, form happydns.ChangePasswordForm) error
- type CheckPasswordConstraintsUsecase
- type CreateAuthUserUsecase
- type DeleteAuthUserUsecase
- type EmailValidationUsecase
- type GetAuthUserUsecase
- type RecoverAccountUsecase
- type Service
- func (s *Service) CanRegister(user happydns.UserRegistration) error
- func (s *Service) ChangePassword(user *happydns.UserAuth, newPassword string) error
- func (s *Service) CheckNewPassword(user *happydns.UserAuth, request happydns.ChangePasswordForm) error
- func (s *Service) CheckPassword(user *happydns.UserAuth, request happydns.ChangePasswordForm) error
- func (s *Service) CreateAuthUser(uu happydns.UserRegistration) (*happydns.UserAuth, error)
- func (s *Service) DeleteAuthUser(user *happydns.UserAuth, password string) error
- func (s *Service) GenerateRecoveryLink(user *happydns.UserAuth) (string, error)
- func (s *Service) GenerateValidationLink(user *happydns.UserAuth) string
- func (s *Service) GetAuthUser(userID happydns.Identifier) (*happydns.UserAuth, error)
- func (s *Service) GetAuthUserByEmail(email string) (*happydns.UserAuth, error)
- func (s *Service) ResetPassword(user *happydns.UserAuth, form happydns.AccountRecoveryForm) error
- func (s *Service) SendRecoveryLink(user *happydns.UserAuth) error
- func (s *Service) SendValidationLink(user *happydns.UserAuth) error
- func (s *Service) ValidateEmail(user *happydns.UserAuth, form happydns.AddressValidationForm) error
Constants ¶
AccountRecoveryHashValidityis the time during which the recovery link is at least valid.
RegistrationHashValidity is the time during which the email validation link is at least valid.
Variables ¶
This section is empty.
Functions ¶
func CanRecoverAccount ¶
CanRecoverAccount checks if the given key is a valid recovery hash.
func GenAccountRecoveryHash ¶
GenAccountRecoveryHash generates the recovery hash for the current or previous period. It updates the UserAuth structure in some cases, when it needs to generate a new recovery key, so don't forget to save the changes made.
Types ¶
type AuthUserStorage ¶
type AuthUserStorage interface { // ListAllAuthUsers retrieves the list of known Users. ListAllAuthUsers() (happydns.Iterator[happydns.UserAuth], error) // GetAuthUser retrieves the User with the given identifier. GetAuthUser(id happydns.Identifier) (*happydns.UserAuth, error) // GetAuthUserByEmail retrieves the User with the given email address. GetAuthUserByEmail(email string) (*happydns.UserAuth, error) // AuthUserExists checks if the given email address is already associated to an User. AuthUserExists(email string) (bool, error) // CreateAuthUser creates a record in the database for the given User. CreateAuthUser(user *happydns.UserAuth) error // UpdateAuthUser updates the fields of the given User. UpdateAuthUser(user *happydns.UserAuth) error // DeleteAuthUser removes the given User from the database. DeleteAuthUser(user *happydns.UserAuth) error // ClearAuthUsers deletes all AuthUsers present in the database. ClearAuthUsers() error }
type CanRegisterUsecase ¶
type CanRegisterUsecase struct {
// contains filtered or unexported fields
}
CanRegisterUsecase struct holds the configuration to check if registration is allowed.
func NewCanRegisterUsecase ¶
func NewCanRegisterUsecase(cfg *happydns.Options) *CanRegisterUsecase
NewCanRegisterUsecase creates a new instance of CanRegisterUsecase.
func (*CanRegisterUsecase) IsOpened ¶
func (uc *CanRegisterUsecase) IsOpened() bool
IsOpened returns true if user registrations are enabled on this instance.
type ChangePasswordUsecase ¶
type ChangePasswordUsecase struct {
// contains filtered or unexported fields
}
ChangePasswordUsecase handles the logic for changing a user's password.
func NewChangePasswordUsecase ¶
func NewChangePasswordUsecase(store AuthUserStorage, checkPasswordConstraints *CheckPasswordConstraintsUsecase) *ChangePasswordUsecase
NewChangePasswordUsecase creates a new instance of ChangePasswordUsecase.
func (*ChangePasswordUsecase) Change ¶
func (uc *ChangePasswordUsecase) Change(user *happydns.UserAuth, password string) error
Change changes the password of the given user after verifying the current password and checking new password constraints (length, confirmation, etc.).
func (*ChangePasswordUsecase) CheckNewPassword ¶
func (uc *ChangePasswordUsecase) CheckNewPassword(user *happydns.UserAuth, form happydns.ChangePasswordForm) error
func (*ChangePasswordUsecase) CheckResetPassword ¶
func (uc *ChangePasswordUsecase) CheckResetPassword(user *happydns.UserAuth, form happydns.ChangePasswordForm) error
type CheckPasswordConstraintsUsecase ¶
type CheckPasswordConstraintsUsecase struct { }
CheckPasswordConstraintsUsecase struct contains the necessary dependencies for the usecase to check the password constraints.
func NewCheckPasswordConstraintsUsecase ¶
func NewCheckPasswordConstraintsUsecase() *CheckPasswordConstraintsUsecase
func (*CheckPasswordConstraintsUsecase) Check ¶
func (uc *CheckPasswordConstraintsUsecase) Check(password string) error
Check checks the given password to see if it adheres to the system's constraints. It validates length and format as necessary. Returns an error if the password is invalid.
type CreateAuthUserUsecase ¶
type CreateAuthUserUsecase struct {
// contains filtered or unexported fields
}
CreateAuthUserUsecase handles the creation of a new authenticated user account.
func NewCreateAuthUserUsecase ¶
func NewCreateAuthUserUsecase(store AuthUserStorage, mailer happydns.Mailer, checkPasswordConstraints *CheckPasswordConstraintsUsecase, emailValidation happydns.EmailValidationUsecase) *CreateAuthUserUsecase
NewCreateAuthUserUsecase initializes a new instance of CreateAuthUserUsecase.
func (*CreateAuthUserUsecase) Create ¶
func (uc *CreateAuthUserUsecase) Create(uu happydns.UserRegistration) (*happydns.UserAuth, error)
Create validates the registration request, creates the user, and optionally sends a validation email.
type DeleteAuthUserUsecase ¶
type DeleteAuthUserUsecase struct {
// contains filtered or unexported fields
}
DeleteAuthUserUsecase represents the use case for deleting an authenticated user and their sessions.
func NewDeleteAuthUserUsecase ¶
func NewDeleteAuthUserUsecase(store AuthUserStorage, closeUserSessions happydns.SessionCloserUsecase) *DeleteAuthUserUsecase
NewDeleteAuthUserUsecase creates a new instance of DeleteAuthUserUsecase.
func (*DeleteAuthUserUsecase) Delete ¶
func (uc *DeleteAuthUserUsecase) Delete(user *happydns.UserAuth, password string) error
Do deletes an authenticated user from the system, ensuring their sessions are also removed. It first verifies the current password, then removes the user and their associated sessions from the storage.
type EmailValidationUsecase ¶
type EmailValidationUsecase struct {
// contains filtered or unexported fields
}
func NewEmailValidationUsecase ¶
func NewEmailValidationUsecase(store AuthUserStorage, mailer happydns.Mailer, config *happydns.Options) *EmailValidationUsecase
func (*EmailValidationUsecase) GenerateLink ¶
func (uc *EmailValidationUsecase) GenerateLink(user *happydns.UserAuth) string
GenerateLink returns the absolute URL corresponding to the recovery URL of the given account.
func (*EmailValidationUsecase) SendLink ¶
func (uc *EmailValidationUsecase) SendLink(user *happydns.UserAuth) error
func (*EmailValidationUsecase) Validate ¶
func (uc *EmailValidationUsecase) Validate(user *happydns.UserAuth, form happydns.AddressValidationForm) error
Validate tries to validate the email address by comparing the given key to the expected one.
type GetAuthUserUsecase ¶
type GetAuthUserUsecase struct {
// contains filtered or unexported fields
}
GetAuthUserUsecase handles retrieval of authenticated users by ID.
func NewGetAuthUserUsecase ¶
func NewGetAuthUserUsecase(store AuthUserStorage) *GetAuthUserUsecase
NewGetAuthUserUsecase creates a new instance of GetAuthUserUsecase.
func (*GetAuthUserUsecase) ByEmail ¶
func (uc *GetAuthUserUsecase) ByEmail(email string) (*happydns.UserAuth, error)
ByEmail retrieves an authenticated user from the storage by their email address. Returns the user if found, or an error otherwise.
func (*GetAuthUserUsecase) ByID ¶
func (uc *GetAuthUserUsecase) ByID(id happydns.Identifier) (*happydns.UserAuth, error)
ByID retrieves an authenticated user from the storage by their unique identifier. Returns the user if found, or an error otherwise.
type RecoverAccountUsecase ¶
type RecoverAccountUsecase struct {
// contains filtered or unexported fields
}
func NewRecoverAccountUsecase ¶
func NewRecoverAccountUsecase(store AuthUserStorage, mailer happydns.Mailer, config *happydns.Options, changePassword *ChangePasswordUsecase) *RecoverAccountUsecase
func (*RecoverAccountUsecase) GenerateLink ¶
func (uc *RecoverAccountUsecase) GenerateLink(user *happydns.UserAuth) (string, error)
GenerateLink returns the absolute URL corresponding to the recovery URL of the given account.
func (*RecoverAccountUsecase) ResetPassword ¶
func (uc *RecoverAccountUsecase) ResetPassword(user *happydns.UserAuth, form happydns.AccountRecoveryForm) error
func (*RecoverAccountUsecase) SendLink ¶
func (uc *RecoverAccountUsecase) SendLink(user *happydns.UserAuth) error
type Service ¶
type Service struct { // Usecases for user management actions CanRegisterUC *CanRegisterUsecase ChangePasswordUC *ChangePasswordUsecase CheckPasswordConstraintsUC *CheckPasswordConstraintsUsecase CreateAuthUserUC *CreateAuthUserUsecase DeleteAuthUserUC *DeleteAuthUserUsecase EmailValidationUC happydns.EmailValidationUsecase GetAuthUserUC *GetAuthUserUsecase RecoverAccountUC *RecoverAccountUsecase }
Service groups all use cases related to user authentication and management.
func NewAuthUserUsecases ¶
func NewAuthUserUsecases( cfg *happydns.Options, mailer happydns.Mailer, store AuthUserStorage, closeUserSessionsUseCase happydns.SessionCloserUsecase, ) *Service
NewAuthUserService initializes and returns a new AuthUserService, containing all use cases.
func (*Service) ChangePassword ¶
func (*Service) CheckNewPassword ¶
func (*Service) CheckPassword ¶
func (*Service) CreateAuthUser ¶
func (*Service) DeleteAuthUser ¶
func (*Service) GenerateRecoveryLink ¶
func (*Service) GenerateValidationLink ¶
func (*Service) GetAuthUser ¶
func (*Service) GetAuthUserByEmail ¶
func (*Service) ResetPassword ¶
func (*Service) SendRecoveryLink ¶
func (*Service) SendValidationLink ¶
Source Files
¶
- account_recovery.go
- authuser_storage.go
- can_register.go
- change_password.go
- check_password_constraints.go
- create_auth_user.go
- delete_auth_user.go
- email_validation.go
- factory.go
- get_auth_user.go