示例#1
0
func ac_admin_groupcate(w http.ResponseWriter, r *http.Request) {
	switch r.FormValue("op") {
	case "":
		var cates []Group_cate
		err := Db.C("go_Group_cate").Find(nil).All(&cates)
		CheckErr(err)
		AdminTemplate(w, r, map[string]interface{}{"cates": cates}, "template/group/admin_groupcate.html")
	case "add":
		err := Db.C("go_Group_cate").Insert(&Group_cate{Id_: bson.NewObjectId(),
			Catename:    r.FormValue("catename"),
			Count_group: 0})
		CheckErr(err)
		http.Redirect(w, r, "/admin/group/cate", http.StatusFound)
	case "del":
		err := Db.C("go_Group_cate").Remove(bson.M{"_id": bson.ObjectIdHex(r.FormValue("id"))})
		CheckErr(err)
		http.Redirect(w, r, "/admin/group/cate", http.StatusFound)
	case "update":
		id := bson.ObjectIdHex(r.FormValue("id"))
		//fmt.Println(id)
		err := Db.C("go_Group_cate").Update(bson.M{"_id": id},
			bson.M{"$set": bson.M{"catename": r.FormValue("catename")}})
		//fmt.Println(id)
		CheckErr(err)
		fmt.Fprint(w, "ok")
	}
}
示例#2
0
//文章分类 增删改
func ac_admin_catelist(w http.ResponseWriter, r *http.Request) {
	C := Db.C("go_Article_cate")

	switch r.FormValue("op") {
	case "add": //添加
		catename := r.FormValue("catename")
		orderid := r.FormValue("sortid")
		if forms.IsEmpty(w, catename, orderid) {
			return
		}
		err := C.Insert(&Article_cate{Id_: bson.NewObjectId(),
			Catename: catename, Orderid: forms.Toint(orderid)})
		CheckErr(err)
		http.Redirect(w, r, "/admin/article/catelist", http.StatusFound)
		return
	case "del": //删除
		err := C.Remove(bson.M{"_id": bson.ObjectIdHex(r.FormValue("delid"))})
		CheckErr(err)
		http.Redirect(w, r, "/admin/article/catelist", http.StatusFound)
	case "update": //修改
		if r.FormValue("catename") == "" || r.FormValue("sortid") == "" {
			fmt.Fprint(w, "no")
			return
		}
		err := C.Update(bson.M{"_id": bson.ObjectIdHex(r.FormValue("id"))},
			bson.M{"$set": bson.M{"catename": r.FormValue("catename"),
				"orderid": forms.Toint(r.FormValue("sortid"))}})
		CheckErr(err)
		fmt.Fprint(w, "ok")
		return
	case "": //显示列表
		cates := Article_allcate(nil)
		AdminTemplate(w, r, map[string]interface{}{"cates": cates}, "template/article/admin_catelist.html")
	}
}
示例#3
0
文件: article.go 项目: jinzhe/GOSNS
func ac_articleshow(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	article := Article_Get(bson.ObjectIdHex(vars["id"]))
	tags := TagidToname(article.Tags)
	comment := Article_Getcomment(bson.ObjectIdHex(vars["id"]))
	IndexTemplate(w, r,
		map[string]interface{}{"article": article, "tags": tags, "comment": comment},
		"template/article/articleshow.html")

}
示例#4
0
func ac_group(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	var group Group
	err := Db.C("go_Group").Find(bson.M{"_id": bson.ObjectIdHex(vars["group"])}).One(&group)
	CheckErr(err)
	var posts []Group_posts
	Db.C("go_Group_posts").Find(bson.M{"groupid": bson.ObjectIdHex(vars["group"])}).
		Sort("-lasttime").All(&posts)
	IndexTemplate(w, r, map[string]interface{}{"group": group, "posts": posts,
		"user": User_curuser(w, r)}, "template/group/group.html")
}
示例#5
0
文件: group.go 项目: jinzhe/GOSNS
//回复
func ac_commentpost(w http.ResponseWriter, r *http.Request) {
	userid := User_curuserid(w, r)
	if userid == "" {
		ExitMsg(w, "请登录")
	}
	text := ubb2html.Ubb2html(r.FormValue("text"))
	p := &Group_posts_comment{Id_: bson.NewObjectId(), Postid: bson.ObjectIdHex(r.FormValue("tid")),
		Userid: bson.ObjectIdHex(userid), Content: template.HTML(text),
		Referid: bson.ObjectIdHex(r.FormValue("rid"))}
	AddComment(p)
	http.Redirect(w, r, "/group/p/"+r.FormValue("tid"), http.StatusFound)
}
示例#6
0
文件: article.go 项目: jinzhe/GOSNS
func ac_articlecomment(w http.ResponseWriter, r *http.Request) {
	if r.Method == "POST" {
		id := User_curuserid(w, r)
		if id == "" {
			ExitMsg(w, "请先登录")
			return
		}
		ac := Article_comment{Id_: bson.NewObjectId(),
			Articleid: bson.ObjectIdHex(r.FormValue("articleid")),
			Userid:    bson.ObjectIdHex(id),
			Content:   template.HTML(ubb2html.Ubb2html(r.FormValue("text"))),
		}
		err := Db.C("go_Article_comment").Insert(&ac)
		CheckErr(err)
		ExitMsg(w, "评论成功")
	}
}
示例#7
0
文件: group.go 项目: jinzhe/GOSNS
//发帖
func ac_grouppost(w http.ResponseWriter, r *http.Request) {
	userid := User_curuserid(w, r)
	if userid == "" {
		ExitMsg(w, "请登录")
	}
	title := r.FormValue("title")
	if len(r.FormValue("title")) > 60 {
		title = r.FormValue("title")[0:60]
	}
	fmt.Println(len(r.FormValue("title")))
	g := &Group_posts{Id_: bson.NewObjectId(), Cateid: bson.ObjectIdHex(r.FormValue("cateid")),
		Groupid: bson.ObjectIdHex(r.FormValue("groupid")), Title: title,
		Userid: bson.ObjectIdHex(userid), Content: template.HTML(r.FormValue("text")),
		Lastuser: bson.ObjectIdHex(userid), Lasttime: time.Now()}
	err := Db.C("go_Group_posts").Insert(&g)
	CheckErr(err)
	http.Redirect(w, r, "/group/g/"+r.FormValue("groupid"), http.StatusFound)
}
示例#8
0
func User_curuser(w http.ResponseWriter, r *http.Request) *User {
	id := User_curuserid(w, r)
	if id == "" {
		return nil
	}
	var user User
	err := Db.C("go_user").Find(bson.M{"_id": bson.ObjectIdHex(id)}).One(&user)
	CheckErr(err)
	return &user
}
示例#9
0
func ac_tshow(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	var post Group_posts
	err := Db.C("go_Group_posts").Find(bson.M{"_id": bson.ObjectIdHex(vars["tid"])}).One(&post)
	CheckErr(err)
	var comm []Group_posts_comment
	Db.C("go_Group_posts_comment").Find(bson.M{"postid": post.Id_}).All(&comm)
	Db.C("go_Group_posts").Update(bson.M{"_id": post.Id_}, bson.M{"$inc": bson.M{"count_click": 1}})
	IndexTemplate(w, r, map[string]interface{}{"post": post, "comm": comm}, "template/group/tlist.html")
}
示例#10
0
文件: tag_admin.go 项目: jinzhe/GOSNS
//标签删除修改
func ac_tagaction(w http.ResponseWriter, r *http.Request) {
	switch r.FormValue("op") {
	case "update":
		err := Db.C("go_tag").Update(bson.M{"_id": bson.ObjectIdHex(r.FormValue("id"))},
			bson.M{"$set": bson.M{"tagname": r.FormValue("tagname")}})
		CheckErr(err)
		fmt.Fprint(w, "ok")
	case "del":

	}
}
示例#11
0
func ac_admin_comment(w http.ResponseWriter, r *http.Request) {
	switch r.FormValue("op") {
	case "":
		var comments []Article_comment
		err := Db.C("go_Article_comment").Find(nil).All(&comments)
		CheckErr(err)
		AdminTemplate(w, r, map[string]interface{}{"comments": comments}, "template/article/admin_comment.html")
	case "del":
		id := bson.ObjectIdHex(r.FormValue("id"))
		err := Db.C("go_Article_comment").Remove(bson.M{"_id": id})
		CheckErr(err)
		http.Redirect(w, r, "/admin/article/comment", http.StatusFound)
	}
}
示例#12
0
func ac_admin_group(w http.ResponseWriter, r *http.Request) {
	if r.Method == "POST" {
		switch r.FormValue("op") {
		case "add":
			userid := User_curuserid(w, r)
			cateid := r.FormValue("cateid")
			group := &Group{Id_: bson.NewObjectId(), Userid: bson.ObjectIdHex(userid),
				Cateid: bson.ObjectIdHex(cateid), Count_user: 0, Count_topic: 0,
				Groupname: r.FormValue("groupname"), Role_user: r.FormValue("role_user")}
			err := Db.C("go_Group").Insert(&group)
			Group_cateaddgroup(bson.ObjectIdHex(cateid))
			CheckErr(err)
			ExitMsg(w, "添加成功")
		}
	}
	switch r.FormValue("op") {
	case "":
		list := Group_list()
		AdminTemplate(w, r, map[string]interface{}{"list": list}, "template/group/admin_group.html")
	case "showadd":
		cates := Group_allcate()
		AdminTemplate(w, r, map[string]interface{}{"cates": cates}, "template/group/admin_groupadd.html")
	}
}
示例#13
0
//文章浏览删除
func ac_admin_articlelist(w http.ResponseWriter, r *http.Request) {
	C := Db.C("go_Article")
	switch r.FormValue("op") {
	case "":
		var articles []Article
		C.Find(nil).Select(bson.M{"content": false}).All(&articles)
		cates := Article_mapcate(bson.M{"orderid": 0})
		AdminTemplate(w, r, map[string]interface{}{"articles": articles,
			"cates": cates}, "template/article/admin_articlelist.html")
	case "del":
		err := C.Remove(bson.M{"_id": bson.ObjectIdHex(r.FormValue("delid"))})
		CheckErr(err)
		http.Redirect(w, r, "/admin/article/list", http.StatusFound)
	}
}
示例#14
0
文件: user.go 项目: jinzhe/GOSNS
func ac_usercenter(w http.ResponseWriter, r *http.Request) {
	sess := Gsession.SessionStart(w, r)
	suid := sess.Get("User")
	if suid == nil {
		ExitMsg(w, "未登录", "/user/login")
		return
	}

	switch r.FormValue("t") {
	case "":
		Userinfo := User{}
		err := Db.C("go_user").Find(bson.M{"_id": bson.ObjectIdHex(suid.(string))}).One(&Userinfo)
		CheckErr(err)
		IndexTemplate(w, r, map[string]interface{}{"info": Userinfo}, "template/user/usercenter.html")
	case "tx":
		IndexTemplate(w, r, map[string]interface{}{}, "template/user/touxiang.html")
	}

}
示例#15
0
//文章添加编辑
func ac_admin_article(w http.ResponseWriter, r *http.Request) {
	C := Db.C("go_Article")
	if r.Method == "POST" {
		if forms.IsEmpty(w, r.FormValue("title"), r.FormValue("cateid")) {
			return
		}
		switch r.FormValue("op") {
		case "add":
			inid := bson.NewObjectId()
			err := C.Insert(&Article{Id_: inid, Cateid: bson.ObjectIdHex(r.FormValue("cateid")),
				Title: r.FormValue("title"), Content: template.HTML(r.FormValue("elm1")), Count_comment: 0})
			CheckErr(err)
			var nullstr []bson.ObjectId
			Tag_add(r.FormValue("tags"), "Article", inid, nullstr)
			ExitMsg(w, "添加成功")
			return
		case "update":
			err := C.Update(bson.M{"_id": bson.ObjectIdHex(r.FormValue("id"))}, bson.M{"$set": bson.M{
				"cateid": bson.ObjectIdHex(r.FormValue("cateid")),
				"title":  r.FormValue("title"), "content": template.HTML(r.FormValue("elm1"))}})
			var getarticle Article
			CheckErr(err)
			gerr := C.Find(bson.M{"_id": bson.ObjectIdHex(r.FormValue("id"))}).One(&getarticle)
			CheckErr(gerr)
			Tag_add(r.FormValue("tags"), "Article", bson.ObjectIdHex(r.FormValue("id")), getarticle.Tags)
			ExitMsg(w, "修改成功")
			return
		}
	}

	switch r.FormValue("op") {
	case "":
		cates := Article_allcate(nil)
		AdminTemplate(w, r, map[string]interface{}{"cates": cates}, "template/article/admin_addarticle.html")
	case "edit":
		cates := Article_allcate(nil)
		article := Article_Get(bson.ObjectIdHex(r.FormValue("id")))
		tags := TagidToname(article.Tags)
		AdminTemplate(w, r, map[string]interface{}{"cates": cates, "article": article, "tags": tags},
			"template/article/admin_editarticle.html")
	}
}
示例#16
0
//修改头像
func Face(userid string) {
	err := Db.C("go_user").Update(bson.M{"_id": bson.ObjectIdHex(userid)}, bson.M{"$set": bson.M{"face": userid}})
	CheckErr(err)
}