controller

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SESSION_COOKIE = "session_id"
)

Variables

This section is empty.

Functions

func AddRouters

func AddRouters(router *mux.Router)

AddRouters adds the router handler functions

func AllGrids added in v0.6.0

func AllGrids(userid int) []string

AllGrids returns the list of all grid file names for this user.

func CheckForExistingUser added in v0.7.0

func CheckForExistingUser(u User) (bool, error)

CheckForExistingUser looks up a username in the users table and returns true if it exists

func Connect added in v0.6.0

func Connect() (*sql.DB, error)

Connect opens a connection to the gocrossword database.

func CountGridsWithName added in v0.6.0

func CountGridsWithName(gridname string) int

CountGridsWithName gets the number of grids in the table with a specified name. Broken out from the main function for ease of unit testing.

func GetDocumentRoot

func GetDocumentRoot() string

GetDocumentRoot returns the absolute path to the $PROJECT_ROOT/view/static directory.

func GetUserID added in v0.7.0

func GetUserID(u User) (int, error)

GetUserID returns the userid assigned for this username.

func GridChanged

func GridChanged(w http.ResponseWriter, r *http.Request)

GridChanged is a REST method to determine whether the grid has changed

func GridChooser added in v0.6.0

func GridChooser(w http.ResponseWriter, r *http.Request)

GridChooser displays a list of grids to choose from.

func GridClick

func GridClick(w http.ResponseWriter, r *http.Request)

GridClick handles adding or deleting a black cell on the grid.

func GridDelete added in v0.6.0

func GridDelete(w http.ResponseWriter, r *http.Request)

GridDelete delete the specified grid and redirects to main screen.

func GridLoad added in v0.6.0

func GridLoad(gridname string, userid int) string

GridLoad gets the jsonstr for the specified gridname from the database.

func GridNameUsed added in v0.6.0

func GridNameUsed(w http.ResponseWriter, r *http.Request)

GridNameUsed is a REST method to determine whether a grid by the specified name already exists in the database.

func GridNew

func GridNew(w http.ResponseWriter, r *http.Request)

GridNew creates a new grid and redirects to GridScreen

func GridOpen added in v0.6.0

func GridOpen(w http.ResponseWriter, r *http.Request)

GridOpen starts a new grid editing session with the specified grid name.

func GridPreview added in v0.6.0

func GridPreview(w http.ResponseWriter, r *http.Request)

GridPreview is a REST method that return the scaled SVG for the specified grid name.

func GridRedo

func GridRedo(w http.ResponseWriter, r *http.Request)

GridRedo redoes the latest add or remove black cell.

func GridSave added in v0.6.0

func GridSave(w http.ResponseWriter, r *http.Request)

GridSave adds or updates the database entry for this grid.

func GridSaveAs added in v0.6.0

func GridSaveAs(w http.ResponseWriter, r *http.Request)

GridSaveAs saves the grid under a new name

func GridSaveCommon added in v0.6.0

func GridSaveCommon(w http.ResponseWriter, r *http.Request, gridname string)

GridSaveCommon is a method used by both grid_save and grid_save_as.

func GridScreen

func GridScreen(w http.ResponseWriter, r *http.Request)

GridScreen displays the grid screen

func GridStatistics

func GridStatistics(w http.ResponseWriter, r *http.Request)

GridStatistics runs the statistics methods and returns the results

func GridUndo

func GridUndo(w http.ResponseWriter, r *http.Request)

GridUndo undoes the latest add or remove black cell.

func HandleLogin added in v0.7.0

func HandleLogin(w http.ResponseWriter, r *http.Request)

HandleLogin is a POST method that accepts a username and password, verifies them against the database, and redirects to the main page if they are valid.

func HandleRegister added in v0.7.0

func HandleRegister(w http.ResponseWriter, r *http.Request)

HandleRegister is a POST method that creates a new user in the database.

func HandleRequests

func HandleRequests()

HandleRequests registers all the routers and starts the server.

func MainPage

func MainPage(w http.ResponseWriter, r *http.Request)

MainPage shows the main page of the application

func Register added in v0.7.0

func Register(w http.ResponseWriter, r *http.Request)

Register displays the registration screen

func UpdateDatabase added in v0.7.0

func UpdateDatabase(u User) error

UpdateDatabase adds a user to the database. If the user already exists, updates the record. Returns any error message.

func ValidateForm added in v0.7.0

func ValidateForm(u User) error

ValidateForm checks for required fields

Types

type Enabled

type Enabled struct {
	GridNew      bool
	GridOpen     bool
	GridSave     bool
	GridSaveAs   bool
	GridClose    bool
	GridStats    bool
	GridEditGrid bool
	GridUndo     bool
	GridRedo     bool
	GridDelete   bool
}

type Session

type Session struct {
	USERID           int
	USERNAME         string
	EXPIRES          time.Time
	ENABLED          Enabled
	UISTATE          UIState
	MESSAGES         []string
	GRID             string
	GRID_INITIAL_SHA string
	GRIDNAME         string
	N                int
	BOXSIZE          int
	SVGSTR           string
	STATS            *model.Statistics
	GRIDLIST         []string
	NEXTURL          string
}

Session holds the values for an HTTP session

func GetSession added in v0.7.0

func GetSession(w http.ResponseWriter, r *http.Request) (*Session, bool)

GetSession gets the session ID from the request cookie and looks up the correct session in the session map. If there is no cookie, or if the session does not exist or has expired, a 401 HTTP error is written to the response and the ok boolean is set to false.

func NewSession added in v0.7.0

func NewSession() *Session

NewSession creates a new session and returns a pointer to it.

type UIState

type UIState byte

UIState reflects the state of the UI, and which menu items to enable.

const (
	MAIN_MENU            UIState = iota // 0
	GRID_CHOOSER                        // 1
	PROMPT_FOR_GRID_SIZE                // 2
	EDITING_GRID                        // 3
	EDITING_PUZZLE                      // 4
	EDITING_WORD                        // 5
)

func (UIState) GetEnabled

func (st UIState) GetEnabled() Enabled

GetEnabled returns a map of menu item names to whether to enable them.

func (UIState) String

func (st UIState) String() string

String returns a string representation of the byte value of this state.

type User added in v0.7.0

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

Jump to

Keyboard shortcuts

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