token

package
v0.0.0-...-53bd342 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActivationToken = "activation"
	RecoveryToken   = "recovery"
)

Variables

This section is empty.

Functions

func Create

func Create(ctx context.Context, db sqlx.ExtContext, token Token) error

Create inserts a new token.

func DeleteByUser

func DeleteByUser(ctx context.Context, db sqlx.ExtContext, userID string, scope string) error

DeleteByUser drops the token associated to the passed user with a specific scope, if any.

func HandleActivation

func HandleActivation(db *sqlx.DB, session *scs.SessionManager) web.Handler

HandleActivation validates the passed token and, if correct, it activates the user.

func HandleRecovery

func HandleRecovery(db *sqlx.DB) web.Handler

HandleRecovery validates the passed token and, if correct, changes the user's password with the one provided.

func HandleToken

func HandleToken(db *sqlx.DB, mailer Mailer, timeout time.Duration, bg *background.Background) web.Handler

HandleToken is used to send specific tokens to users via email. A valid scope must be provided by users, together with their email. It doesn't require a user to be logged in, because users who need tokens will probably not be able to login at all. This function leverages a rate limiter to avoid too many emails.

Types

type Mailer

type Mailer interface {
	SendActivationToken(token string, to string) error
	SendRecoveryToken(token string, to string) error
}

Mailer should be able to send emails to users for handling their activation and their password recovery.

type Token

type Token struct {
	Hash   []byte    `json:"-" db:"hash"`
	UserID string    `json:"userId" db:"user_id"`
	Expiry time.Time `json:"expiry" db:"expiry"`
	Scope  string    `json:"scope" db:"scope"`
}

Token models tokens to be sent to users for activation and recovery purposes.

func GenToken

func GenToken(userID string, ttl time.Duration, scope string) (string, Token, error)

GenToken generates a new random token for a user.

Jump to

Keyboard shortcuts

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