web

package
v0.0.0-...-c6bd9c1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2015 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package web contains all functionality required by the web handlers and application. All HTTP handlers, routers and routes as well as static assets will be stored here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssetChecksums

type AssetChecksums struct {
	// Checksums represents a map of checksums, indexed by the file's name
	Checksums map[string]string
}

AssetChecksums stores MD5 checksums for all JS and CSS assets the web app uses

func SetupAssetChecksums

func SetupAssetChecksums() (*AssetChecksums, error)

SetupAssetChecksums prepares the checksums of all files by walking the appropriate directories and calculating MD5 values

func (*AssetChecksums) CalculateFileChecksum

func (checksums *AssetChecksums) CalculateFileChecksum(path string, info os.FileInfo, err error) error

CalculateFileChecksum reads the content of a file and calculates its MD5 checksum

type Controller

type Controller struct {
	Config    *misc.Configuration
	Database  database.Connection
	Session   *session.Controller
	Templates *Templates
	Checksums *AssetChecksums
	RedisPool *redis.Pool
	// contains filtered or unexported fields
}

Controller provides functionality for handling web requests and accessing session and backend data

func SetupController

func SetupController(config *misc.Configuration, db database.Connection, sessions *session.Controller, templates *Templates, checksums *AssetChecksums) *Controller

SetupController prepares the web controller and initialises the router and handled routes

func (*Controller) AddGroupRoleToGroup

func (controller *Controller) AddGroupRoleToGroup(groupID int64, roleID int64, roleGranted bool) error

AddGroupRoleToGroup adds the role with the given ID to the group

func (*Controller) AddGroupToUser

func (controller *Controller) AddGroupToUser(userID int64, groupID int64) error

AddGroupToUser adds the group with the given ID to the user

func (*Controller) AddUserRoleToUser

func (controller *Controller) AddUserRoleToUser(userID int64, roleID int64, roleGranted bool) error

AddUserRoleToUser adds the role with the given ID to the user

func (*Controller) AdminGroupDetailsGetHandler

func (controller *Controller) AdminGroupDetailsGetHandler(w http.ResponseWriter, r *http.Request)

AdminGroupDetailsGetHandler allows administrators to view details of a group

func (*Controller) AdminGroupsGetHandler

func (controller *Controller) AdminGroupsGetHandler(w http.ResponseWriter, r *http.Request)

AdminGroupsGetHandler allows administrators to modify groups and assign new roles

func (*Controller) AdminGroupsPostHandler

func (controller *Controller) AdminGroupsPostHandler(w http.ResponseWriter, r *http.Request)

AdminGroupsPostHandler allows creation of new groups and adds roles to existing ones

func (*Controller) AdminGroupsPutHandler

func (controller *Controller) AdminGroupsPutHandler(w http.ResponseWriter, r *http.Request)

AdminGroupsPutHandler updates a groups and removes existing roles

func (*Controller) AdminRolesGetHandler

func (controller *Controller) AdminRolesGetHandler(w http.ResponseWriter, r *http.Request)

AdminRolesGetHandler allows administrators to modify roles

func (*Controller) AdminRolesPostHandler

func (controller *Controller) AdminRolesPostHandler(w http.ResponseWriter, r *http.Request)

AdminRolesPostHandler allows creation of new roles

func (*Controller) AdminRolesPutHandler

func (controller *Controller) AdminRolesPutHandler(w http.ResponseWriter, r *http.Request)

AdminRolesPutHandler allows removal of existing roles

func (*Controller) AdminUserDetailsGetHandler

func (controller *Controller) AdminUserDetailsGetHandler(w http.ResponseWriter, r *http.Request)

AdminUserDetailsGetHandler allows administrators to view details of a user

func (*Controller) AdminUsersGetHandler

func (controller *Controller) AdminUsersGetHandler(w http.ResponseWriter, r *http.Request)

AdminUsersGetHandler allows administrators to modify users and assign new groups and roles

func (*Controller) AdminUsersPostHandler

