本文整理匯總了Golang中github.com/MessageDream/salvation/modules/middleware.Context.GetSuperSecureCookie方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.GetSuperSecureCookie方法的具體用法?Golang Context.GetSuperSecureCookie怎麽用?Golang Context.GetSuperSecureCookie使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/MessageDream/salvation/modules/middleware.Context
的用法示例。
在下文中一共展示了Context.GetSuperSecureCookie方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SignIn
func SignIn(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("sign_in")
if _, ok := ctx.Session.Get("socialId").(int64); ok {
ctx.Data["IsSocialLogin"] = true
ctx.HTML(200, SIGNIN)
return
}
if setting.OauthService != nil {
ctx.Data["OauthEnabled"] = true
ctx.Data["OauthService"] = setting.OauthService
}
// Check auto-login.
uname := ctx.GetCookie(setting.CookieUserName)
if len(uname) == 0 {
ctx.HTML(200, SIGNIN)
return
}
isSucceed := false
defer func() {
if !isSucceed {
log.Trace("auto-login cookie cleared: %s", uname)
ctx.SetCookie(setting.CookieUserName, "", -1)
ctx.SetCookie(setting.CookieRememberName, "", -1)
return
}
}()
u, err := models.GetUserByName(uname)
if err != nil {
if err != models.ErrUserNotExist {
ctx.Handle(500, "GetUserByName", err)
}
return
}
if val, _ := ctx.GetSuperSecureCookie(
base.EncodeMd5(u.Rands+u.Passwd), setting.CookieRememberName); val != u.Name {
ctx.HTML(200, SIGNIN)
return
}
isSucceed = true
ctx.Session.Set("uid", u.Id)
ctx.Session.Set("uname", u.Name)
if redirectTo, _ := url.QueryUnescape(ctx.GetCookie("redirect_to")); len(redirectTo) > 0 {
ctx.SetCookie("redirect_to", "", -1)
ctx.Redirect(redirectTo)
return
}
ctx.Redirect("/")
}