求助:beego GetActiveSession 获取当前活跃的 session 用户

du86796922 · · 1595 次点击
**自己给自己顶!**
#1
更多评论
是否应该提供下设置和获取 session 的关键代码?
#2
session配置 sscfg := &session.ManagerConfig{ CookieName: "gosessionid", EnableSetCookie: true, Gclifetime: 3600, Maxlifetime: 3600, Secure: false, SessionIDHashFunc: "sha1", SessionIDHashKey: "sessionidkey", CookieLifeTime: 0, ProviderConfig: "", } 存session数据 func (self *LogonController) Post() { defer self.ServeJson() self.Data["host"] = self.Ctx.Request.Host userId := self.Ctx.Request.Form.Get("username") pwd := self.Ctx.Request.Form.Get("pwd") userBasic :=self.Ctx.Request.Form.Get("userbasic") log.Oper(userId, "Logon") sess := self.StartSession() sess.Set("username", userId)//存userID sess.Set("userBash64",userBasic)//存userbash64 if self.IsDefaultUser(userId) { self.Data["json"] = self.validateDefaultUser(userId, pwd) } else { self.Data["json"] = self.validateDomainUser(userId, pwd) } self.WirteLinkAdd(self.Ctx.Request) } 取session数据 func(this *ControllerCommon) GetJiraProjectList() string { userBasic :=this.GetCurSessionUserBasic() client := &http.Client{} reqest, _ := http.NewRequest("GET", "http://jira.zte.com.cn/rest/api/2/project/", nil) reqest.Header.Set("Authorization",userBasic) reqest.Header.Set("Content-Type","application/json;charset=UTF-8") response,err := client.Do(reqest) if err != nil { log.Error("NewRequest Get jiraprojectList fail :", err.Error()) return "" } message, _ := ioutil.ReadAll(response.Body) return string(message) } //获取当前活跃用户数 func(this *ControllerCommon)GetSessionNum() int { return beego.GlobalSessions.GetActiveSession() }
#3