本文整理匯總了Golang中github.com/hoisie/web.Context.SetSecureCookie方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.SetSecureCookie方法的具體用法?Golang Context.SetSecureCookie怎麽用?Golang Context.SetSecureCookie使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hoisie/web.Context
的用法示例。
在下文中一共展示了Context.SetSecureCookie方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: login
// Checks login
func login(wr *web.Context) {
// Login user
if wr.Params["username"] != "" && wr.Params["password"] != "" {
username := wr.Params["username"]
password := wr.Params["password"]
loginName := jailgo.Authenticate(username, password)
// If you have a valid user
if loginName != nil {
log.Println("DEBUG Controller *Username type: ", loginName.User)
wr.SetSecureCookie("user", loginName.User, 20000) //15 minutes for session
wr.Redirect(303, "/jail?check=ok")
// If you haven't
} else {
wr.Redirect(303, "/jail?check=err")
}
// Maybe you're going out
} else if wr.Params["logout"] != "" {
wr.SetSecureCookie("user", "off", 0)
wr.Redirect(303, "/jail?check=out")
} else {
// If you wrote nothing
log.Println("DEBUG Controller user: ", wr.Params["username"])
log.Println("DEBUG Controller pass: ", wr.Params["password"])
wr.Redirect(303, "/jail?check=err")
}
}
示例2: update
func update(ctx *web.Context) {
if ctx.Params["submit"] == "Delete" {
ctx.SetCookie(web.NewCookie(cookieName, "", -1))
} else {
ctx.SetSecureCookie(cookieName, ctx.Params["cookie"], 0)
}
ctx.Redirect(301, "/")
}
示例3: Login
func (sm *SessionManager) Login(ctx *web.Context, user, pass string) bool {
sm.removeExpired()
if sm.LoggedIn(ctx) {
return true
}
if pHash, ok := sm.users[user]; ok && bcrypt.CompareHashAndPassword([]byte(pHash), []byte(pass)) == nil {
s := session{makeSessionId(), time.Now().Add(2 * time.Minute)}
sm.sessions = append(sm.sessions, s)
ctx.SetSecureCookie("TDB-user", s.id, 120)
return true
}
return false
}
示例4: adminPost
func adminPost(ctx *web.Context) {
level := ctx.Params["godlevel"]
godlevel := godHash(level)
if ctx.Params["what"] == "login" {
if godlevel == admin_pass {
ctx.SetSecureCookie("godlevel", level, 3600)
ctx.Redirect(301, "/admin")
return
}
ctx.SetSecureCookie("godlevel", "fefe", 3600)
ctx.Redirect(301, "/")
return
}
if !checkGodLevel(ctx) {
ctx.SetSecureCookie("godlevel", "fefe", 3600)
ctx.Redirect(301, "/")
return
}
if ctx.Params["what"] == "post" {
err := createNewPost(ctx.Params["content"])
if err != nil {
ctx.WriteString("couldn't post: " + err.Error())
ctx.WriteString("<br><br><A href='/'>Index</a>")
return
}
ctx.WriteString(successpage)
return
}
}
示例5: SetCSS
func SetCSS(ctx *web.Context, css string) {
ctx.SetSecureCookie("css", css, 31556926)
}