本文整理匯總了Golang中github.com/xyproto/pinterface.IUserState.SetCookieTimeout方法的典型用法代碼示例。如果您正苦於以下問題:Golang IUserState.SetCookieTimeout方法的具體用法?Golang IUserState.SetCookieTimeout怎麽用?Golang IUserState.SetCookieTimeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/xyproto/pinterface.IUserState
的用法示例。
在下文中一共展示了IUserState.SetCookieTimeout方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: exportUserstate
//.........這裏部分代碼省略.........
return 0 // number of results
}))
// Log in a user, both on the server and with a cookie.
// Returns true of successful.
// Takes a username
L.SetGlobal("Login", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
L.Push(lua.LBool(nil == userstate.Login(w, username)))
return 1 // number of results
}))
// Logs out a user, on the server (which is enough). Returns nothing
// Takes a username
L.SetGlobal("Logout", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
userstate.Logout(username)
return 0 // number of results
}))
// Get the current username, from the cookie
// Takes nothing
L.SetGlobal("Username", L.NewFunction(func(L *lua.LState) int {
username := userstate.Username(req)
L.Push(lua.LString(username))
return 1 // number of results
}))
// Get the current cookie timeout
// Takes a username
L.SetGlobal("CookieTimeout", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
L.Push(lua.LNumber(userstate.CookieTimeout(username)))
return 1 // number of results
}))
// Set the current cookie timeout
// Takes a timeout number, measured in seconds
L.SetGlobal("SetCookieTimeout", L.NewFunction(func(L *lua.LState) int {
timeout := int64(L.ToNumber(1))
userstate.SetCookieTimeout(timeout)
return 0 // number of results
}))
// Get the current password hashing algorithm (bcrypt, bcrypt+ or sha256)
// Takes nothing
L.SetGlobal("PasswordAlgo", L.NewFunction(func(L *lua.LState) int {
algorithm := userstate.PasswordAlgo()
L.Push(lua.LString(algorithm))
return 1 // number of results
}))
// Set the current password hashing algorithm (bcrypt, bcrypt+ or sha256)
// Takes a string
L.SetGlobal("SetPasswordAlgo", L.NewFunction(func(L *lua.LState) int {
algorithm := L.ToString(1)
userstate.SetPasswordAlgo(algorithm)
return 0 // number of results
}))
// Hash the password, returns a string
// Takes a username and password (username can be used for salting)
L.SetGlobal("HashPassword", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
password := L.ToString(2)
L.Push(lua.LString(userstate.HashPassword(username, password)))
return 1 // number of results
}))
// Check if a given username and password is correct, returns a bool
// Takes a username and password
L.SetGlobal("CorrectPassword", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
password := L.ToString(2)
L.Push(lua.LBool(userstate.CorrectPassword(username, password)))