本文整理汇总了Golang中github.com/zond/diplicity/common.HTTPContext.Session方法的典型用法代码示例。如果您正苦于以下问题:Golang HTTPContext.Session方法的具体用法?Golang HTTPContext.Session怎么用?Golang HTTPContext.Session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/zond/diplicity/common.HTTPContext
的用法示例。
在下文中一共展示了HTTPContext.Session方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Openid
func Openid(c *common.HTTPContext) (err error) {
redirect, email, ok, err := gopenid.VerifyAuth(c.Req())
if err != nil {
return
}
if ok {
email = strings.ToLower(email)
c.Session().Values[common.SessionEmail] = email
u := &User{Id: kol.Id(email)}
err = c.DB().Get(u)
if err == kol.NotFound {
err = nil
u.Email = email
u.Ranking = 1
}
if err == nil {
u.Language = common.GetLanguage(c.Req())
u.DiplicityHost = c.Req().Host
u.LastLoginAt = time.Now()
err = c.DB().Set(u)
}
} else {
delete(c.Session().Values, common.SessionEmail)
}
c.Close()
c.Resp().Header().Set("Location", redirect.String())
c.Resp().WriteHeader(302)
fmt.Fprintln(c.Resp(), redirect.String())
return
}
示例2: AdminBecome
func AdminBecome(c *common.HTTPContext) (err error) {
c.Session().Values[common.SessionEmail] = c.Req().FormValue("become")
c.Close()
c.Resp().Header().Set("Location", "/")
c.Resp().WriteHeader(302)
fmt.Fprintln(c.Resp(), "/")
return
}
示例3: Logout
func Logout(c *common.HTTPContext) (err error) {
delete(c.Session().Values, common.SessionEmail)
c.Close()
redirect := c.Req().FormValue("return_to")
if redirect == "" {
redirect = fmt.Sprintf("http://%v/", c.Req().Host)
}
c.Resp().Header().Set("Location", redirect)
c.Resp().WriteHeader(302)
fmt.Fprintln(c.Resp(), redirect)
return
}
示例4: Token
func Token(c *common.HTTPContext) (err error) {
if emailIf, found := c.Session().Values[common.SessionEmail]; found {
token := &gosubs.Token{
Principal: fmt.Sprint(emailIf),
Timeout: time.Now().Add(time.Second * 10),
}
if err = token.Encode(c.Secret()); err != nil {
return
}
err = c.RenderJSON(token)
} else {
err = c.RenderJSON(gosubs.Token{})
}
return
}