func (controller *Controller) AdminUsersPostHandler(w http.ResponseWriter, r *http.Request)

AdminUsersPostHandler updates the user and adds new roles and groups

func (*Controller) AdminUsersPutHandler

func (controller *Controller) AdminUsersPutHandler(w http.ResponseWriter, r *http.Request)

AdminUsersPutHandler updates the user and removes roles and groups

func (*Controller) AuthorizeGetHandler

func (controller *Controller) AuthorizeGetHandler(w http.ResponseWriter, r *http.Request)

AuthorizeGetHandler provides an endpoint for applications to request an authorization token

func (*Controller) CreateNewGroup

func (controller *Controller) CreateNewGroup(groupName string) (*models.Group, error)

CreateNewGroup creates a new group, saves it to the database and returns the updated model

func (*Controller) CreateNewRole

func (controller *Controller) CreateNewRole(roleName string, roleLocked bool) (*models.Role, error)

CreateNewRole creates a new role, saves it to the database and returns the updated model

func (*Controller) EncryptUserPermissions

func (controller *Controller) EncryptUserPermissions(userID int64, appID int64) (string, error)

EncryptUserPermissions retrieves the data for the given user and app and encrypted the user's permissions using the app secret

func (*Controller) GetAuthorizationToken

func (controller *Controller) GetAuthorizationToken(userID int64, appID int64) (string, error)

GetAuthorizationToken tries to retrieve a temporary authorization for the given user and app

func (*Controller) HandleRequests

func (controller *Controller) HandleRequests()

HandleRequests starts the blocking call to handle web requests

func (*Controller) IndexGetHandler

func (controller *Controller) IndexGetHandler(w http.ResponseWriter, r *http.Request)

IndexGetHandler displays the index page of the web app

func (*Controller) LegalGetHandler

func (controller *Controller) LegalGetHandler(w http.ResponseWriter, r *http.Request)

LegalGetHandler displays some legal information as well as copyright disclaimers and contact info

func (*Controller) LoadAllGroups

func (controller *Controller) LoadAllGroups() ([]*models.Group, error)

LoadAllGroups retrieves all currently existing groups

func (*Controller) LoadAllRoles

func (controller *Controller) LoadAllRoles() ([]*models.Role, error)

LoadAllRoles retrieves all currently existing roles

func (*Controller) LoadAllUsers

func (controller *Controller) LoadAllUsers() ([]*models.User, error)

LoadAllUsers retrieves all currently registered users

func (*Controller) LoadAvailableGroupRolesForGroup

func (controller *Controller) LoadAvailableGroupRolesForGroup(groupID int64) ([]*models.Role, error)

LoadAvailableGroupRolesForGroup retrieves all roles the group can be assigned

func (*Controller) LoadAvailableGroupsForUser

func (controller *Controller) LoadAvailableGroupsForUser(userID int64) ([]*models.Group, error)

LoadAvailableGroupsForUser retrieves all groups the user can be added to

func (*Controller) LoadAvailableUserRolesForUser

func (controller *Controller) LoadAvailableUserRolesForUser(userID int64) ([]*models.Role, error)

LoadAvailableUserRolesForUser retrieves all roles the user can be assigned

func (*Controller) LoadGroupFromGroupID

func (controller *Controller) LoadGroupFromGroupID(groupID int64) (*models.Group, error)

LoadGroupFromGroupID retrieves a group with the given group ID

func (*Controller) LoadUserFromUserID

func (controller *Controller) LoadUserFromUserID(userID int64) (*models.User, error)

LoadUserFromUserID retrieves a user with the given user ID

func (*Controller) LoginGetHandler

func (controller *Controller) LoginGetHandler(w http.ResponseWriter, r *http.Request)

LoginGetHandler displays the login page of the web app

func (*Controller) LoginPostHandler

func (controller *Controller) LoginPostHandler(w http.ResponseWriter, r *http.Request)

LoginPostHandler handles submitted data from the login page and verifies the user's credentials

func (*Controller) LoginRegisterGetHandler

