robfig/revel — pull request #293 by slogsdon (2013-09-05 05:26:56+00:00)
Title: Basic user authentication module

For #281. I tried to get this as simple and as decoupled as I could to allow for customization on the app side.

## Usage

package app

import (
"github.com/robfig/revel"
"github.com/slogsdon/blog/app/controllers"
"github.com/robfig/revel/modules/auth"
"github.com/slogsdon/acvte/modules/db"
)

func init() {
// Filters is the default set of global filters.
revel.Filters = []revel.Filter{
revel.PanicFilter,
revel.RouterFilter,
revel.FilterConfiguringFilter,
revel.ParamsFilter,
revel.SessionFilter,
revel.FlashFilter,
revel.ValidationFilter,
revel.I18nFilter,
revel.InterceptorFilter,
revel.ActionInvoker,
}
// tell auth module how to grab our user
auth.GetHash = func(username string) *auth.User {
user := new(auth.User)
db.Db.WhereEqual("username", username).Limit(1).Find(user)
return user
}
// the Admin controller requires authentication
revel.InterceptFunc(auth.CheckSession, revel.BEFORE, &controllers.Admin{})
}