本文整理匯總了Golang中web.Context.SetSecureCookie方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.SetSecureCookie方法的具體用法?Golang Context.SetSecureCookie怎麽用?Golang Context.SetSecureCookie使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類web.Context
的用法示例。
在下文中一共展示了Context.SetSecureCookie方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SigninPost
func SigninPost(ctx *web.Context, val string) string {
username := ctx.Params["Username"]
password := ctx.Params["Password"]
user := NewUser()
if db, err := util.GetDB(); err == nil {
if _, err = db.Retrieve("User_"+username, &user); err == nil {
if string(util.PasswordHash(password, user.Password.Version).Hash) == string(user.Password.Hash) {
num := rand.Int63()
key := username + "_" + strconv.Itoa64(num)
util.SetUserKey(key, username)
ctx.SetSecureCookie("UserKey", key, 6000000)
return util.MessagePage("You are now signed in.", ctx)
}
return util.MessagePage("Invalid username and password combination.", ctx)
}
return util.MessagePage("Error: Username may not exist.", ctx)
}
return util.MessagePage("Could not access the database.", ctx)
}
示例2: 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.String())
ctx.WriteString("<br><br><A href='/'>Index</a>")
return
}
ctx.WriteString(successpage)
return
}
}
示例3: SetCSS
func SetCSS(ctx *web.Context, css string) {
ctx.SetSecureCookie("css", css, 31556926)
}
示例4: get
func get(ctx *web.Context, val string) string {
switch val {
case "Account.html":
return users.AccountManagementGet(ctx, val)
case "Character.html":
return char.ViewCharacterGet(ctx, val)
case "EditCharacter.html":
return char.EditCharacterGet(ctx, val)
case "EditPost.html":
return posts.GetEditPost(ctx, val)
case "", "index.html", "index.htm":
db, err := util.GetDB()
if err != nil {
return util.MessagePage("Cannot access database.", ctx)
}
data, err := util.LoadTemplate("", "index.html", ctx)
if err != nil {
break
}
list := ""
if users, err := db.QueryIds("_design/users/_view/all", nil); err == nil {
list = "<ul>\n"
size := len(users)
for i := 0; i < size; i++ {
user := strings.SplitAfter(users[i], "User_", 2)[1]
list += "\t<il><a href=\"" + "view?user=" + user + "\">" + user + "</a></il><br>\n"
}
list += "</ul>"
}
data = strings.Replace(data, "{{UserList}}", list, -1)
if postList, err := db.QueryIds("_design/posts/_view/all", nil); err == nil {
list = "<ul>\n"
start := 10
if start >= len(postList) {
start = len(postList) - 1
}
for i := start; i > -1; i-- {
var post posts.Post
_, err := db.Retrieve(postList[i], &post)
if err == nil {
list += "\t<il>" + post.HTML(ctx) + "</il><br>\n"
}
}
list += "</ul>"
}
data = strings.Replace(data, "{{Posts}}", list, -1)
return data
case "signout.html":
if value, ok := util.ReadUserKey(ctx); ok {
ctx.SetSecureCookie("UserKey", value, -6000000)
util.DeleteUserKey(value)
}
if username, ok := util.ReadCookie("Username", ctx); ok {
ctx.SetSecureCookie("Username", username, -6000000)
}
return util.MessagePage("You're signed out.", ctx)
break
case "signin.html":
if util.SignedIn(ctx) {
return util.MessagePage("You're already signed in.", ctx)
}
retval, err := util.LoadTemplate("", val, ctx)
if err != nil {
break
}
return retval
case "view/", "view":
return posts.ViewPost(ctx, val)
default:
if strings.HasSuffix(val, ".html") {
retval, err := util.LoadTemplate("", val, ctx)
if err != nil {
break
}
return retval
}
retval, err := util.LoadFile(val)
if err != nil {
break
}
if strings.HasSuffix(val, ".html") {
} else if strings.HasSuffix(val, ".wgt") {
topbar, _ := util.TopBar(ctx)
retval = strings.Replace(retval, "{{TopBar}}", topbar, -1)
}
return retval
}
return util.FileNotFound
}