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


Golang pinterface.IUserState類代碼示例

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


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

示例1: exportCodeLibrary

// Make functions related to building a library of Lua code available
func exportCodeLibrary(L *lua.LState, userstate pinterface.IUserState) {
	creator := userstate.Creator()

	// Register the Library class and the methods that belongs with it.
	mt := L.NewTypeMetatable(lLibraryClass)
	mt.RawSetH(lua.LString("__index"), mt)
	L.SetFuncs(mt, libMethods)

	// The constructor for new Libraries takes only an optional id
	L.SetGlobal("CodeLib", L.NewFunction(func(L *lua.LState) int {
		// Check if the optional argument is given
		id := defaultID
		if L.GetTop() == 1 {
			id = L.ToString(1)
		}

		// Create a new Library in Lua
		userdata, err := newCodeLibrary(L, creator, id)
		if err != nil {
			L.Push(lua.LNil)
			L.Push(lua.LString(err.Error()))
			L.Push(lua.LNumber(1))
			return 3 // Number of returned values
		}

		// Return the hash map object
		L.Push(userdata)
		return 1 // number of results
	}))

}
開發者ID:sneakyweasel,項目名稱:algernon,代碼行數:32,代碼來源:codelib.go

示例2: NewUsersHole

func NewUsersHole(state pinterface.IUserState) *UsersHole {
	uh := new(UsersHole)
	creator := state.Creator()
	uh.state = state
	uh.holes, _ = creator.NewHashMap("holes")
	uh.seq, _ = creator.NewKeyValue("seq")
	uh.servers = make(map[string]*HoleApp)
	return uh
}
開發者ID:ultimate010,項目名稱:holehub,代碼行數:9,代碼來源:holehubd.go

示例3: NewWikiEngine

func NewWikiEngine(state pinterface.IUserState) *WikiEngine {
	pool := state.Pool()

	wikiState := new(WikiState)
	wikiState.pages = simpleredis.NewHashMap(pool, "pages")
	wikiState.pages.SelectDatabase(state.DatabaseIndex())
	wikiState.pool = pool

	return &WikiEngine{state, wikiState}
}
開發者ID:xyproto,項目名稱:siteengines,代碼行數:10,代碼來源:wikiengine.go

示例4: NewTimeTableEngine

func NewTimeTableEngine(state pinterface.IUserState) *TimeTableEngine {
	pool := state.Pool()
	timeTableState := new(TimeTableState)

	timeTableState.plans = simpleredis.NewHashMap(pool, "plans")
	timeTableState.plans.SelectDatabase(state.DatabaseIndex())

	timeTableState.pool = pool
	return &TimeTableEngine{state, timeTableState}
}
開發者ID:xyproto,項目名稱:siteengines,代碼行數:10,代碼來源:timetableengine.go

示例5: NewIPEngine

func NewIPEngine(state pinterface.IUserState) *IPEngine {

	// Create a RedisList for storing IP adresses
	ips := simpleredis.NewList(state.Pool(), "IPs")

	ipEngine := new(IPEngine)
	ipEngine.data = ips
	ipEngine.state = state

	return ipEngine
}
開發者ID:xyproto,項目名稱:siteengines,代碼行數:11,代碼來源:ipengine.go

示例6: GenerateAllUsernames

func GenerateAllUsernames(state pinterface.IUserState) SimpleContextHandle {
	return func(ctx *web.Context) string {
		if !state.AdminRights(ctx.Request) {
			return MessageOKback("List usernames", "Not logged in as Administrator")
		}
		s := ""
		usernames, err := state.AllUsernames()
		if err == nil {
			for _, username := range usernames {
				s += username + "<br />"
			}
		}
		return MessageOKback("Usernames", s)
	}
}
開發者ID:xyproto,項目名稱:siteengines,代碼行數:15,代碼來源:adminengine.go

示例7: NewChatEngine

func NewChatEngine(userState pinterface.IUserState) *ChatEngine {
	pool := userState.Pool()
	dbindex := userState.DatabaseIndex()

	chatState := new(ChatState)

	chatState.active = pinterface.NewSet(pool, "active")
	chatState.active.SelectDatabase(dbindex)

	chatState.said = pinterface.NewList(pool, "said")
	chatState.said.SelectDatabase(dbindex)

	chatState.userInfo = pinterface.NewHashMap(pool, "userInfo") // lastSeen.time is an encoded timestamp for when the user was last seen chatting
	chatState.userInfo.SelectDatabase(dbindex)

	chatState.pool = pool
	return &ChatEngine{userState, chatState}
}
開發者ID:xyproto,項目名稱:siteengines,代碼行數:18,代碼來源:chatengine.go

示例8: 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

示例9: 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

示例10: GenerateLoginUser

// Log in a user by changing the loggedin value
func GenerateLoginUser(state pinterface.IUserState) WebHandle {
	return func(ctx *web.Context, val string) string {
		// Fetch password from ctx
		password, found := ctx.Params["password"]
		if !found {
			return MessageOKback("Login", "Can't log in without a password.")
		}
		username := val
		if username == "" {
			return MessageOKback("Login", "Can't log in with a blank username.")
		}
		if !state.HasUser(username) {
			return MessageOKback("Login", "User "+username+" does not exist, could not log in.")
		}
		if !state.IsConfirmed(username) {
			return MessageOKback("Login", "The email for "+username+" has not been confirmed, check your email and follow the link.")
		}
		if !state.CorrectPassword(username, password) {
			return MessageOKback("Login", "Wrong password.")
		}

		// Log in the user by changing the database and setting a secure cookie
		state.SetLoggedIn(username)

		// Also store the username in the browser
		state.SetUsernameCookie(ctx.ResponseWriter, username)

		// TODO: Use a welcoming messageOK where the user can see when he/she last logged in and from which host

		if username == "admin" {
			ctx.SetHeader("Refresh", "0; url=/admin", true)
		} else {
			// TODO: Redirect to the page the user was at before logging in
			ctx.SetHeader("Refresh", "0; url=/", true)
		}

		return ""
	}
}
開發者ID:xyproto,項目名稱:siteengines,代碼行數:40,代碼來源:userengine.go

