Documentation ¶
Index ¶
- Constants
- type EmailRegistration
- func (r *EmailRegistration) Activate(token string) error
- func (r *EmailRegistration) GetUser(userID ids.ID) (*User, error)
- func (r *EmailRegistration) Login(email string, password string) (ids.ID, error)
- func (r *EmailRegistration) Register(email string, password string) error
- func (r *EmailRegistration) RequestResetPassword(email string) error
- func (r *EmailRegistration) ResetPasswordWithToken(token string, newPassword string) error
- type HostInfo
- type NopRegistrationRepo
- func (r *NopRegistrationRepo) ActivateUser(token string) (*User, error)
- func (r *NopRegistrationRepo) CheckPassword(email string, password string) (ids.ID, error)
- func (r *NopRegistrationRepo) CreateInactiveUser(email string, password string) (string, error)
- func (r *NopRegistrationRepo) CreatePasswordResetRequest(email string) (*User, string, error)
- func (r *NopRegistrationRepo) DeleteUser(email string) error
- func (r *NopRegistrationRepo) GetUserByEmail(email string) *User
- func (r *NopRegistrationRepo) GetUserByID(userID ids.ID) *User
- func (r *NopRegistrationRepo) ListUsers(from ids.ID, limit int, backwards bool) ([]User, error)
- func (r *NopRegistrationRepo) ResetPassword(token string, password string) (*User, error)
- type RegistrationRepo
- type RepoSQLX
- func (r *RepoSQLX) ActivateUser(token string) (*User, error)
- func (r *RepoSQLX) CheckPassword(email string, password string) (ids.ID, error)
- func (r *RepoSQLX) CreateInactiveUser(email string, password string) (string, error)
- func (r *RepoSQLX) CreatePasswordResetRequest(email string) (*User, string, error)
- func (r *RepoSQLX) DeleteUser(email string) error
- func (r *RepoSQLX) GetUserByEmail(email string) *User
- func (r *RepoSQLX) GetUserByID(userID ids.ID) *User
- func (r *RepoSQLX) ListUsers(from ids.ID, limit int, backwards bool) ([]User, error)
- func (r *RepoSQLX) ResetPassword(token string, password string) (*User, error)
- type User
Constants ¶
const ( NotifRequestRegistration string = "users_requestregistration" NotifRequestPasswordReset string = "users_requestpasswordreset" )
Notification template names
const ( ErrUserExists = consterr.ConstErr("ErrUserExists") ErrNotFound = consterr.ConstErr("ErrNotFound") ErrConsumed = consterr.ConstErr("ErrConsumed") ErrExpired = consterr.ConstErr("ErrExpired") ErrNotificationFailed = consterr.ConstErr("ErrNotificationFailed") )
Error definitions for the user registration, login and reset password flows.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EmailRegistration ¶
type EmailRegistration struct {
// contains filtered or unexported fields
}
EmailRegistration is the controller to handle an email registration flow
func NewEmailRegistration ¶
func NewEmailRegistration( ins *obs.Insighter, composer notifications.Composer, mailSender mailer.Mailer, regRepo RegistrationRepo, hostInfo HostInfo) *EmailRegistration
NewEmailRegistration creates a new EmailRegistration controller
func (*EmailRegistration) Activate ¶
func (r *EmailRegistration) Activate(token string) error
Activate completes the activation of a registered user.
func (*EmailRegistration) GetUser ¶
func (r *EmailRegistration) GetUser(userID ids.ID) (*User, error)
GetUser returns a user given its ID
func (*EmailRegistration) Register ¶
func (r *EmailRegistration) Register(email string, password string) error
Register creates an inactive user, and send a notification (email), with the activation link.
func (*EmailRegistration) RequestResetPassword ¶
func (r *EmailRegistration) RequestResetPassword(email string) error
RequestResetPassword creates a temporal reset token and sends it to the user email, so it can reset the password.
func (*EmailRegistration) ResetPasswordWithToken ¶
func (r *EmailRegistration) ResetPasswordWithToken(token string, newPassword string) error
ResetPasswordWithToken sets a new password for a given user using a reset password token
type HostInfo ¶
type HostInfo struct { Scheme string // http or https Host string // includes port ActivationPath string // activation path where the handler has been installed ResetPasswordPath string // reset pass path where the handler has been installed }
HostInfo contains the required info to construct a URL to where a user can be redirected to use an activation token, or use a reset password token. This information might not be available if the request is proxied, so it can be configured at startup time.
type NopRegistrationRepo ¶
type NopRegistrationRepo struct { }
NopRegistrationRepo is an empty not working implementation of a RegistrationRepo
func (*NopRegistrationRepo) ActivateUser ¶
func (r *NopRegistrationRepo) ActivateUser(token string) (*User, error)
ActivateUser confirms an user email with its activation token.
func (*NopRegistrationRepo) CheckPassword ¶
CheckPassword return the user ID for a user from its email and password.
func (*NopRegistrationRepo) CreateInactiveUser ¶
func (r *NopRegistrationRepo) CreateInactiveUser( email string, password string) (string, error)
CreateInactiveUser return a token for the user to be used to confirm the account.
func (*NopRegistrationRepo) CreatePasswordResetRequest ¶
func (r *NopRegistrationRepo) CreatePasswordResetRequest(email string) (*User, string, error)
CreatePasswordResetRequest returns a token for password reset.
func (*NopRegistrationRepo) DeleteUser ¶
func (r *NopRegistrationRepo) DeleteUser(email string) error
DeleteUser deletes an existing user
func (*NopRegistrationRepo) GetUserByEmail ¶
func (r *NopRegistrationRepo) GetUserByEmail(email string) *User
GetUserByEmail returns the User for a given email, or nil if the email is not found in the data repo.
func (*NopRegistrationRepo) GetUserByID ¶
func (r *NopRegistrationRepo) GetUserByID(userID ids.ID) *User
GetUserByID returns a User for a given ID, or nil if there is no user for that ID.
func (*NopRegistrationRepo) ResetPassword ¶
func (r *NopRegistrationRepo) ResetPassword(token string, password string) (*User, error)
ResetPassword changes the pasword for the user associated with the given reset password token
type RegistrationRepo ¶
type RegistrationRepo interface { // GetUserByEmail returns the User for a given email, // or nil if the email is not found in the data repo. GetUserByEmail(email string) *User // GetUserByID returns a User for a given ID, or nil // if there is no user for that ID. GetUserByID(userID ids.ID) *User // CreateInactiveUser return a token for the user to be used // to confirm the account. CreateInactiveUser(email string, password string) (string, error) // ActivateUser confirms an user email with its activation token. ActivateUser(token string) (*User, error) // CreatePasswordResetRequest returns a token for password reset. CreatePasswordResetRequest(email string) (*User, string, error) // ResetPassword changes the pasword for the user associated with // the given reset password token ResetPassword(token string, password string) (*User, error) // CheckPassword return the user ID for a user from its email // and password. CheckPassword(email string, password string) (ids.ID, error) // DeleteUser deletes a created user DeleteUser(email string) error // ListUsers lists users with pagination ListUsers(from ids.ID, limit int, backwards bool) ([]User, error) }
RegistrationRepo defines the data access interface to implement an Email user registration (and reset password) workflow.
type RepoSQLX ¶
type RepoSQLX struct {
// contains filtered or unexported fields
}
RepoSQLX implemnte the RegistrationRepo interface with a SQL db.
func NewRepoSQLX ¶
NewRepoSQLX creates a new RepoSQLX
func (*RepoSQLX) ActivateUser ¶
ActivateUser confirms an user email with its activation token.
func (*RepoSQLX) CheckPassword ¶
CheckPassword return the user ID for a user from its email and password.
func (*RepoSQLX) CreateInactiveUser ¶
CreateInactiveUser return a token for the user to be used to confirm the account.
func (*RepoSQLX) CreatePasswordResetRequest ¶
CreatePasswordResetRequest returns a token for password reset.
func (*RepoSQLX) DeleteUser ¶
DeleteUser hard deletes a user (and all its related data will be deleted too)
func (*RepoSQLX) GetUserByEmail ¶
GetUserByEmail returns the User for a given email, or nil if the email is not found in the data repo.
func (*RepoSQLX) GetUserByID ¶
GetUserByID returns a User for a given ID, or nil if there is no user for that ID.