func LoginRequired(r render.Render, user User, req *http.Request) {
	if user.IsAuthenticated() == false {
		path := fmt.Sprintf("%s?%s=%s", RedirectUrl, RedirectParam, req.URL.Path)
		r.Redirect(path, 302)
	}
}
LoginRequired verifies that the current user is authenticated. Any routes that
require a login should have this handler placed in the flow. If the user is not
authenticated, they will be redirected to /login with the "next" get parameter
set to the attempted URL.
package sessionauth
import (
	"fmt"
	"github.com/go-martini/martini"
	"github.com/martini-contrib/render"
	"github.com/martini-contrib/sessions"
	"log"
	"net/http"
)
var (
	RedirectUrl string = "/login"
	RedirectParam string = "next"
	SessionKey string = "AUTHUNIQUEID"
)
type User interface {
	IsAuthenticated() bool
	Login()
	Logout()
	UniqueId() interface{}
	GetById(id interface{}) error
}
func SessionUser(newUser func() User) martini.Handler {
	return func(s sessions.Session, c martini.Context, l *log.Logger) {
		userId := s.Get(SessionKey)
		user := newUser()
		if userId != nil {
			err := user.GetById(userId)
			if err != nil {
				l.Printf("Login Error: %v\n", err)
			} else {
				user.Login()
			}
		}
		c.MapTo(user, (*User)(nil))
	}
}
func AuthenticateSession(s sessions.Session, user User) error {
	user.Login()
	return UpdateUser(s, user)
}
func Logout(s sessions.Session, user User) {
	user.Logout()
	s.Delete(SessionKey)
}