Beispiel #1
0
func init() {
	ModuleLog = log.New("Module")
	DBLog = log.New("Database")
	Register(users.Module)

	config.Register("DEFAULT", "port", "8080", "The port on which to run the webserver")
	config.Register("DEFAULT", "assetDirectory", "assets", `
		The directory to find static assets and templates. Can be an absolute path or
		relative to the executable.
		`)

	config.Register("Database", "username", "", "The database username")
	config.Register("Database", "password", "", "The database password")
	config.Register("Database", "database", "", "The name of the database to use")
	config.Register("Database", "host", "localhost", "The database host")
}
Beispiel #2
0
package users

import (
	"fmt"
	"github.com/YouthBuild-USA/godata/log"
	"github.com/YouthBuild-USA/godata/templates"
	"github.com/YouthBuild-USA/godata/web"
	"net/http"
)

var userLog = log.New("User")

var (
	loginFormTemplate = templates.OneColumn().Add("users/loginForm")
	userTemplate      = templates.OneColumn().Add("users/user")
)

func init() {
}

func (module userModule) AddRoutes(handleAdder web.HandlerAdder) error {

	handleAdder("/login", loginForm).Methods("GET")
	handleAdder("/login", login).Methods("POST")
	handleAdder("/user", userPage).Methods("GET")
	handleAdder("/logout", logout).Methods("GET")
	return nil
}

func loginForm(w http.ResponseWriter, r *http.Request) error {
	user, _ := CurrentUser(r)
Beispiel #3
0
	"fmt"
	"github.com/YouthBuild-USA/godata/log"
	"github.com/goods/httpbuf"
	"github.com/gorilla/context"
	"github.com/gorilla/mux"
	"github.com/gorilla/sessions"
	"io"
	"net/http"
)

var store sessions.Store

type HandlerAdder func(string, Handle) *mux.Route
type Handle func(http.ResponseWriter, *http.Request) error

var requestLog = log.New("request")

type Handler interface {
	ServeHTTP(w http.ResponseWriter, r *http.Request) error
}

type RequestInitializer func(*http.Request) error

var initializers = make([]RequestInitializer, 0, 0)

func AddRequestInitializer(initializer RequestInitializer) {
	initializers = append(initializers, initializer)
}

func (h Handle) ServeHTTP(w http.ResponseWriter, r *http.Request) {