Example #1
0
func AccountManagementGet(ctx *web.Context, val string) string {
	file, err := util.LoadTemplate("Accout Management", val, ctx)
	if err != nil {
		return util.FileNotFound
	}
	return file
}
Example #2
0
func ViewPost(ctx *web.Context, val string) string {
	db, err := util.GetDB()
	if err != nil {
		return util.FileNotFound
	}
	user := ctx.Params["user"]
	retval, err := util.LoadTemplate(user, "posts.html", ctx)
	if err != nil {
		return util.FileNotFound
	}
	blogData := util.NewBlogData()
	_, err = db.Retrieve("BlogData_"+user, &blogData)
	if err != nil {
		return util.FileNotFound
	}
	post := NewPost()
	posts := ""
	for i := len(blogData.Posts) - 1; i > -1; i-- {
		_, err := db.Retrieve(blogData.Posts[i], &post)
		if err != nil {
			post.Title = "Error: Post not found."
			post.Content = ""
		} else {
			post.Content = strings.Replace(post.Content, "\n", "<br>", -1)
		}
		posts += post.HTML(ctx) + "<br>"
	}
	retval = strings.Replace(retval, "{{Posts}}", posts, -1)
	return retval
}
Example #3
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
}
Example #4
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
}
Example #5
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)
}
Example #6
0
func ViewCharacterGet(ctx *web.Context, val string) string {
	charid, ok := ctx.Params["CharID"]
	if ok {
		db, err := util.GetDB()
		if err != nil {
			return util.FileNotFound
		}
		char := NewCharacter()
		db.Retrieve(charid, &char)
		if file, err := util.LoadTemplate(char.Name, "Character.html", ctx); err == nil {
			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, "{{Alligence}}", char.Alligiance, -1)
			file = strings.Replace(file, "{{Bio}}", char.Bio, -1)
			return file
		}
	}
	return util.FileNotFound
}
Example #7
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
}
Example #8
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
}