Documentation ¶
Overview ¶
Package session provides functionality to manage user sessions and temporary storages. The web handlers will mainly interact with this package to retrieve information. If the required information is not found within the session storage, the database backend is being queried.
Index ¶
- type Controller
- func (controller *Controller) Authenticate(w http.ResponseWriter, r *http.Request, username string, password string) misc.AuthStatus
- func (controller *Controller) CreateNewUser(w http.ResponseWriter, r *http.Request, username string, email string, ...) error
- func (controller *Controller) DeleteAPIKey(w http.ResponseWriter, r *http.Request, apiKeyID string) error
- func (controller *Controller) DestroySession(w http.ResponseWriter, r *http.Request)
- func (controller *Controller) EncodeUserPermissions(r *http.Request, application *models.Application) (string, error)
- func (controller *Controller) GetCSRFToken(w http.ResponseWriter, r *http.Request) string
- func (controller *Controller) GetLoginRedirect(w http.ResponseWriter, r *http.Request) string
- func (controller *Controller) GetUser(r *http.Request) (*models.User, error)
- func (controller *Controller) GetUserAccounts(r *http.Request) ([]*models.Account, error)
- func (controller *Controller) GetUserCharacters(r *http.Request) ([]*models.Character, error)
- func (controller *Controller) HasUserRole(r *http.Request, role string) bool
- func (controller *Controller) IsLoggedIn(w http.ResponseWriter, r *http.Request) bool
- func (controller *Controller) ResendEmailVerification(w http.ResponseWriter, r *http.Request, username string, email string) error
- func (controller *Controller) SaveAPIKey(w http.ResponseWriter, r *http.Request, apiKeyID string, apivCode string) error
- func (controller *Controller) SendEmailVerification(w http.ResponseWriter, r *http.Request, username string, email string) error
- func (controller *Controller) SendPasswordReset(w http.ResponseWriter, r *http.Request, username string, email string) error
- func (controller *Controller) SetCSRFToken(w http.ResponseWriter, r *http.Request, token string) error
- func (controller *Controller) SetDefaultCharacter(w http.ResponseWriter, r *http.Request, characterID string) error
- func (controller *Controller) SetLoginRedirect(w http.ResponseWriter, r *http.Request, redirect string) error
- func (controller *Controller) SetUser(w http.ResponseWriter, r *http.Request, user *models.User) (*models.User, error)
- func (controller *Controller) UpdateUser(w http.ResponseWriter, r *http.Request, email string, oldPassword string, ...) (*models.User, error)
- func (controller *Controller) VerifyCSRFToken(w http.ResponseWriter, r *http.Request) bool
- func (controller *Controller) VerifyEmail(w http.ResponseWriter, r *http.Request, email string, verification string) error
- func (controller *Controller) VerifyPasswordReset(w http.ResponseWriter, r *http.Request, email string, username string, ...) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller provides functionality to handle sessions and cached values as well as retrieval of data
func SetupSessionController ¶
func SetupSessionController(conf *misc.Configuration, db database.Connection, mailer *mail.Controller) (*Controller, error)
SetupSessionController prepares the controller's session store and sets a default session lifespan
func (*Controller) Authenticate ¶
func (controller *Controller) Authenticate(w http.ResponseWriter, r *http.Request, username string, password string) misc.AuthStatus
Authenticate validates the given username and password against the database and creates a new session with timestamp if successful
func (*Controller) CreateNewUser ¶
func (controller *Controller) CreateNewUser(w http.ResponseWriter, r *http.Request, username string, email string, password string) error
CreateNewUser creates a new user in the database and saves the user's data in the current session
func (*Controller) DeleteAPIKey ¶
func (controller *Controller) DeleteAPIKey(w http.ResponseWriter, r *http.Request, apiKeyID string) error
DeleteAPIKey removes the given API key from the user and database
func (*Controller) DestroySession ¶
func (controller *Controller) DestroySession(w http.ResponseWriter, r *http.Request)
DestroySession destroys a user's session by setting a negative maximum age
func (*Controller) EncodeUserPermissions ¶
func (controller *Controller) EncodeUserPermissions(r *http.Request, application *models.Application) (string, error)
EncodeUserPermissions encodes the user's current permissions in a JSON struct and returns the encrypted payload
func (*Controller) GetCSRFToken ¶
func (controller *Controller) GetCSRFToken(w http.ResponseWriter, r *http.Request) string
GetCSRFToken retrieves the CSRF token for the current session or sets a new one if the session was newly created
func (*Controller) GetLoginRedirect ¶
func (controller *Controller) GetLoginRedirect(w http.ResponseWriter, r *http.Request) string
GetLoginRedirect retrieves the previously set path for redirection after login
func (*Controller) GetUserAccounts ¶
GetUserAccounts returns the accounts associated with the current user
func (*Controller) GetUserCharacters ¶
GetUserCharacters returns the characters associated with all accounts of the current user
func (*Controller) HasUserRole ¶
func (controller *Controller) HasUserRole(r *http.Request, role string) bool
HasUserRole checks whether the current user has a role with the given name granted
func (*Controller) IsLoggedIn ¶
func (controller *Controller) IsLoggedIn(w http.ResponseWriter, r *http.Request) bool
IsLoggedIn checks whether the user is currently logged in
func (*Controller) ResendEmailVerification ¶
func (controller *Controller) ResendEmailVerification(w http.ResponseWriter, r *http.Request, username string, email string) error
ResendEmailVerification resends an email with a verification link to the given address
func (*Controller) SaveAPIKey ¶
func (controller *Controller) SaveAPIKey(w http.ResponseWriter, r *http.Request, apiKeyID string, apivCode string) error
SaveAPIKey saves the given API key ID and verification code to the database and updated the user-object in the data session
func (*Controller) SendEmailVerification ¶
func (controller *Controller) SendEmailVerification(w http.ResponseWriter, r *http.Request, username string, email string) error
SendEmailVerification sends an email with a verification link to the given address
func (*Controller) SendPasswordReset ¶
func (controller *Controller) SendPasswordReset(w http.ResponseWriter, r *http.Request, username string, email string) error
SendPasswordReset sends an email with a verification link to reset a user's password to the given address
func (*Controller) SetCSRFToken ¶
func (controller *Controller) SetCSRFToken(w http.ResponseWriter, r *http.Request, token string) error
SetCSRFToken saves the given CSRF token for the current session
func (*Controller) SetDefaultCharacter ¶
func (controller *Controller) SetDefaultCharacter(w http.ResponseWriter, r *http.Request, characterID string) error
SetDefaultCharacter sets the default character for the current user
func (*Controller) SetLoginRedirect ¶
func (controller *Controller) SetLoginRedirect(w http.ResponseWriter, r *http.Request, redirect string) error
SetLoginRedirect saves the given path as a redirect after successful login
func (*Controller) SetUser ¶
func (controller *Controller) SetUser(w http.ResponseWriter, r *http.Request, user *models.User) (*models.User, error)
SetUser saves the given user object to the database and updates the data session reference
func (*Controller) UpdateUser ¶
func (controller *Controller) UpdateUser(w http.ResponseWriter, r *http.Request, email string, oldPassword string, newPassword string) (*models.User, error)
UpdateUser updates the current user's settings with the new given values
func (*Controller) VerifyCSRFToken ¶
func (controller *Controller) VerifyCSRFToken(w http.ResponseWriter, r *http.Request) bool
VerifyCSRFToken checks whether the provided CSRF token of the request and the stored session token match
func (*Controller) VerifyEmail ¶
func (controller *Controller) VerifyEmail(w http.ResponseWriter, r *http.Request, email string, verification string) error
VerifyEmail checks the given code and verifies the presented email address is correct
func (*Controller) VerifyPasswordReset ¶
func (controller *Controller) VerifyPasswordReset(w http.ResponseWriter, r *http.Request, email string, username string, verification string, password string) error
VerifyPasswordReset checks the given code and changes the user's password if the request is valid