Documentation ¶
Index ¶
- Constants
- Variables
- type Config
- type Flash
- type Service
- type ServiceOpt
- type Session
- func (s Session) ClearFlashes(w http.ResponseWriter, r *http.Request)
- func (s Session) Delete(w http.ResponseWriter, r *http.Request) error
- func (s Session) DeregisterUser(w http.ResponseWriter, r *http.Request) error
- func (s Session) Flashes(w http.ResponseWriter, r *http.Request) []Flash
- func (s Session) Get(key any) any
- func (s Session) RegisterUser(w http.ResponseWriter, r *http.Request, ID uint) error
- func (s Session) ResetExpiry(w http.ResponseWriter, r *http.Request) error
- func (s Session) Save(w http.ResponseWriter, r *http.Request) error
- func (s Session) Set(w http.ResponseWriter, r *http.Request, key trails.Key, val any) error
- func (s Session) SetFlash(w http.ResponseWriter, r *http.Request, flash Flash) error
- func (s Session) UserID() (uint, error)
- type SessionStorer
- type Stub
Constants ¶
const ( // Default Flash Type FlashError = "error" FlashInfo = "info" FlashSuccess = "success" FlashWarning = "warning" // Default Flash Msg BadCredsMsg = "Hmm... check those credentials." BadInputMsg = "Hmm... check your form, something isn't correct." DefaultErrMsg = "Uh oh! We've run into an issue." EmailNotValidMsg = "It looks like your primary email has not been validated. Please complete this process and try again." LinkSentMsg = "Email sent! Please open the link in your email to reset your password." NoAccessMsg = "Oops, sending you back somewhere safe." )
Variables ¶
var ( ErrNotValid = errors.New("not valid") ErrNoUser = errors.New("no user") )
var ContactUsErr = DefaultErrMsg + " Please contact us at %s if the issue persists."
Functions ¶
This section is empty.
Types ¶
type Config ¶ added in v0.6.1
type Config struct { Env trails.Environment // The number of seconds a session is valid. MaxAge int // The name sessions are stored under. // Also used as the name of the cookie when WithCookie is used. SessionName string // Hex-encoded key AuthKey string // Hex-encoded key EncryptKey string }
A Config provides the required values
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
A Service wraps a gorilla.Store to manage constructing a new one and accessing the sessions contained in it.
Service implements SessionStorer.
func NewStoreService ¶
NewStoreService initiates a data store for user web sessions with the provided config.
type ServiceOpt ¶
A ServiceOpt configures the provided *Service, returning an error if unable to.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
A Session provides all functionality for managing a fully featured session.
Its functionality is implemented by lightly wrapping a gorilla.Session.
func (Session) ClearFlashes ¶
func (s Session) ClearFlashes(w http.ResponseWriter, r *http.Request)
ClearFlashes removes all Flashes from the Session.
func (Session) DeregisterUser ¶
DeregisterUser removes the User from the session.
func (Session) RegisterUser ¶
RegisterUserSession stores the user's ID in the session.
func (Session) ResetExpiry ¶
ResetExpiry resets the expiration of the session by saving it.
func (Session) UserID ¶
UserID gets the user ID out of the session. A user ID should be present in a session if the user is successfully authenticated. If no user ID can be found, this ErrNoUser is returned. This ought to only happen when a user is going through an authentication workflow or hitting unauthenticated pages.
If the value returned from the session is not a uint, ErrNotValid is returned and represents a programming error.
type SessionStorer ¶
The SessionStorer defines methods for interacting with a Sessionable for the given *http.Request.