本文整理汇总了Golang中github.com/astaxie/beego/context.Context.GetSecureCookie方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.GetSecureCookie方法的具体用法?Golang Context.GetSecureCookie怎么用?Golang Context.GetSecureCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/astaxie/beego/context.Context
的用法示例。
在下文中一共展示了Context.GetSecureCookie方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: LoginUserFromRememberCookie
func (this *BaseController) LoginUserFromRememberCookie(u *user.User, ctx *context.Context) (success bool) {
userName := ctx.GetCookie(setting.CookieUsername)
if len(userName) == 0 {
return false
}
defer func() {
if !success {
this.DeleteRememberCookie(ctx)
}
}()
u.Username = userName
if err := this.UserService.Read(u, "Username"); err != nil {
return false
}
secret := utils.EncodeMd5(u.PasswordSalt + u.Password)
value, _ := ctx.GetSecureCookie(secret, setting.CookieRememberName)
if value != userName {
return false
}
this.LoginUserRememberCookie(u, ctx, true)
return true
}
示例2: LoginUserFromRememberCookie
func LoginUserFromRememberCookie(user *models.User, ctx *context.Context) (success bool) {
userName := ctx.GetCookie(setting.CookieUserName)
if len(userName) == 0 {
return false
}
defer func() {
if !success {
DeleteRememberCookie(ctx)
}
}()
user.UserName = userName
if err := user.Read("UserName"); err != nil {
return false
}
secret := utils.EncodeMd5(user.Rands + user.Password)
value, _ := ctx.GetSecureCookie(secret, setting.CookieRememberName)
if value != userName {
return false
}
LoginUser(user, ctx, true)
return true
}
示例3: Render
// Render takes a Beego context, template name and a Context (map[string]interface{}).
// The template is parsed and cached, and gets executed into beegoCtx's ResponseWriter.
//
// Templates are looked up in `templates/` instead of Beego's default `views/` so that
// Beego doesn't attempt to load and parse our templates with `html/template`.
func Render(beegoCtx *context.Context, tmpl string, ctx Context) error {
template, err := p2.FromCache(path.Join(templateDir, tmpl))
if err != nil {
panic(err)
}
var pCtx p2.Context
if ctx == nil {
pCtx = p2.Context{}
} else {
pCtx = p2.Context(ctx)
}
if xsrf, ok := beegoCtx.GetSecureCookie(beego.BConfig.WebConfig.XSRFKey, "_xsrf"); ok {
pCtx["_xsrf"] = xsrf
}
// Only override "flash" if it hasn't already been set in Context
if _, ok := ctx["flash"]; !ok {
if ctx == nil {
ctx = Context{}
}
ctx["flash"] = readFlash(beegoCtx)
}
return template.ExecuteWriter(pCtx, beegoCtx.ResponseWriter)
}
示例4: Render
// Render takes a Beego context, template name and a Context (map[string]interface{}).
// The template is parsed and cached, and gets executed into beegoCtx's ResponseWriter.
//
// Templates are looked up in `templates/` instead of Beego's default `views/` so that
// Beego doesn't attempt to load and parse our templates with `html/template`.
func Render(beegoCtx *context.Context, tmpl string, ctx Context) {
mutex.RLock()
template, ok := templates[tmpl]
mutex.RUnlock()
if !ok || devMode {
var err error
// default ViewsPath
prefix := beego.AppConfig.String("ViewsPath")
if prefix == "" {
prefix = "views/"
}
template, err = p2.FromFile(prefix + tmpl)
if err != nil {
panic(err)
}
mutex.Lock()
templates[tmpl] = template
mutex.Unlock()
}
var pCtx p2.Context
if ctx == nil {
pCtx = p2.Context{}
} else {
pCtx = p2.Context(ctx)
}
if xsrf, ok := beegoCtx.GetSecureCookie(beego.XSRFKEY, "_xsrf"); ok {
pCtx["_xsrf"] = xsrf
}
// Only override "flash" if it hasn't already been set in Context
if _, ok := ctx["flash"]; !ok {
if ctx == nil {
ctx = Context{}
}
ctx["flash"] = readFlash(beegoCtx)
}
err := template.ExecuteWriter(pCtx, beegoCtx.ResponseWriter)
if err != nil {
panic(err)
}
}