Exemple #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)
}
Exemple #2
0
//The HTTP get method for getting the page for editing posts.
func GetEditPost(ctx *web.Context, val string) string {
	db, err := util.GetDB()
	if err != nil {
		return util.FileNotFound
	}
	post := NewPost()
	postID, ok := ctx.Params["PostID"]
	var newPost bool
	if ok && postID != "NewPost" {
		db.Retrieve(postID, &post)
		if userKey, ok := util.ReadUserKey(ctx); !(ok && util.GetUserKey(userKey) == post.Owner) {
			return util.MessagePage("You do not have permission to edit this post.", ctx)
		}
		newPost = false
	} else {
		postID = "NewPost"
		newPost = true
	}
	if file, err := util.LoadTemplate("", "EditPost.html", ctx); err == nil {
		if newPost {
			file = strings.Replace(file, "{{Message}}", "<h3>Writing New Post</h3>", 1)
		} else {
			file = strings.Replace(file, "{{Message}}", "<h3>Editing Existing Post</h3>", 1)
		}
		file = strings.Replace(file, "{{PostID}}", postID, 1)
		file = strings.Replace(file, "{{Title}}", post.Title, 1)
		file = strings.Replace(file, "{{Author}}", post.Author, 1)
		file = strings.Replace(file, "{{Content}}", post.Content, 1)
		authors := ""
		defaultAuthor := post.Author
		if defaultAuthor != "" {
			char := char.NewCharacter()
			db.Retrieve(defaultAuthor, &char)
			authors += "\t\t<option value=\"" + defaultAuthor + "\">" + char.Name + " (" + char.Game + " - " + char.World + ")</option>\n"
		}
		authors += "\t\t<option value=\"\">Me</option>\n"
		blog := util.NewBlogData()
		db.Retrieve("BlogData_"+util.ReadUsername(ctx), &blog)
		for i := 0; i < len(blog.Characters); i++ {
			if blog.Characters[i] != defaultAuthor {
				char := char.NewCharacter()
				db.Retrieve(blog.Characters[i], &char)
				authors += "\t\t<option value=\"" + blog.Characters[i] + "\">" + char.Name + " (" + char.Game + " - " + char.World + ")</option>\n"
			}
		}
		file = strings.Replace(file, "{{AuthorOptions}}", authors, 1)

		return file
	}
	return util.FileNotFound
}
Exemple #3
0
func EditCharacterGet(ctx *web.Context, val string) string {
	if db, err := util.GetDB(); err == nil {
		blog := util.NewBlogData()
		db.Retrieve("BlogData_"+util.ReadUsername(ctx), &blog)
		chars := "<option>----</option>\n"
		for i := 0; i < len(blog.Characters); i++ {
			char := NewCharacter()
			db.Retrieve(blog.Characters[i], &char)
			chars += "\t\t<option value=\"" + blog.Characters[i] + "\">" + char.Name + " (" + char.Game + " - " + char.World + ")</option>\n"
		}
		file, err := util.LoadTemplate("Edit Character", "EditCharacter.html", ctx)
		if err == nil {
			file = strings.Replace(file, "{{CharacterOptions}}", chars, -1)
			return file
		}
	}
	return util.FileNotFound
}
Exemple #4
0
func EditCharacterPost(ctx *web.Context, val string) string {
	if db, err := util.GetDB(); err == nil {
		var char Character
		_, err = db.Retrieve(ctx.Params["CharacterID"], &char)
		if err == nil {
			if util.ReadUsername(ctx) == char.Owner {
				file, err := util.LoadTemplate("Editing "+char.Name, "CharacterEditor.html", ctx)
				if err == nil {
					file = strings.Replace(file, "{{CharacterID}}", ctx.Params["CharacterID"], -1)
					file = strings.Replace(file, "{{Name}}", char.Name, -1)
					file = strings.Replace(file, "{{Game}}", char.Game, -1)
					file = strings.Replace(file, "{{World}}", char.World, -1)
					file = strings.Replace(file, "{{Alligiance}}", char.Alligiance, -1)
					file = strings.Replace(file, "{{Bio}}", char.Bio, -1)
					return file
				}
			}
		}
	}
	return util.FileNotFound
}
Exemple #5
0
func (me *Post) HTML(ctx *web.Context) string {
	retval := util.PostDiv()
	retval = strings.Replace(retval, "{{Title}}", me.Title, -1)
	if len(me.Author) != 0 {
		char := char.NewCharacter()
		db, err := util.GetDB()
		if err == nil {
			db.Retrieve(me.Author, &char)
			retval = strings.Replace(retval, "{{Author}}", "<a href=\"Character.html?CharID="+me.Author+"\">"+char.Name+"</a>", -1)
		} else {
			retval = strings.Replace(retval, "{{Author}}", "", -1)
		}
	} else {
		retval = strings.Replace(retval, "{{Author}}", me.Owner, -1)
	}
	retval = strings.Replace(retval, "{{Content}}", me.Content, -1)
	if username := util.ReadUsername(ctx); me.Owner == username {
		ownerControls := html.TextLink("Edit", "EditPost.html?PostID="+me.ID)
		retval = strings.Replace(retval, "{{OwnerControls}}", ownerControls.String(), -1)
	} else {
		retval = strings.Replace(retval, "{{OwnerControls}}", "", -1)
	}
	return retval
}