func (controller *Controller) LoginRegisterGetHandler(w http.ResponseWriter, r *http.Request)

LoginRegisterGetHandler displays the registration page of the web app

func (*Controller) LoginRegisterPostHandler

func (controller *Controller) LoginRegisterPostHandler(w http.ResponseWriter, r *http.Request)

LoginRegisterPostHandler handles submitted data from the registration page and creates a new user

func (*Controller) LoginResetGetHandler

func (controller *Controller) LoginResetGetHandler(w http.ResponseWriter, r *http.Request)

LoginResetGetHandler allows the user to reset their password

func (*Controller) LoginResetPostHandler

func (controller *Controller) LoginResetPostHandler(w http.ResponseWriter, r *http.Request)

LoginResetPostHandler allows the user to reset their password

func (*Controller) LoginResetVerifyGetHandler

func (controller *Controller) LoginResetVerifyGetHandler(w http.ResponseWriter, r *http.Request)

LoginResetVerifyGetHandler provides the user with a form to reset their password

func (*Controller) LoginResetVerifyPostHandler

func (controller *Controller) LoginResetVerifyPostHandler(w http.ResponseWriter, r *http.Request)

LoginResetVerifyPostHandler updates the user's password as per choice

func (*Controller) LoginVerifyGetHandler

func (controller *Controller) LoginVerifyGetHandler(w http.ResponseWriter, r *http.Request)

LoginVerifyGetHandler handles the verification of email addresses as produced by the registration system

func (*Controller) LoginVerifyResendGetHandler

func (controller *Controller) LoginVerifyResendGetHandler(w http.ResponseWriter, r *http.Request)

LoginVerifyResendGetHandler allows the user to request re-sending the verification code to his email address

func (*Controller) LoginVerifyResendPostHandler

func (controller *Controller) LoginVerifyResendPostHandler(w http.ResponseWriter, r *http.Request)

LoginVerifyResendPostHandler resends the activiation email as requested by the user

func (*Controller) LogoutGetHandler

func (controller *Controller) LogoutGetHandler(w http.ResponseWriter, r *http.Request)

LogoutGetHandler destroys the user's current session and thus logs him out

func (*Controller) PermissionsGetHandler

func (controller *Controller) PermissionsGetHandler(w http.ResponseWriter, r *http.Request)

PermissionsGetHandler provides an endpoint for applications to receive a user's permissions

func (*Controller) QueryCorporationName

func (controller *Controller) QueryCorporationName(corporationID int64) (string, error)

QueryCorporationName queries the database for the name of the corporation with the given ID

func (*Controller) SendJSONResponse

func (controller *Controller) SendJSONResponse(w http.ResponseWriter, r *http.Request, response map[string]interface{})

SendJSONResponse sends the given reponse data as a JSON encoded string to the client

func (*Controller) SendRawError

func (controller *Controller) SendRawError(w http.ResponseWriter, statusCode int, err error)

SendRawError sends a raw error messages with the given HTTP status code to the client

func (*Controller) SendRedirect

func (controller *Controller) SendRedirect(w http.ResponseWriter, r *http.Request, redirect string, status int)

SendRedirect sends a redirect to the given URL using the provided status code

func (*Controller) SendResponse

func (controller *Controller) SendResponse(w http.ResponseWriter, r *http.Request, template string, response map[string]interface{})

SendResponse sends a response to the client by executing the templates and appending the asset checksum data

func (*Controller) ServeHTTP

func (controller *Controller) ServeHTTP(inner http.Handler, name string) http.Handler

ServeHTTP acts as a middleware between parsed requests, logging the requests and replacing the remote address with the proxy-value if needed

func (*Controller) SetAuthorizationToken

func (controller *Controller) SetAuthorizationToken(userID int64, appID int64, token string) error

SetAuthorizationToken stores a temporary authorization token for the given user and app

func (*Controller) SettingsAccountsGetHandler

func (controller *Controller) SettingsAccountsGetHandler(w http.ResponseWriter, r *http.Request)

