本文整理汇总了Golang中github.com/xyproto/pinterface.IUserState.AddUnconfirmed方法的典型用法代码示例。如果您正苦于以下问题:Golang IUserState.AddUnconfirmed方法的具体用法?Golang IUserState.AddUnconfirmed怎么用?Golang IUserState.AddUnconfirmed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/xyproto/pinterface.IUserState
的用法示例。
在下文中一共展示了IUserState.AddUnconfirmed方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: exportUserstate
//.........这里部分代码省略.........
}
L.Push(result)
return 1 // number of results
}))
// Get all unconfirmed usernames
// Takes no arguments
L.SetGlobal("AllUnconfirmedUsernames", L.NewFunction(func(L *lua.LState) int {
usernames, err := userstate.AllUnconfirmedUsernames()
var table *lua.LTable
if err != nil {
table = L.NewTable()
} else {
table = strings2table(L, usernames)
}
L.Push(table)
return 1 // number of results
}))
// Get a confirmation code that can be given to a user, or an empty string
// Takes a username
L.SetGlobal("ConfirmationCode", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
pw, err := userstate.ConfirmationCode(username)
var result lua.LString
if err != nil {
result = lua.LString("")
} else {
result = lua.LString(pw)
}
L.Push(result)
return 1 // number of results
}))
// Add a user to the list of unconfirmed users, returns nothing
// Takes a username and a confirmation code
L.SetGlobal("AddUnconfirmed", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
confirmationCode := L.ToString(2)
userstate.AddUnconfirmed(username, confirmationCode)
return 0 // number of results
}))
// Remove a user from the list of unconfirmed users, returns nothing
// Takes a username
L.SetGlobal("RemoveUnconfirmed", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
userstate.RemoveUnconfirmed(username)
return 0 // number of results
}))
// Mark a user as confirmed, returns nothing
// Takes a username
L.SetGlobal("MarkConfirmed", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
userstate.MarkConfirmed(username)
return 0 // number of results
}))
// Removes a user, returns nothing
// Takes a username
L.SetGlobal("RemoveUser", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
userstate.RemoveUser(username)
return 0 // number of results
}))
// Make a user an admin, returns nothing
// Takes a username
L.SetGlobal("SetAdminStatus", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
userstate.SetAdminStatus(username)
return 0 // number of results
示例2: GenerateRegisterUser
// Register a new user, site is ie. "archlinux.no"
func GenerateRegisterUser(state pinterface.IUserState, site string) WebHandle {
return func(ctx *web.Context, val string) string {
// Password checks
password1, found := ctx.Params["password1"]
if password1 == "" || !found {
return MessageOKback("Register", "Can't register without a password.")
}
password2, found := ctx.Params["password2"]
if password2 == "" || !found {
return MessageOKback("Register", "Please confirm the password by typing it in twice.")
}
if password1 != password2 {
return MessageOKback("Register", "The password and confirmation password must be equal.")
}
// Email checks
email, found := ctx.Params["email"]
if !found {
return MessageOKback("Register", "Can't register without an email address.")
}
// must have @ and ., but no " "
if !strings.Contains(email, "@") || !strings.Contains(email, ".") || strings.Contains(email, " ") {
return MessageOKback("Register", "Please use a valid email address.")
}
if email != CleanUserInput(email) {
return MessageOKback("Register", "The sanitized email differs from the given email.")
}
// Username checks
username := val
if username == "" {
return MessageOKback("Register", "Can't register without a username.")
}
if state.HasUser(username) {
return MessageOKback("Register", "That user already exists, try another username.")
}
// Only some letters are allowed in the username
err := permissions.ValidUsernamePassword(username, password1)
if err != nil {
return MessageOKback("Register", err.Error())
}
adminuser := false
// A special case
if username == "admin" {
// The first user to register with the username "admin" becomes the administrator
adminuser = true
}
// Register the user
state.AddUser(username, password1, email)
// Mark user as administrator if that is the case
if adminuser {
// Set admin status
state.SetAdminStatus(username)
}
confirmationCode, err := state.GenerateUniqueConfirmationCode()
if err != nil {
panic(err.Error())
}
// If registering the admin user (first user on the system), don't send a confirmation email, just register it
if adminuser {
// Mark user as confirmed
state.MarkConfirmed(username)
// Redirect
return MessageOKurl("Registration complete", "Thanks for registering, the admin user has been created.", "/login")
}
// Send confirmation email
ConfirmationEmail(site, "https://"+site+"/confirm/"+confirmationCode, username, email)
// Register the need to be confirmed
state.AddUnconfirmed(username, confirmationCode)
// Redirect
return MessageOKurl("Registration complete", "Thanks for registering, the confirmation e-mail has been sent.", "/login")
}
}