當前位置: 首頁>>代碼示例>>Golang>>正文


Golang IUserState.AllUnconfirmedUsernames方法代碼示例

本文整理匯總了Golang中github.com/xyproto/pinterface.IUserState.AllUnconfirmedUsernames方法的典型用法代碼示例。如果您正苦於以下問題:Golang IUserState.AllUnconfirmedUsernames方法的具體用法?Golang IUserState.AllUnconfirmedUsernames怎麽用?Golang IUserState.AllUnconfirmedUsernames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/xyproto/pinterface.IUserState的用法示例。


在下文中一共展示了IUserState.AllUnconfirmedUsernames方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: GenerateRemoveUnconfirmedUser

// Remove an unconfirmed user
func GenerateRemoveUnconfirmedUser(state pinterface.IUserState) WebHandle {
    return func(ctx *web.Context, username string) string {
        if !state.AdminRights(ctx.Request) {
            return MessageOKback("Remove unconfirmed user", "Not logged in as Administrator")
        }

        if username == "" {
            return MessageOKback("Remove unconfirmed user", "Can't remove blank user.")
        }

        found := false
        usernames, err := state.AllUnconfirmedUsernames()
        if err == nil {
            for _, unconfirmedUsername := range usernames {
                if username == unconfirmedUsername {
                    found = true
                    break
                }
            }
        }

        if !found {
            return MessageOKback("Remove unconfirmed user", "Can't find "+username+" in the list of unconfirmed users.")
        }

        // Mark as confirmed
        state.RemoveUnconfirmed(username)

        return MessageOKurl("Remove unconfirmed user", "OK, removed "+username+" from the list of unconfirmed users.", "/admin")
    }
}
開發者ID:xyproto,項目名稱:siteengines,代碼行數:32,代碼來源:adminengine.go

示例2: GenerateConfirmUser

// Create a user by adding the username to the list of usernames
func GenerateConfirmUser(state pinterface.IUserState) WebHandle {
    return func(ctx *web.Context, val string) string {
        confirmationCode := val

        unconfirmedUsernames, err := state.AllUnconfirmedUsernames()
        if err != nil {
            return MessageOKurl("Confirmation", "All users are confirmed already.", "/register")
        }

        // Find the username by looking up the confirmationCode on unconfirmed users
        username := ""
        for _, aUsername := range unconfirmedUsernames {
            aConfirmationCode, err := state.ConfirmationCode(aUsername)
            if err != nil {
                // If the confirmation code can not be found, just skip this one
                continue
            }
            if confirmationCode == aConfirmationCode {
                // Found the right user
                username = aUsername
                break
            }
        }

        // Check that the user is there
        if username == "" {
            // Say "no longer" because we don't care about people that just try random confirmation links
            return MessageOKurl("Confirmation", "The confirmation link is no longer valid.", "/register")
        }
        hasUser := state.HasUser(username)
        if !hasUser {
            return MessageOKurl("Confirmation", "The user you wish to confirm does not exist anymore.", "/register")
        }

        // Remove from the list of unconfirmed usernames
        state.RemoveUnconfirmed(username)

        // Mark user as confirmed
        state.MarkConfirmed(username)

        return MessageOKurl("Confirmation", "Thank you "+username+", you can now log in.", "/login")
    }
}
開發者ID:xyproto,項目名稱:siteengines,代碼行數:44,代碼來源:userengine.go

示例3: GenerateAdminStatus

// TODO: Log and graph when people visit pages and when people contribute content
// This one is wrapped by ServeAdminPages
func GenerateAdminStatus(state pinterface.IUserState) SimpleContextHandle {
    return func(ctx *web.Context) string {
        if !state.AdminRights(ctx.Request) {
            return "<div class=\"no\">Not logged in as Administrator</div>"
        }

        // TODO: List all sorts of info, edit users, etc
        s := "<h2>Administrator Dashboard</h2>"

        s += "<strong>User table</strong><br />"
        s += "<table class=\"whitebg\">"
        s += "<tr>"
        s += "<th>Username</th><th>Confirmed</th><th>Logged in</th><th>Administrator</th><th>Admin toggle</th><th>Remove user</th><th>Email</th><th>Password hash</th>"
        s += "</tr>"
        usernames, err := state.AllUsernames()
        if err == nil {
            for rownr, username := range usernames {
                if rownr%2 == 0 {
                    s += "<tr class=\"even\">"
                } else {
                    s += "<tr class=\"odd\">"
                }
                s += "<td><a class=\"username\" href=\"/status/" + username + "\">" + username + "</a></td>"
                s += TableCell(state.IsConfirmed(username))
                s += TableCell(state.IsLoggedIn(username))
                s += TableCell(state.IsAdmin(username))
                s += "<td><a class=\"darkgrey\" href=\"/admintoggle/" + username + "\">admin toggle</a></td>"
                // TODO: Ask for confirmation first with a MessageOKurl("blabla", "blabla", "/actually/remove/stuff")
                s += "<td><a class=\"careful\" href=\"/remove/" + username + "\">remove</a></td>"
                email, err := state.Email(username)
                if err == nil {
                    // The cleanup happens at registration time, but it's ok with an extra cleanup
                    s += "<td>" + CleanUserInput(email) + "</td>"
                }
                passwordHash, err := state.PasswordHash(username)
                if err == nil {
                    if strings.HasPrefix(passwordHash, "abc123") {
                        s += "<td>" + passwordHash + " (<a href=\"/fixpassword/" + username + "\">fix</a>)</td>"
                    } else {
                        s += "<td>" + symbolhash.New(passwordHash, 16).String() + "</td>"
                    }
                }
                s += "</tr>"
            }
        }
        s += "</table>"
        s += "<br />"
        s += "<strong>Unconfirmed users</strong><br />"
        s += "<table>"
        s += "<tr>"
        s += "<th>Username</th><th>Confirmation link</th><th>Remove</th>"
        s += "</tr>"
        usernames, err = state.AllUnconfirmedUsernames()
        if err == nil {
            for _, username := range usernames {
                s += "<tr>"
                s += "<td><a class=\"username\" href=\"/status/" + username + "\">" + username + "</a></td>"
                confirmationCode, err := state.ConfirmationCode(username)
                if err != nil {
                    panic("ERROR: Could not get confirmation code")
                }
                s += "<td><a class=\"somewhatcareful\" href=\"/confirm/" + confirmationCode + "\">" + confirmationCode + "</a></td>"
                s += "<td><a class=\"careful\" href=\"/removeunconfirmed/" + username + "\">remove</a></td>"
                s += "</tr>"
            }
        }
        s += "</table>"
        return s
    }
}
開發者ID:xyproto,項目名稱:siteengines,代碼行數:72,代碼來源:adminengine.go

示例4: exportUserstate


//.........這裏部分代碼省略.........
        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 {
        username := L.ToString(1)
        email, err := userstate.Email(username)
        var result lua.LString
        if err != nil {
            result = lua.LString("")
        } else {
            result = lua.LString(email)
        }
        L.Push(result)
        return 1 // number of results
    }))
    // Get the password hash for a given username, or an empty string
    // Takes a username
    L.SetGlobal("PasswordHash", L.NewFunction(func(L *lua.LState) int {
        username := L.ToString(1)
        pw, err := userstate.PasswordHash(username)
        var result lua.LString
        if err != nil {
            result = lua.LString("")
        } else {
            result = lua.LString(pw)
        }
        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
    }))
開發者ID:sneakyweasel,項目名稱:algernon,代碼行數:67,代碼來源:userstate.go


注:本文中的github.com/xyproto/pinterface.IUserState.AllUnconfirmedUsernames方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。