本文整理汇总了Golang中github.com/xyproto/pinterface.IUserState.ClearCookie方法的典型用法代码示例。如果您正苦于以下问题:Golang IUserState.ClearCookie方法的具体用法?Golang IUserState.ClearCookie怎么用?Golang IUserState.ClearCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/xyproto/pinterface.IUserState
的用法示例。
在下文中一共展示了IUserState.ClearCookie方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: exportUserstate
// Make functions related to users and permissions available to Lua scripts
func exportUserstate(w http.ResponseWriter, req *http.Request, L *lua.LState, userstate pinterface.IUserState) {
// Check if the current user has "user rights", returns bool
// Takes no arguments
L.SetGlobal("UserRights", L.NewFunction(func(L *lua.LState) int {
L.Push(lua.LBool(userstate.UserRights(req)))
return 1 // number of results
}))
// Check if the given username exists, returns bool
// Takes a username
L.SetGlobal("HasUser", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
L.Push(lua.LBool(userstate.HasUser(username)))
return 1 // number of results
}))
// Get the value from the given boolean field, returns bool
// Takes a username and fieldname
L.SetGlobal("BooleanField", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
fieldname := L.ToString(2)
L.Push(lua.LBool(userstate.BooleanField(username, fieldname)))
return 1 // number of results
}))
// Save a value as a boolean field, returns nothing
// Takes a username, fieldname and boolean value
L.SetGlobal("SetBooleanField", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
fieldname := L.ToString(2)
value := L.ToBool(3)
userstate.SetBooleanField(username, fieldname, value)
return 0 // number of results
}))
// Check if a given username is confirmed, returns a bool
// Takes a username
L.SetGlobal("IsConfirmed", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
L.Push(lua.LBool(userstate.IsConfirmed(username)))
return 1 // number of results
}))
// Check if a given username is logged in, returns a bool
// Takes a username
L.SetGlobal("IsLoggedIn", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
L.Push(lua.LBool(userstate.IsLoggedIn(username)))
return 1 // number of results
}))
// Check if the current user has "admin rights", returns a bool
// Takes no arguments.
L.SetGlobal("AdminRights", L.NewFunction(func(L *lua.LState) int {
L.Push(lua.LBool(userstate.AdminRights(req)))
return 1 // number of results
}))
// Check if a given username is an admin, returns a bool
// Takes a username
L.SetGlobal("IsAdmin", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
L.Push(lua.LBool(userstate.IsAdmin(username)))
return 1 // number of results
}))
// Get the username stored in a cookie, or an empty string
// Takes no arguments
L.SetGlobal("UsernameCookie", L.NewFunction(func(L *lua.LState) int {
username, err := userstate.UsernameCookie(req)
var result lua.LString
if err != nil {
result = lua.LString("")
} else {
result = lua.LString(username)
}
L.Push(result)
return 1 // number of results
}))
// Store the username in a cookie, returns true if successful
// Takes a username
L.SetGlobal("SetUsernameCookie", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
L.Push(lua.LBool(nil == userstate.SetUsernameCookie(w, username)))
return 1 // number of results
}))
// Clear the user cookie. The result depends on the browser.
L.SetGlobal("ClearCookie", L.NewFunction(func(L *lua.LState) int {
userstate.ClearCookie(w)
return 0 // number of results
}))
// Get the username stored in a cookie, or an empty string
// Takes no arguments
L.SetGlobal("AllUsernames", L.NewFunction(func(L *lua.LState) int {
usernames, err := userstate.AllUsernames()
var table *lua.LTable
if err != nil {
table = L.NewTable()
} else {
table = strings2table(L, usernames)
}
L.Push(table)
return 1 // number of results
}))
// Get the email for a given username, or an empty string
// Takes a username
L.SetGlobal("Email", L.NewFunction(func(L *lua.LState) int {
//.........这里部分代码省略.........