示例11: exportList

// Make functions related to HTTP requests and responses available to Lua scripts
func exportList(L *lua.LState, userstate pinterface.IUserState) {
	creator := userstate.Creator()

	// Register the list class and the methods that belongs with it.
	mt := L.NewTypeMetatable(lListClass)
	mt.RawSetH(lua.LString("__index"), mt)
	L.SetFuncs(mt, listMethods)

	// The constructor for new lists takes a name and an optional redis db index
	L.SetGlobal("List", L.NewFunction(func(L *lua.LState) int {
		name := L.ToString(1)

		// Check if the optional argument is given
		if L.GetTop() == 2 {
			localDBIndex := L.ToInt(2)

			// Set the DB index, if possible
			switch rh := creator.(type) {
			case pinterface.IRedisCreator:
				rh.SelectDatabase(localDBIndex)
			}
		}

		// Create a new list in Lua
		userdata, err := newList(L, creator, name)
		if err != nil {
			L.Push(lua.LNil)
			L.Push(lua.LString(err.Error()))
			L.Push(lua.LNumber(1))
			return 3 // Number of returned values
		}

		// Return the list object
		L.Push(userdata)
		return 1 // Number of returned values
	}))

}
開發者ID:sneakyweasel,項目名稱:algernon,代碼行數:39,代碼來源:list.go

示例12: GenerateToggleAdmin

func GenerateToggleAdmin(state pinterface.IUserState) WebHandle {
	return func(ctx *web.Context, username string) string {
		if !state.AdminRights(ctx.Request) {
			return MessageOKback("Admin toggle", "Not logged in as Administrator")
		}
		if username == "" {
			return MessageOKback("Admin toggle", "Can't set toggle empty username")
		}
		if !state.HasUser(username) {
			return MessageOKback("Admin toggle", "Can't toggle non-existing user")
		}
		// A special case
		if username == "admin" {
			return MessageOKback("Admin toggle", "Can't remove admin rights from the admin user")
		}
		if !state.IsAdmin(username) {
			state.SetAdminStatus(username)
			return MessageOKurl("Admin toggle", "OK, "+username+" is now an admin", "/admin")
		}
		state.RemoveAdminStatus(username)
		return MessageOKurl("Admin toggle", "OK, "+username+" is now a regular user", "/admin")
	}
}
開發者ID:xyproto,項目名稱:siteengines,代碼行數:23,代碼來源:adminengine.go

示例13: GenerateStatusCurrentUser

func GenerateStatusCurrentUser(state pinterface.IUserState) SimpleContextHandle {
	return func(ctx *web.Context) string {
		if !state.AdminRights(ctx.Request) {
			return MessageOKback("Status", "Not logged in as Administrator")
		}
		username := state.Username(ctx.Request)
		if username == "" {
			return MessageOKback("Current user status", "No user logged in")
		}
		hasUser := state.HasUser(username)
		if !hasUser {
			return MessageOKback("Current user status", username+" does not exist")
		}
		if !(state.IsLoggedIn(username)) {
			return MessageOKback("Current user status", "User "+username+" is not logged in")
		}
		return MessageOKback("Current user status", "User "+username+" is logged in")
	}
}
開發者ID:xyproto,項目名稱:siteengines,代碼行數:19,代碼來源:adminengine.go

示例14: GenerateLogoutCurrentUser

// Log out a user by changing the loggedin value
func GenerateLogoutCurrentUser(state pinterface.IUserState) SimpleContextHandle {
	return func(ctx *web.Context) string {
		username := state.Username(ctx.Request)
		if username == "" {
			return MessageOKback("Logout", "No user to log out")
		}
		if !state.HasUser(username) {
			return MessageOKback("Logout", "user "+username+" does not exist, could not log out")
		}

		// Log out the user by changing the database, the cookie can stay
		state.SetLoggedOut(username)

		// Redirect
		//ctx.SetHeader("Refresh", "0; url=/login", true)
		return MessageOKurl("Logout", username+" is now logged out. Hope to see you soon!", "/login")
	}
}
開發者ID:xyproto,項目名稱:siteengines,代碼行數:19,代碼來源:userengine.go

示例15: GenerateRemoveUser

// TODO: Undo for removing users
// Remove a user
func GenerateRemoveUser(state pinterface.IUserState) WebHandle {
	return func(ctx *web.Context, username string) string {
		if !state.AdminRights(ctx.Request) {
			return MessageOKback("Remove user", "Not logged in as Administrator")
		}

		if username == "" {
			return MessageOKback("Remove user", "Can't remove blank user")
		}
		if !state.HasUser(username) {
			return MessageOKback("Remove user", username+" doesn't exists, could not remove")
		}

		// Remove the user
		state.RemoveUser(username)

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


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