Exemplo n.º 1
0
func CharacterEditorPost(ctx *web.Context, val string) string {
	if util.SignedIn(ctx) {
		char := NewCharacter()
		char.Owner = util.ReadUsername(ctx)
		char.ID = ctx.Params["CharacterID"]
		char.Game = ctx.Params["Game"]
		char.Name = ctx.Params["Name"]
		char.World = ctx.Params["World"]
		char.Alligiance = ctx.Params["Alligiance"]
		char.Bio = ctx.Params["Bio"]
		if db, err := util.GetDB(); err == nil {
			blog := util.NewBlogData()
			db.Retrieve("BlogData_"+char.Owner, &blog)
			dummy := NewCharacter()
			rev, err := db.Retrieve(char.ID, &dummy)
			if err == nil {
				if dummy.Owner != char.Owner {
					return util.MessagePage("You are not authorized to edit this charater.", ctx)
				}
				char.Rev = rev
				db.Edit(&char)
				return util.MessagePage("Character updated.", ctx)
			} else {
				char.ID = "Character_" + strconv.Itoa(blog.CharacterIndex) + "_" + char.Owner
				db.Insert(&char)
				blog.CharacterIndex++
				blog.Characters = append(blog.Characters, char.ID)
				db.Edit(&blog)
				return util.MessagePage("Character created.", ctx)
			}
		}
	}
	return util.MessagePage("Operation failed, try again later.", ctx)
}
Exemplo n.º 2
0
func AddCharacterPost(ctx *web.Context, val string) string {
	game, ok := ctx.Params["Game"]
	if ok {
		if !util.SignedIn(ctx) {
			return util.MessagePage("Please sign in.", ctx)
		}
		file, err := util.LoadTemplate("Add"+game+"Character", "CharacterEditor.html", ctx)

		if err == nil {
			file = strings.Replace(file, "{{Game}}", game, -1)
			file = strings.Replace(file, "{{CharacterID}}", "", -1)
			file = strings.Replace(file, "{{Name}}", "", -1)
			file = strings.Replace(file, "{{World}}", "", -1)
			file = strings.Replace(file, "{{Alligiance}}", "", -1)
			file = strings.Replace(file, "{{Bio}}", "", -1)
			return file
		}
	}
	return util.MessagePage("Operation failed, try again later.", ctx)
}
Exemplo n.º 3
0
func get(ctx *web.Context, val string) string {
	switch val {
	case "Account.html":
		return users.AccountManagementGet(ctx, val)
	case "Character.html":
		return char.ViewCharacterGet(ctx, val)
	case "EditCharacter.html":
		return char.EditCharacterGet(ctx, val)
	case "EditPost.html":
		return posts.GetEditPost(ctx, val)
	case "", "index.html", "index.htm":
		db, err := util.GetDB()
		if err != nil {
			return util.MessagePage("Cannot access database.", ctx)
		}
		data, err := util.LoadTemplate("", "index.html", ctx)
		if err != nil {
			break
		}
		list := ""
		if users, err := db.QueryIds("_design/users/_view/all", nil); err == nil {
			list = "<ul>\n"
			size := len(users)
			for i := 0; i < size; i++ {
				user := strings.SplitAfter(users[i], "User_", 2)[1]
				list += "\t<il><a href=\"" + "view?user="******"\">" + user + "</a></il><br>\n"
			}
			list += "</ul>"
		}
		data = strings.Replace(data, "{{UserList}}", list, -1)

		if postList, err := db.QueryIds("_design/posts/_view/all", nil); err == nil {
			list = "<ul>\n"
			start := 10
			if start >= len(postList) {
				start = len(postList) - 1
			}
			for i := start; i > -1; i-- {
				var post posts.Post
				_, err := db.Retrieve(postList[i], &post)
				if err == nil {
					list += "\t<il>" + post.HTML(ctx) + "</il><br>\n"
				}
			}
			list += "</ul>"
		}
		data = strings.Replace(data, "{{Posts}}", list, -1)

		return data
	case "signout.html":
		if value, ok := util.ReadUserKey(ctx); ok {
			ctx.SetSecureCookie("UserKey", value, -6000000)
			util.DeleteUserKey(value)
		}
		if username, ok := util.ReadCookie("Username", ctx); ok {
			ctx.SetSecureCookie("Username", username, -6000000)
		}
		return util.MessagePage("You're signed out.", ctx)
		break
	case "signin.html":
		if util.SignedIn(ctx) {
			return util.MessagePage("You're already signed in.", ctx)
		}
		retval, err := util.LoadTemplate("", val, ctx)
		if err != nil {
			break
		}
		return retval
	case "view/", "view":
		return posts.ViewPost(ctx, val)
	default:
		if strings.HasSuffix(val, ".html") {
			retval, err := util.LoadTemplate("", val, ctx)
			if err != nil {
				break
			}
			return retval
		}
		retval, err := util.LoadFile(val)
		if err != nil {
			break
		}
		if strings.HasSuffix(val, ".html") {
		} else if strings.HasSuffix(val, ".wgt") {
			topbar, _ := util.TopBar(ctx)
			retval = strings.Replace(retval, "{{TopBar}}", topbar, -1)
		}
		return retval
	}
	return util.FileNotFound
}