Documentation ¶
Overview ¶
Package confirmcode implements confirmation of user registration via e-mail with copy-paste codes.
Index ¶
- Constants
- Variables
- func GenerateConfirmCreds(length int) (code string, hash string, err error)
- func Middleware(ab *authboss.Authboss) func(http.Handler) http.Handler
- type Config
- type Confirm
- func (c *Confirm) Get(w http.ResponseWriter, r *http.Request) error
- func (c *Confirm) Post(w http.ResponseWriter, r *http.Request) error
- func (c *Confirm) PreventAuth(w http.ResponseWriter, r *http.Request, handled bool) (bool, error)
- func (c *Confirm) SendConfirmEmail(ctx context.Context, to, code string)
- func (c *Confirm) StartConfirmation(ctx context.Context, user User, sendEmail bool) error
- func (c *Confirm) StartConfirmationWeb(w http.ResponseWriter, r *http.Request, handled bool) (bool, error)
- type Storer
- type User
Constants ¶
const ( // PageConfirm is only really used for the BodyReader PageConfirm = "confirm" // EmailConfirmHTML is the name of the html template for e-mails EmailConfirmHTML = "confirm_html" // EmailConfirmTxt is the name of the text template for e-mails EmailConfirmTxt = "confirm_txt" // DataConfirmCode is the name of the template field for the user's code DataConfirmCode = "code" )
Variables ¶
var ( // ErrRetryLimit is returned when the user has requested a resend but // it is too soon. ErrRetryLimit = errors.New("retry limit reached please wait") )
Functions ¶
func GenerateConfirmCreds ¶
GenerateConfirmCreds creates a code of given length and returns the sha512 of that code as well for storage in a database.
func Middleware ¶
Middleware ensures that a user is confirmed, or else it will intercept the request and send them to the confirm page, this will load the user if he's not been loaded yet from the session.
Panics if the user was not able to be loaded in order to allow a panic handler to show a nice error page, also panics if it failed to redirect for whatever reason.
Types ¶
type Config ¶
type Config struct { // Add Dashes to codes after each N characters AddDashes int // Length of the token excluding automatically added dashes. Length int // Period between attempts AttemptPeriod time.Duration // CodeExpiry is the duration before a code expires. CodeExpiry time.Duration // PathOK is where to redirect when the user is confirmed PathOK string // PathNotOK is the url back to the confirm page PathNotOK string }
Config for the confirm module
type Confirm ¶
type Confirm struct { *authboss.Authboss // contains filtered or unexported fields }
Confirm module
func (*Confirm) PreventAuth ¶
PreventAuth stops the EventAuth from succeeding when a user is not confirmed This relies on the fact that the context holds the user at this point in time loaded by the auth module (or something else).
func (*Confirm) SendConfirmEmail ¶
SendConfirmEmail sends a confirmation e-mail to a user
func (*Confirm) StartConfirmation ¶
StartConfirmation begins confirmation on a user by setting them to require confirmation via a created token, and optionally sending them an e-mail.
func (*Confirm) StartConfirmationWeb ¶
func (c *Confirm) StartConfirmationWeb(w http.ResponseWriter, r *http.Request, handled bool) (bool, error)
StartConfirmationWeb hijacks a request and forces a user to be confirmed first it's assumed that the current user is loaded into the request context.
type Storer ¶
type Storer interface { authboss.ServerStorer // LoadByConfirmCode finds a user by his confirm selector field // and should return ErrUserNotFound if that user cannot be found. LoadByConfirmCode(ctx context.Context, code string) (User, error) }
Storer for confirm module, allows looking up a user by a code
func EnsureCanConfirm ¶
func EnsureCanConfirm(storer authboss.ServerStorer) Storer
EnsureCanConfirm makes sure the server storer supports confirm-lookup operations
type User ¶
type User interface { authboss.User GetEmail() (email string) GetConfirmed() (confirmed bool) GetConfirmCode() (code string) GetConfirmExpiration() (date time.Time) GetConfirmLastAttempt() (date time.Time) PutEmail(email string) PutConfirmed(confirmed bool) PutConfirmCode(verifier string) PutConfirmExpiration(date time.Time) PutConfirmLastAttempt(date time.Time) }
User can be in a state of confirmed or not.
func MustHaveConfirmFields ¶
func MustHaveConfirmFields(u authboss.User) User
MustHaveConfirmFields ensures the user has confirm-related fields