会话默认 1 天过期

This commit is contained in:
Liang Ding 2014-09-02 09:56:36 +08:00
parent c5d8056c81
commit a420cdf049
1 changed files with 5 additions and 2 deletions

View File

@ -21,12 +21,15 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
session, _ := user.Session.Get(r, "wide-session")
if session.IsNew {
// TODO: 以 admin 作为用户登录
// TODO: 写死以 admin 作为用户登录
name := conf.Wide.Users[0].Name
glog.Infof("[%s] logged in", name)
session.Values["username"] = name
session.Values["id"] = strconv.Itoa(rand.Int())
// 一天过期
session.Options.MaxAge = 60 * 60 * 24
glog.Infof("Created a session [%s] for user [%s]", session.Values["id"].(string), name)
}
session.Save(r, w)