Ejemplo n.º 1
0
func (self *NewAnswerHandler) Post() {
	qid, _ := self.GetInt(":qid")
	suid, _ := self.GetSession("userid").(int64)

	author := template.HTMLEscapeString(strings.TrimSpace(strings.ToLower(self.GetString("author"))))
	email := template.HTMLEscapeString(strings.TrimSpace(strings.ToLower(self.GetString("email"))))
	website := template.HTMLEscapeString(strings.TrimSpace(strings.ToLower(self.GetString("website"))))
	rc := template.HTMLEscapeString(strings.TrimSpace(self.GetString("content")))

	//不等于0,即是注册用户或管理层 此时把ctype设置为1 主要是为了区分游客
	if suid != 0 {
		if qid > 0 && rc != "" {

			if usr, err := model.GetUser(suid); err == nil {
				//为安全计,先行保存回应,顺手获得aid,在后面顺手再更新替换@通知的链接
				if aid, err := model.AddAnswer(qid, suid, 1, rc, usr.Username, usr.Content, usr.Email, usr.Website); err != nil {
					fmt.Println("#", aid, ":", err)
				} else {

					//如果回应内容中有@通知 则处理以下事件
					/*
						if users := helper.AtUsers(rc); len(users) > 0 {
							if tp, err := model.GetQuestion(qid); err == nil {
								todo := []string{}
								for _, v := range users {
									//判断被通知之用户名是否真实存在
									if u, e := model.GetUserByUsername(v); e == nil && u != nil {
										//存在的则加入待操作列
										todo = append(todo, v)
										//替换被通知用户的用户名带上用户主页链接
										rc = strings.Replace(rc, "@"+v,
											"<a href='/user/"+u.Username+"/' title='"+u.Nickname+"' target='_blank'><span>@</span><span>"+u.Username+"</span></a>", -1)

										//发送通知内容到用户的 时间线
										model.AddTimeline(usr.Username+"在「"+tp.Title+"」的回应里提到了你~",
											rc+"[<a href='/"+self.GetString(":qid")+"/#answer-"+strconv.Itoa(int(aid))+"'>"+tp.Title+"</a>]",
											tp.Cid, tp.Nid, u.Id, usr.Username, usr.Content)

									}

								}
								if len(todo) > 0 {
									model.SetReplyContentByRid(aid, rc)
								}

							}
						}
					*/
					self.Redirect("/"+self.GetString(":qid")+"/#answer-"+strconv.Itoa(int(aid)), 302)
					return
				}
			}
			self.Redirect("/"+self.GetString(":qid")+"/", 302)
		} else if qid > 0 {
			self.Redirect("/"+self.GetString(":qid")+"/", 302)
		} else {
			self.Redirect("/", 302)
		}
	} else { //游客回应 此时把ctype设置为-1   游客不开放@通知功能
		if author != "" && email != "" && qid > 0 && rc != "" {
			if aid, err := model.AddAnswer(qid, suid, -1, rc, author, "", email, website); err != nil {
				fmt.Println("#", aid, ":", err)
				self.Redirect("/"+self.GetString(":qid")+"/", 302)
			} else {
				self.Redirect("/"+self.GetString(":qid")+"/#answer-"+strconv.Itoa(int(aid)), 302)
			}
		} else if qid > 0 {
			self.Redirect("/"+self.GetString(":qid")+"/", 302)
		} else {
			self.Redirect("/", 302)
		}

	}

}
Ejemplo n.º 2
0
func (self *QuestionHandler) Get() {
	self.TplNames = "sdc/question.html"

	qid, _ := self.GetInt(":qid")

	if qid > 0 {

		if qs, err := model.GetQuestion(qid); qs != nil && err == nil {
			avatar := ""
			if usr, err := model.GetUser(qs.Uid); err == nil && usr != nil {
				avatar = helper.Gravatar(usr.Email, 32)
			}
			self.Data["avatar"] = avatar
			self.Data["article"] = *qs
			self.Data["replys"] = *model.GetAnswersByPid(qid, 0, 0, 0, "hotness")

			/*
				if qss := model.GetTopicsByCidOnBetween(qs.Cid, qid-5, qid+5, 0, 11, 0, "asc"); qss != nil && qid != 0 && len(qss) > 0 {

					for i, v := range qss {

						if v.Id == qid {
							//两侧的翻页按钮参数 初始化 s
							prev := i - 1
							next := i + 1
							//两侧的翻页按钮参数 初始化 e

							//话题内容部位 页码  初始化 s
							ipagesbar := `<div class="link_pages">`
							h := 5
							ipagesbar_start := i - h
							ipagesbar_end := i + h
							j := 0
							//话题内容部位 页码  初始化 e
							for i, v := range qss {
								//两侧的翻页按钮 s
								if prev == i {
									self.Data["previd"] = v.Id
									self.Data["prev"] = v.Title
								}
								if next == i {
									self.Data["nexqid"] = v.Id
									self.Data["next"] = v.Title
								}
								//两侧的翻页按钮 e

								//话题内容部位 页码 s
								if ipagesbar_start == i {
									ipagesbar = ipagesbar + `<a href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `"><span><</span></a>`
								}
								if i > ipagesbar_start && i < ipagesbar_end {
									j += 1
									if v.Id == qid { // current

										ipagesbar = ipagesbar + `<span>` + strconv.Itoa(int(v.Id)) + `</span>`

									} else { //loop

										ipagesbar = ipagesbar + `<a href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `"><span>` + strconv.Itoa(int(v.Id)) + `</span></a>`

									}
									if j > (2 * h) {
										break
									}
								}
								if ipagesbar_end == i {
									ipagesbar = ipagesbar + `<a href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `"><span>></span></a>`
								}
								//话题内容部位 页码 e
							}
							self.Data["ipagesbar"] = template.HTML(ipagesbar + "</div>")
						}
					}
					// (qss []*Topic)

				}
			*/

			//侧栏你可能喜欢 推荐同节点下的最热话题
			/*
				if qss := model.GetTopicsByNid(qs.Nid, 0, 6, 0, "hotness"); *qss != nil {

					if len(*qss) > 0 {
						i := 0
						ouqsut := `<ul class="widgets-similar clx">`
						for _, v := range *qss {

							i += 1
							if i == 3 {
								ouqsut = ouqsut + `<li class="similar similar-third">`
								i = 0
							} else {
								ouqsut = ouqsut + `<li class="similar">`
							}
							ouqsut = ouqsut + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">
													<img src="` + v.ThumbnailsSmall + `" wdith="70" height="70" />
												</a>
											</li>`
						}
						ouqsut = ouqsut + `</ul>`
						self.Data["topic_sidebar_hotness_6_module"] = template.HTML(ouqsut)
					}

				}
			*/

			//侧栏九宫格推荐榜单
			//先行取出最热门的一个节点 然后根据节点获取该节点下最热门的话题
			/*
				if nd, err := model.GetNodes(0, 1, "hotness"); err == nil {
					if len(*nd) == 1 {
						for _, v := range *nd {

							if qss := model.GetTopicsByNid(v.Id, 0, 9, 0, "hotness"); err == nil {

								if len(*qss) > 0 {
									i := 0
									ouqsut := `<ul class="widgets-popular widgets-similar clx">`
									for _, v := range *qss {

										i += 1
										if i == 3 {
											ouqsut = ouqsut + `<li class="similar similar-third">`
											i = 0
										} else {
											ouqsut = ouqsut + `<li class="similar">`
										}
										ouqsut = ouqsut + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">
													<img src="` + v.ThumbnailsSmall + `" wdith="70" height="70" />
												</a>
											</li>`
									}
									ouqsut = ouqsut + `</ul>`
									self.Data["topic_hotness_9_module"] = template.HTML(ouqsut)
								}
							} else {
								fmt.Println("推荐榜单(9)数据查询出错", err)
							}
						}
					}
				} else {
					fmt.Println("节点数据查询出错", err)
				}
			*/

			//底部六格推荐
			//推荐同一作者的最热话题
			/*
				if qss := model.GetTopicsByUid(qs.Uid, 0, 6, 0, "hotness"); len(*qss) > 0 {
					i := 0
					ouqsut := `<ul class="widgets-similar clx">`
					for _, v := range *qss {

						i += 1
						if i == 3 {
							ouqsut = ouqsut + `<li class="likesimilar likesimilar-3">`
							i = 0
						} else {
							ouqsut = ouqsut + `<li class="likesimilar">`
						}
						ouqsut = ouqsut + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `" alt="` + v.Title + `" class="likeimglink">
													<img src="` + v.ThumbnailsMedium + `" wdith="150" height="150" />
													<span class="bg">` + v.Title + `</span>
												</a>
											</li>`
					}
					ouqsut = ouqsut + `</ul>`
					self.Data["topic_hotness_6_module"] = template.HTML(ouqsut)
				}
			*/
		} else {
			self.Redirect("/", 302)
		}
	} else {
		self.Redirect("/", 302)
	}

}
Ejemplo n.º 3
0
func (self *SearchHandler) Get() {
	self.TplNames = "sdc/search.html"
	keyword := template.HTMLEscapeString(strings.TrimSpace(self.GetString(":keyword")))

	if keyword == "" {
		keyword = template.HTMLEscapeString(strings.TrimSpace(self.GetString("keyword")))
	}

	ipage, _ := self.GetInt(":page")
	if ipage <= 0 {
		ipage, _ = self.GetInt("page")
	}
	page := int(ipage)

	limit := 9 //每页显示数目

	//如果已经登录登录
	sess_username, _ := self.GetSession("username").(string)
	if sess_username != "" {
		limit = 30
	}

	if keyword != "" {
		if qts, err := model.SearchQuestion(keyword, 0, 0, "id"); err == nil {

			rcs := len(*qts)
			pages, pageout, beginnum, endnum, offset := helper.Pages(rcs, page, limit)

			if st, err := model.SearchQuestion(keyword, offset, limit, "hotness"); err == nil {
				results_count := len(*st)
				if results_count > 0 {
					i := 1
					output := ""
					for _, v := range *qts {

						i += i

						output = output + `<article class="post" id="` + strconv.Itoa(int(v.Id)) + `"><div class="status">`

						if v.Ctype == 2 {
							output = output + `<span class="answer answered-accepted" title="` + strconv.Itoa(int(v.ReplyCount)) + ` 个答案">` + strconv.Itoa(int(v.ReplyCount)) + `</span>`
						} else if v.Ctype == -1 {
							output = output + `<span class="answer answered closed" title="` + strconv.Itoa(int(v.ReplyCount)) + ` 个答案">` + strconv.Itoa(int(v.ReplyCount)) + `</span>`
						} else if v.ReplyCount == 0 {
							output = output + `<span class="answer" title="0 个答案">0</span>`
						} else {
							output = output + `<span class="answer answered" title="` + strconv.Itoa(int(v.ReplyCount)) + ` 个答案">` + strconv.Itoa(int(v.ReplyCount)) + `</span>`
						}

						if v.Hotvote == 0 {
							output = output + `<span class="vote" title="0 个投票">0</span>`
						} else {
							output = output + `<span class="vote voted" title="` + strconv.Itoa(int(v.Hotvote)) + ` 个投票">` + strconv.Itoa(int(v.Hotvote)) + `</span>`
						}
						output = output + `</div><div class="p-summary">`
						avatar := ""
						if usr, err := model.GetUser(v.Uid); err == nil && usr != nil {
							avatar = helper.Gravatar(usr.Email, 40)
						}
						if avatar == "" {
							output = output + `<a class="author" data-toggle="tooltip" data-placement="bottom" rel="tooltip" href="###" title="&bull; ` + v.Author + ` &bull;">
			               <img class="avatar-40" src="http://sfault-avatar.b0.upaiyun.com/262/496/2624967969-1030000000395062_medium40" alt="` + v.Author + `" />
			           </a>`
						} else {
							output = output + `<a class="author" data-toggle="tooltip" data-placement="bottom" rel="tooltip" href="###/user/` + v.Author + `/" title="&bull; ` + v.Author + ` &bull;">
			               <img class="avatar-40" src="` + avatar + `" alt="` + v.Author + `" />
			           </a>`
						}

						output = output + `
			           <h2>
			               <a href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">` + v.Title + `</a>
			           </h2>
			           <div class="meta">
			               <span class="views"> <i class="i-view"></i>
			                   ` + strconv.Itoa(int(v.Views)) + ` 次浏览
			               </span>
			               &nbsp;`

						if v.Tags != "" {
							output = output + `<ul class="meta-tags"><li><i class="i-tag"></i></li>`
							tags := helper.Tags(v.Tags, ",")
							itags := len(tags)

							for _, tag := range tags {
								itags = itags - 1
								if itags == 0 {
									//等于0则不添加逗号
									output = output + `<li><a data-tid="` + strconv.Itoa(int(v.Id)) + `" href="/tag/` + tag + `/">` + tag + `</a></li>`

								} else {
									output = output + `<li><a data-tid="` + strconv.Itoa(int(v.Id)) + `" href="/tag/` + tag + `/">` + tag + `</a> , </li>`

								}
							}
							output = output + `</ul>`
						}
						output = output + `&nbsp;<span class="datetime"><i class="i-time"></i>` + " " + v.Author + " " + helper.TimeSince(v.Created) + `提问` + `</span></div></div></article>`
					}
					self.Data["questions"] = output

				}

			}

			if k := self.GetString("keyword"); k != "" {
				self.Data["search_keyword"] = k
			} else {
				self.Data["search_keyword"] = keyword
			}

			self.Data["pagesbar"] = helper.Pagesbar("/search/", keyword, rcs, pages, pageout, beginnum, endnum, 0)
		} else {
			fmt.Println("SearchQuestion errors:", err)
			return
		}

		self.Data["replys_8s"] = model.GetAnswersByPid(0, 1, 0, 8, "id")

		//侧栏九宫格推荐榜单
		//根据用户的关键词推荐
		/*
			nds, ndserr := model.SearchNode(keyword, 0, 9, "hotness")
			cats, catserr := model.SearchCategory(keyword, 0, 9, "hotness")
			//如果在节点找到关键词
			if (ndserr == catserr) && (ndserr == nil) {

				output_start := `<ul class="widgets-popular widgets-similar clx">`
				output := ""
				i := 0
				if len(*nds) >= len(*cats) && len(*nds) > 0 {
					for _, v := range *nds {

						if tps := model.GetTopicsByNid(v.Id, 0, 1, 0, "hotness"); len(*tps) > 0 {

							for _, v := range *tps {

								i += 1
								if i == 3 {
									output = output + `<li class="similar similar-third">`
									i = 0
								} else {
									output = output + `<li class="similar">`
								}
								output = output + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">
													<img src="` + v.ThumbnailsSmall + `" wdith="70" height="70" />
												</a>
											</li>`
							}
						}

					}
				} else if len(*cats) > len(*nds) && len(*cats) > 0 {
					for _, v := range *cats {

						if tps := model.GetTopicsByCid(v.Id, 0, 1, 0, "hotness"); len(*tps) > 0 {

							for _, v := range *tps {

								i += 1
								if i == 3 {
									output = output + `<li class="similar similar-third">`
									i = 0
								} else {
									output = output + `<li class="similar">`
								}
								output = output + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">
													<img src="` + v.ThumbnailsSmall + `" wdith="70" height="70" />
												</a>
											</li>`
							}
						}

					}
				}
				output_end := "</ul>"
				if len(output) > 0 {
					output = output_start + output + output_end
					self.Data["topic_hotness_9_module"] = template.HTML(output)
				} else {
					self.Data["topic_hotness_9_module"] = nil
				}
			}
		*/

		//侧栏九宫格推荐榜单
		//先行取出最热门的9个节点 然后根据节点获取该节点下最热门的话题
		/*
			if nd, err := model.GetNodes(0, 9, "hotness"); err == nil {
				if len(*nd) > 0 {
					for _, v := range *nd {

						i := 0
						output_start := `<ul class="widgets-popular widgets-similar clx">`
						output := ""
						if tps := model.GetTopicsByNid(v.Id, 0, 1, 0, "hotness"); err == nil {

							if len(*tps) > 0 {
								for _, v := range *tps {

									i += 1
									if i == 3 {
										output = output + `<li class="similar similar-third">`
										i = 0
									} else {
										output = output + `<li class="similar">`
									}
									output = output + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">
													<img src="` + v.ThumbnailsSmall + `" wdith="70" height="70" />
												</a>
											</li>`
								}
							}
						}
						output_end := "</ul>"
						if len(output) > 0 {
							output = output_start + output + output_end
							self.Data["topic_hotness_9_module"] = template.HTML(output)
						} else {
							self.Data["topic_hotness_9_module"] = nil
						}

					}
				}
			} else {
				fmt.Println("节点数据查询出错", err)
			}
		*/
	} else {
		self.Redirect("/", 302)
	}

}
Ejemplo n.º 4
0
func (self *MainHandler) Get() {
	//fmt.Println("im MainHandler")
	self.Data["catpage"] = "home"
	self.TplNames = "sdc/main.html"

	ipage, _ := self.GetInt(":page")
	page := int(ipage)

	tab := template.HTMLEscapeString(strings.TrimSpace(self.GetString(":tab")))

	url := "/"
	if tab == "lastest" {
		url = "/lastest/"
		tab = "id"
		self.Data["tab"] = "lastest"
	} else if tab == "hotness" {
		url = "/hotness/"
		tab = "hotness"
		self.Data["tab"] = "hotness"
	} else if tab == "unanswered" {
		url = "/unanswered/"
		tab = "unanswered"
		self.Data["tab"] = "unanswered"
	} else {
		url = "/lastest/"
		tab = "id"
		self.Data["tab"] = "lastest"
	}

	pagesize := 30
	results_count, err := model.GetQuestionsCount(0, pagesize, tab)
	if err != nil {
		return
	}
	pages, page, beginnum, endnum, offset := helper.Pages(int(results_count), page, pagesize)
	/*
	   <article class="post" id="q-1010000000444736">
	       <div class="status">
	           <span class="answer answered" title="18 个答案">18</span>
	           <span class="vote voted" title="3 个投票">3</span>
	       </div>
	       <div class="p-summary">
	           <a class="author" data-toggle="tooltip" data-placement="bottom" rel="tooltip" href="http://segmentfault.com/u/tonyx" title="TonyX &bull; 658">
	               <img class="avatar-40" src="http://sfault-avatar.b0.upaiyun.com/262/496/2624967969-1030000000395062_medium40" alt="TonyX" />
	           </a>
	           <h2>
	               <a href="http://segmentfault.com/q/1010000000444736" title="你最喜欢的开发工具是什么?">你最喜欢的开发工具是什么?</a>
	           </h2>
	           <div class="meta">
	               <span class="views"> <i class="i-view"></i>
	                   912 次浏览
	               </span>
	               &nbsp;
	               <ul class="meta-tags">
	                   <li> <i class="i-tag"></i>
	                   </li>
	                   <li>
	                       <a data-tid="1040000000090473" href="/t/ide">ide</a>
	                   </li>
	               </ul>
	               &nbsp;
	               <span class="datetime">
	                   <i class="i-time"></i>
	                   17分钟前
	               </span>
	           </div>
	       </div>
	   </article>
	*/
	if qts, err := model.GetQuestions(offset, pagesize, tab); err == nil {
		results_count := len(*qts)
		if results_count > 0 {
			i := 1
			output := ""
			for _, v := range *qts {

				i += i

				output = output + `<article class="post" id="` + strconv.Itoa(int(v.Id)) + `"><div class="status">`

				if v.Ctype == 2 {
					output = output + `<span class="answer answered-accepted" title="` + strconv.Itoa(int(v.ReplyCount)) + ` 个答案">` + strconv.Itoa(int(v.ReplyCount)) + `</span>`
				} else if v.Ctype == -1 {
					output = output + `<span class="answer answered closed" title="` + strconv.Itoa(int(v.ReplyCount)) + ` 个答案">` + strconv.Itoa(int(v.ReplyCount)) + `</span>`
				} else if v.ReplyCount == 0 {
					output = output + `<span class="answer" title="0 个答案">0</span>`
				} else {
					output = output + `<span class="answer answered" title="` + strconv.Itoa(int(v.ReplyCount)) + ` 个答案">` + strconv.Itoa(int(v.ReplyCount)) + `</span>`
				}

				if v.Hotvote == 0 {
					output = output + `<span class="vote" title="0 个投票">0</span>`
				} else {
					output = output + `<span class="vote voted" title="` + strconv.Itoa(int(v.Hotvote)) + ` 个投票">` + strconv.Itoa(int(v.Hotvote)) + `</span>`
				}
				output = output + `</div><div class="p-summary">`
				avatar := ""
				if usr, err := model.GetUser(v.Uid); err == nil && usr != nil {
					avatar = helper.Gravatar(usr.Email, 40)
				}
				if avatar == "" {
					output = output + `<a class="author" data-toggle="tooltip" data-placement="bottom" rel="tooltip" href="###" title="&bull; ` + v.Author + ` &bull;">
	               <img class="avatar-40" src="http://sfault-avatar.b0.upaiyun.com/262/496/2624967969-1030000000395062_medium40" alt="` + v.Author + `" />
	           </a>`
				} else {
					output = output + `<a class="author" data-toggle="tooltip" data-placement="bottom" rel="tooltip" href="###/user/` + v.Author + `/" title="&bull; ` + v.Author + ` &bull;">
	               <img class="avatar-40" src="` + avatar + `" alt="` + v.Author + `" />
	           </a>`
				}

				output = output + `
	           <h2>
	               <a href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">` + v.Title + `</a>
	           </h2>
	           <div class="meta">
	               <span class="views"> <i class="i-view"></i>
	                   ` + strconv.Itoa(int(v.Views)) + ` 次浏览
	               </span>
	               &nbsp;`

				if v.Tags != "" {
					output = output + `<ul class="meta-tags"><li><i class="i-tag"></i></li>`
					tags := helper.Tags(v.Tags, ",")
					itags := len(tags)

					for _, tag := range tags {
						itags = itags - 1
						if itags == 0 {
							//等于0则不添加逗号
							output = output + `<li><a data-tid="` + strconv.Itoa(int(v.Id)) + `" href="/tag/` + tag + `/">` + tag + `</a></li>`

						} else {
							output = output + `<li><a data-tid="` + strconv.Itoa(int(v.Id)) + `" href="/tag/` + tag + `/">` + tag + `</a> , </li>`

						}
					}
					output = output + `</ul>`
				}
				output = output + `&nbsp;<span class="datetime"><i class="i-time"></i>` + " " + v.Author + " " + helper.TimeSince(v.Created) + `提问` + `</span></div></div></article>`
			}
			self.Data["questions"] = output
			self.Data["pagesbar"] = helper.Pagesbar(url, "", results_count, pages, page, beginnum, endnum, 0)
		}

	} else {
		fmt.Println("首页推荐榜单 数据查询出错", err)
	}

	self.Data["replys_8s"] = model.GetAnswersByPid(0, 1, 0, 8, "id")

	//侧栏九宫格推荐榜单
	//先行取出最热门的9个节点 然后根据节点获取该节点下最热门的话题
	/*
		if nd, err := model.GetNodes(0, 9, "hotness"); err == nil {
			if len(*nd) > 0 {
				for _, v := range *nd {

					i := 0
					output_start := `<ul class="widgets-popular widgets-similar clx">`
					output := ""
					if qts := model.GetTopicsByNid(v.Id, 0, 1, 0, "hotness"); err == nil {

						if len(*qts) > 0 {
							for _, v := range *qts {

								i += 1
								if i == 3 {
									output = output + `<li class="similar similar-third">`
									i = 0
								} else {
									output = output + `<li class="similar">`
								}
								output = output + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">
													<img src="` + v.ThumbnailsSmall + `" wdith="70" height="70" />
												</a>
											</li>`
							}
						}
					}
					output_end := "</ul>"
					if len(output) > 0 {
						output = output_start + output + output_end
						self.Data["topic_hotness_9_module"] = template.HTML(output)
					} else {
						self.Data["topic_hotness_9_module"] = nil
					}

				}
			}
		} else {
			fmt.Println("节点数据查询出错", err)
		}
	*/

	//侧栏九宫格推荐榜单
	//根据最热的1个分类查找该分类下级9个话题
	/*
		if cats, err := model.GetCategorys(0, 1, "hotness"); err == nil && len(cats) > 0 {
			for _, v := range cats {
				output_start := `<ul class="widgets-popular widgets-similar clx">`
				output := ""
				i := 0
				//根据CID 获取同分类下的最热的9个话题
				if qts := model.GetTopicsByCid(v.Id, 0, 9, 0, "hotness"); len(*qts) > 0 {

					for _, v := range *qts {

						i += 1
						if i == 3 {
							output = output + `<li class="similar similar-third">`
							i = 0
						} else {
							output = output + `<li class="similar">`
						}
						output = output + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">
													<img src="` + v.ThumbnailsSmall + `" wdith="70" height="70" />
												</a>
											</li>`
					}
				}
				output_end := "</ul>"

				if len(output) > 0 {
					output = output_start + output + output_end
					self.Data["topic_hotness_9_module"] = template.HTML(output)
				} else {
					self.Data["topic_hotness_9_module"] = nil
				}
			}

		}
	*/

	//根据最热的1个节点查找该节点的上级分类下的9个话题
	/*
		if nd, err := model.GetNodes(0, 1, "hotness"); err == nil && len(*nd) > 0 {
			for _, v := range *nd {

				output_start := `<ul class="widgets-popular widgets-similar clx">`
				output := ""
				i := 0
				//根据节点的上级PID 获取同分类下的最热话题
				if qts := model.GetQuestionsByCid(v.Pid, 0, 9, 0, "hotness"); len(*qts) > 0 {

					for _, v := range *qts {

						i += 1
						if i == 3 {
							output = output + `<li class="similar similar-third">`
							i = 0
						} else {
							output = output + `<li class="similar">`
						}
						output = output + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">
														<img src="` + v.ThumbnailsSmall + `" wdith="70" height="70" />
													</a>
												</li>`
					}
				}
				output_end := "</ul>"

				if len(output) > 0 {
					output = output_start + output + output_end
					self.Data["topic_hotness_9_module"] = template.HTML(output)
				} else {
					self.Data["topic_hotness_9_module"] = nil
				}

			}
		}
	*/
}
Ejemplo n.º 5
0
func (self *SignupHandler) Post() {

	self.TplNames = "sdc/signup.html"

	flash := beego.NewFlash()
	email := strings.TrimSpace(strings.ToLower(self.GetString("email")))
	username := strings.ToLower(self.GetString("username"))
	password := self.GetString("password")
	repassword := self.GetString("repassword")

	if password == "" {
		flash.Error("密码为空~")
		flash.Store(&self.Controller)

		return

	}

	if password != repassword {
		flash.Error("两次密码不匹配~")
		flash.Store(&self.Controller)

		return

	}

	if helper.CheckPassword(password) == false {
		flash.Error("密码含有非法字符或密码过短(至少4~30位密码)!")
		flash.Store(&self.Controller)

		return

	}

	if username == "" {
		flash.Error("用户名是为永久性设定,不能少于4个字或多于30个字,请慎重考虑,不能为空~")
		flash.Store(&self.Controller)

		return

	}

	if helper.CheckUsername(username) == false {
		flash.Error("用户名是为永久性设定,不能少于4个字或多于30个字,请慎重考虑,不能为空~")
		flash.Store(&self.Controller)

		return
	}

	if helper.CheckEmail(email) == false {
		flash.Error("Email格式不合符规格~")
		flash.Store(&self.Controller)

		return

	}

	if usrinfo, err := model.GetUserByEmail(email); usrinfo != nil {

		flash.Error("此账号不能使用~")
		flash.Store(&self.Controller)

		return

	} else if err != nil {

		flash.Error("检索账号期间出错~")
		flash.Store(&self.Controller)

		return
	}

	if usrid, err := model.AddUser(email, username, "", "", helper.Encrypt_hash(password, nil), 1); err != nil {
		flash.Error("用户注册信息写入数据库时发生错误~")
		flash.Store(&self.Controller)

		return

	} else {

		if usrinfo, err := model.GetUser(usrid); err == nil {

			//注册账号成功,以下自动登录并设置session
			self.SetSession("userid", usrid)
			self.SetSession("username", usrinfo.Username)
			self.SetSession("userrole", usrinfo.Role)
			self.SetSession("useremail", usrinfo.Email)
			self.SetSession("usercontent", usrinfo.Content)

			//signbar的值为 0则关闭提示栏  1则显示提示栏
			self.Ctx.SetCookie("signbar", "1", 31536000, "/")

			//设置cookie

			//设置提示栏cookie标记
			//signbar的值为 0则关闭提示栏  1则显示提示栏
			self.Ctx.SetCookie("signbar", "0", 31536000, "/")

			flash.Notice("账号登录成功~")
			flash.Store(&self.Controller)

			//session 写入后直接跳到首页
			self.Redirect("/", 302)

		} else {

			flash.Notice("注册账号成功,请手动登录~")
			flash.Store(&self.Controller)

			//注册成功后直接跳转到登录页
			self.Redirect("/signin/", 302)

		}

	}

}