SettingsAccountsGetHandler displays the currently associated accounts and lets the user modify them

func (*Controller) SettingsAccountsPutHandler

func (controller *Controller) SettingsAccountsPutHandler(w http.ResponseWriter, r *http.Request)

SettingsAccountsPutHandler handles AJAX requests used to update the user's accounts settings

func (*Controller) SettingsApplicationsGetHandler

func (controller *Controller) SettingsApplicationsGetHandler(w http.ResponseWriter, r *http.Request)

SettingsApplicationsGetHandler provides the user with an overview of their registered applications

func (*Controller) SettingsApplicationsPostHandler

func (controller *Controller) SettingsApplicationsPostHandler(w http.ResponseWriter, r *http.Request)

SettingsApplicationsPostHandler allows the creation of new applications

func (*Controller) SettingsApplicationsPutHandler

func (controller *Controller) SettingsApplicationsPutHandler(w http.ResponseWriter, r *http.Request)

SettingsApplicationsPutHandler allows updating applications as well as removing them

func (*Controller) SettingsCharactersGetHandler

func (controller *Controller) SettingsCharactersGetHandler(w http.ResponseWriter, r *http.Request)

SettingsCharactersGetHandler allows the user to manage the EVE Online characters associated with his account

func (*Controller) SettingsCharactersPutHandler

func (controller *Controller) SettingsCharactersPutHandler(w http.ResponseWriter, r *http.Request)

SettingsCharactersPutHandler handles AJAX requests used to update the user's character settings

func (*Controller) SettingsGetHandler

func (controller *Controller) SettingsGetHandler(w http.ResponseWriter, r *http.Request)

SettingsGetHandler provides the user with some basic settings for his account

func (*Controller) SettingsPutHandler

func (controller *Controller) SettingsPutHandler(w http.ResponseWriter, r *http.Request)

SettingsPutHandler handles AJAX requests used to update the user's settings

func (*Controller) VerifyApplication

func (controller *Controller) VerifyApplication(appID string, callback string, auth string) (*models.Application, error)

VerifyApplication verifies the application to be authorized to perform requests to the auth backend

type Route

type Route struct {
	// Name represents a name for the web route
	Name string
	// Methods contains all HTTP methods available to access this route
	Methods []string
	// Pattern defines the URL pattern used to match this route
	Pattern string
	// HandlerFunc represents the web handler function to call for this route
	HandlerFunc http.HandlerFunc
}

Route stores information about a web route being handled

func SetupRoutes

func SetupRoutes(controller *Controller) []Route

SetupRoutes initialises all used web routes and returns them for the router

type Templates

type Templates struct {
	// contains filtered or unexported fields
}

Templates stores the parsed HTTP templates used by the web app

func SetupTemplates

func SetupTemplates(db database.Connection, sess *session.Controller) *Templates

SetupTemplates parses the HTTP templates from disk and stores them for later usage

func (*Templates) ExecuteTemplates

func (templates *Templates) ExecuteTemplates(w http.ResponseWriter, r *http.Request, template string, response map[string]interface{}) error

ExecuteTemplates performs all replacement in the HTTP templates and sends the response to the client

func (*Templates) HasUserRole

func (templates *Templates) HasUserRole(r *http.Request, role string) bool

HasUserRole checks whether the current user has a role with the given name granted

func (*Templates) IsResultNil

func (templates *Templates) IsResultNil(result interface{}) bool

IsResultNil checks whether the given result is nil

func (*Templates) QueryCorporationName

func (templates *Templates) QueryCorporationName(corporationID int64) string

QueryCorporationName queries the database for the name of the corporation with the given ID

func (*Templates) ReloadTemplates

func (templates *Templates) ReloadTemplates()

ReloadTemplates re-reads the HTTP templates from disk and refreshes the output

func (*Templates) TemplateFunctions

func (templates *Templates) TemplateFunctions(r *http.Request) template.FuncMap

TemplateFunctions prepares a map of functions to be used within templates

Jump to

Keyboard shortcuts

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