Documentation ¶
Index ¶
- type AuthClient
- func (c *AuthClient) CheckPassword(password, hash string) error
- func (c *AuthClient) DeletePasswordTokens(ctx echo.Context, userID int) error
- func (c *AuthClient) GenerateEmailVerificationToken(email string) (string, error)
- func (c *AuthClient) GeneratePasswordResetToken(ctx echo.Context, userID int) (string, *ent.PasswordToken, error)
- func (c *AuthClient) GetAuthenticatedUser(ctx echo.Context) (*ent.User, error)
- func (c *AuthClient) GetAuthenticatedUserID(ctx echo.Context) (int, error)
- func (c *AuthClient) GetValidPasswordToken(ctx echo.Context, userID, tokenID int, token string) (*ent.PasswordToken, error)
- func (c *AuthClient) HashPassword(password string) (string, error)
- func (c *AuthClient) Login(ctx echo.Context, userID int) error
- func (c *AuthClient) Logout(ctx echo.Context) error
- func (c *AuthClient) RandomToken(length int) (string, error)
- func (c *AuthClient) ValidateEmailVerificationToken(token string) (string, error)
- type CacheClient
- type Container
- type InvalidPasswordTokenError
- type MailClient
- type NotAuthenticatedError
- type TaskClient
- type TemplateParsed
- type TemplateRenderer
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthClient ¶
type AuthClient struct {
// contains filtered or unexported fields
}
AuthClient is the client that handles authentication requests
func NewAuthClient ¶
func NewAuthClient(cfg *config.Config, orm *ent.Client) *AuthClient
NewAuthClient creates a new authentication client
func (*AuthClient) CheckPassword ¶
func (c *AuthClient) CheckPassword(password, hash string) error
CheckPassword check if a given password matches a given hash
func (*AuthClient) DeletePasswordTokens ¶
func (c *AuthClient) DeletePasswordTokens(ctx echo.Context, userID int) error
DeletePasswordTokens deletes all password tokens in the database for a belonging to a given user. This should be called after a successful password reset.
func (*AuthClient) GenerateEmailVerificationToken ¶
func (c *AuthClient) GenerateEmailVerificationToken(email string) (string, error)
GenerateEmailVerificationToken generates an email verification token for a given email address using JWT which is set to expire based on the duration stored in configuration
func (*AuthClient) GeneratePasswordResetToken ¶
func (c *AuthClient) GeneratePasswordResetToken(ctx echo.Context, userID int) (string, *ent.PasswordToken, error)
GeneratePasswordResetToken generates a password reset token for a given user. For security purposes, the token itself is not stored in the database but rather a hash of the token, exactly how passwords are handled. This method returns both the generated token as well as the token entity which only contains the hash.
func (*AuthClient) GetAuthenticatedUser ¶
func (c *AuthClient) GetAuthenticatedUser(ctx echo.Context) (*ent.User, error)
GetAuthenticatedUser returns the authenticated user if the user is logged in
func (*AuthClient) GetAuthenticatedUserID ¶
func (c *AuthClient) GetAuthenticatedUserID(ctx echo.Context) (int, error)
GetAuthenticatedUserID returns the authenticated user's ID, if the user is logged in
func (*AuthClient) GetValidPasswordToken ¶
func (c *AuthClient) GetValidPasswordToken(ctx echo.Context, userID, tokenID int, token string) (*ent.PasswordToken, error)
GetValidPasswordToken returns a valid, non-expired password token entity for a given user, token ID and token. Since the actual token is not stored in the database for security purposes, if a matching password token entity is found a hash of the provided token is compared with the hash stored in the database in order to validate.
func (*AuthClient) HashPassword ¶
func (c *AuthClient) HashPassword(password string) (string, error)
HashPassword returns a hash of a given password
func (*AuthClient) Login ¶
func (c *AuthClient) Login(ctx echo.Context, userID int) error
Login logs in a user of a given ID
func (*AuthClient) Logout ¶
func (c *AuthClient) Logout(ctx echo.Context) error
Logout logs the requesting user out
func (*AuthClient) RandomToken ¶
func (c *AuthClient) RandomToken(length int) (string, error)
RandomToken generates a random token string of a given length
func (*AuthClient) ValidateEmailVerificationToken ¶
func (c *AuthClient) ValidateEmailVerificationToken(token string) (string, error)
ValidateEmailVerificationToken validates an email verification token and returns the associated email address if the token is valid and has not expired
type CacheClient ¶
type CacheClient struct { // Client stores the client to the underlying cache service Client *redis.Client // contains filtered or unexported fields }
CacheClient is the client that allows you to interact with the cache
func NewCacheClient ¶
func NewCacheClient(cfg *config.Config) (*CacheClient, error)
NewCacheClient creates a new cache client
func (*CacheClient) Close ¶
func (c *CacheClient) Close() error
Close closes the connection to the cache
func (*CacheClient) Flush ¶
func (c *CacheClient) Flush() *cacheFlush
Flush creates a cache flush operation
type Container ¶
type Container struct { // Validator stores a validator Validator *Validator // Web stores the web framework Web *echo.Echo // Config stores the application configuration Config *config.Config // Cache contains the cache client Cache *CacheClient // Database stores the connection to the database Database *sql.DB // ORM stores a client to the ORM ORM *ent.Client // Mail stores an email sending client Mail *MailClient // Auth stores an authentication client Auth *AuthClient // TemplateRenderer stores a service to easily render and cache templates TemplateRenderer *TemplateRenderer // Tasks stores the task client Tasks *TaskClient }
Container contains all services used by the application and provides an easy way to handle dependency injection including within tests
func NewContainer ¶
func NewContainer() *Container
NewContainer creates and initializes a new Container
type InvalidPasswordTokenError ¶
type InvalidPasswordTokenError struct{}
InvalidPasswordTokenError is an error returned when an invalid token is provided
func (InvalidPasswordTokenError) Error ¶
func (e InvalidPasswordTokenError) Error() string
Error implements the error interface.
type MailClient ¶
type MailClient struct {
// contains filtered or unexported fields
}
MailClient provides a client for sending email This is purposely not completed because there are many different methods and services for sending email, many of which are very different. Choose what works best for you and populate the methods below
func NewMailClient ¶
func NewMailClient(cfg *config.Config, templates *TemplateRenderer) (*MailClient, error)
NewMailClient creates a new MailClient
type NotAuthenticatedError ¶
type NotAuthenticatedError struct{}
NotAuthenticatedError is an error returned when a user is not authenticated
func (NotAuthenticatedError) Error ¶
func (e NotAuthenticatedError) Error() string
Error implements the error interface.
type TaskClient ¶
type TaskClient struct {
// contains filtered or unexported fields
}
TaskClient is that client that allows you to queue or schedule task execution
func NewTaskClient ¶
func NewTaskClient(cfg *config.Config) *TaskClient
NewTaskClient creates a new task client
func (*TaskClient) Close ¶
func (t *TaskClient) Close() error
Close closes the connection to the task service
func (*TaskClient) New ¶
func (t *TaskClient) New(typ string) *task
New starts a task creation operation
func (*TaskClient) StartScheduler ¶
func (t *TaskClient) StartScheduler() error
StartScheduler starts the scheduler service which adds scheduled tasks to the queue This must be running in order to queue tasks set for periodic execution
type TemplateParsed ¶
type TemplateParsed struct { // Template is the parsed template Template *template.Template // contains filtered or unexported fields }
TemplateParsed is a wrapper around parsed templates which are stored in the TemplateRenderer cache
type TemplateRenderer ¶
type TemplateRenderer struct {
// contains filtered or unexported fields
}
TemplateRenderer provides a flexible and easy to use method of rendering simple templates or complex sets of templates while also providing caching and/or hot-reloading depending on your current environment
func NewTemplateRenderer ¶
func NewTemplateRenderer(cfg *config.Config) *TemplateRenderer
NewTemplateRenderer creates a new TemplateRenderer
func (*TemplateRenderer) Load ¶
func (t *TemplateRenderer) Load(group, key string) (*TemplateParsed, error)
Load loads a template from the cache
func (*TemplateRenderer) Parse ¶
func (t *TemplateRenderer) Parse() *templateBuilder
Parse creates a template build operation