Пример #1
0
// 用户个人首页
// URI: /user/{username}
func UserHomeHandler(rw http.ResponseWriter, req *http.Request) {

	vars := mux.Vars(req)
	username := vars["username"]
	// 获取用户信息
	user := service.FindUserByUsername(username)

	if user == nil {
		util.Redirect(rw, req, "/users")
		return
	}

	topics := service.FindRecentTopics(user.Uid, "5")

	resources := service.FindUserRecentResources(user.Uid)
	resourceCats := make(map[int]string)
	for _, resource := range resources {
		resourceCats[resource.Catid] = service.GetCategoryName(resource.Catid)
	}

	projects := service.FindUserRecentProjects(user.Username)
	comments := service.FindRecentComments(user.Uid, -1, "5")
	// 设置模板数据
	filter.SetData(req, map[string]interface{}{"activeUsers": "active", "topics": topics, "resources": resources, "resource_cats": resourceCats, "projects": projects, "comments": comments, "user": user})
	req.Form.Set(filter.CONTENT_TPL_KEY, "/template/user/profile.html")
}
Пример #2
0
// 用户个人首页
// URI: /user/{username}
func UserHomeHandler(rw http.ResponseWriter, req *http.Request) {
	req.Form.Set(filter.CONTENT_TPL_KEY, "/template/user/profile.html")
	vars := mux.Vars(req)
	username := vars["username"]
	// 获取用户信息
	user := service.FindUserByUsername(username)
	if user != nil {
		topics := service.FindRecentTopics(user.Uid)
		comments := service.FindRecentComments(user.Uid, model.TYPE_TOPIC)
		replies := service.FindRecentReplies(comments)
		// 设置模板数据
		filter.SetData(req, map[string]interface{}{"activeUsers": "active", "topics": topics, "replies": replies, "user": user})
	}
}
Пример #3
0
// 最新帖子
// uri: /topics/recent.json
func RecentTopicHandler(rw http.ResponseWriter, req *http.Request) {
	limit := req.FormValue("limit")
	if limit == "" {
		limit = "10"
	}

	recentTopics := service.FindRecentTopics(0, limit)
	buf, err := json.Marshal(recentTopics)
	if err != nil {
		logger.Errorln("[RecentTopicHandler] json.marshal error:", err)
		fmt.Fprint(rw, `{"ok": 0, "error":"解析json出错"}`)
		return
	}
	fmt.Fprint(rw, `{"ok": 1, "data":`+string(buf)+`}`)
}