Exemple #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")
	}
}
Exemple #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")
	}
}
Exemple #3
0
//回复
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)
}
Exemple #4
0
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, "评论成功")
	}
}
Exemple #5
0
func ac_user(w http.ResponseWriter, r *http.Request) {
	if r.Method == "POST" {
		email := r.FormValue("email")
		user := r.FormValue("user")
		pwd := r.FormValue("pwd")
		if !forms.Reg_email(email) {
			ExitMsg(w, "邮箱格式错误")
			return
		}

		if !forms.Reg_user(user) {
			ExitMsg(w, "用户名格式错误")
			return
		}
		if pwd == "" {
			ExitMsg(w, "密码不可为空")
			return
		}
		pwd = forms.Tomd5(pwd)

		if !captcha.VerifyString(r.FormValue("captchaId"), r.FormValue("captchaSolution")) {
			ExitMsg(w, "验证码错误")
			return
		}
		if User_ishaveEmail(email) {
			ExitMsg(w, "Email 已存在")
			return
		}
		if User_ishaveName(user) {
			ExitMsg(w, "用户名 已存在")
			return
		}
		C := Db.C("go_user")
		id := bson.NewObjectId()
		err := C.Insert(&User{Id_: id, Username: user, Pwd: pwd, Email: email, Adminid: 0,
			Regip: forms.Ip(r), Lastip: forms.Ip(r), Lasttime: time.Now()})
		CheckErr(err)
		fmt.Fprint(w, "添加成功")
		return
	}

	t, err := template.ParseFiles("template/user/index.html")
	CheckErr(err)
	t.Execute(w, struct{ CaptchaId string }{captcha.New()})
}
Exemple #6
0
//发帖
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)
}
Exemple #7
0
func addtag(subtag []string, tagtype string, objid bson.ObjectId, oldids []bson.ObjectId) {
	oldtag := TagidToname(oldids)
	newtag := silcenothave(subtag, oldtag)
	removetag := silcenothave(oldtag, subtag)

	///处理新增的标签
	if len(newtag) > 0 {
		for _, ntv := range newtag { //遍历新增的标签
			tag := Ishavetag(ntv)
			if tag == nil { //如果数据库中没有
				newid := bson.NewObjectId()
				CheckErr(Db.C("go_tag").Insert(&Tag{Id_: newid, Tagname: ntv, Count: 1}))
				CheckErr(Db.C("go_"+tagtype).Update(bson.M{"_id": objid}, bson.M{"$push": bson.M{"tags": newid}}))
				Tagnum(newid, tagtype)
			} else { //如果数据库中已有
				isinnum, err := Db.C("go_" + tagtype).Find(bson.M{"_id": objid, "tags": tag.Id_}).Count()
				CheckErr(err)
				if isinnum == 0 {
					CheckErr(Db.C("go_"+tagtype).Update(bson.M{"_id": objid}, bson.M{"$push": bson.M{"tags": tag.Id_}}))
					Tagnum(tag.Id_, tagtype)
					Tagcount(tag.Id_, 1)
				}
			}
		}
	}
	fmt.Println("newtag")
	fmt.Println(newtag)
	fmt.Println("removetag")
	fmt.Println(removetag)
	//处理删除的标签
	if len(removetag) > 0 {
		for _, delv := range removetag {
			b, tid := Getagid(delv)
			if !b {
				panic("并不存在需要删除的标签 model-tag_model.go 58")
			}
			Db.C("go_"+tagtype).Update(bson.M{"_id": objid}, bson.M{"$pull": bson.M{"tags": tid}})
			Tagnum(tid, tagtype)
			Tagcount(tid, -1)
		}
	}

}
Exemple #8
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")
	}
}
Exemple #9
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")
	}
}