示例#1
0
func (self *AvatarHandler) Get() {

	username := self.GetString(":username")
	filename := self.GetString(":filename")

	if usr, e := model.GetUserByUsername(username); e == nil && usr != nil && username != "" && filename != "" {

		if filename == "72x72" {
			if usr.Avatar != "" {

				self.Redirect(usr.Avatar, 301)
			} else {
				self.Redirect("/static/img/usr_72x72.png", 302)
			}
		} else {
			self.Redirect("/static/img/usr_72x72.png", 302)
		}
	} else {
		self.Abort("404")
	}
}
示例#2
0
func (self *TimelineHandler) Get() {

	self.TplNames = "timeline.html"
	username := self.GetString(":username")
	uid, _ := self.GetInt(":userid")

	switch {
	case username != "":

		if usr, err := model.GetUserByUsername(username); usr != nil && err == nil {
			if tls, err := model.GetTimelines(0, 0, "created", usr.Id); err == nil {
				self.Data["timelines_username"] = username
				self.Data["timelines"] = *tls
				return
			}

		} else {
			self.Redirect("/timeline/", 302)
		}

	case uid != 0:
		if usr, err := model.GetUser(uid); usr != nil && err == nil {
			if tls, err := model.GetTimelines(0, 0, "hotness", usr.Id); err == nil {
				self.Data["timelines"] = *tls
				return
			}
		} else {
			self.Redirect("/timeline/", 302)
		}
	case uid == 0 && username == "": //首页
		if tls, err := model.GetTimelines(0, 0, "hotness", 0); err == nil {
			self.Data["timelines"] = *tls
			return
		} else {
			self.Redirect("/timeline/", 302)
		}
	default:
		self.Redirect("/timeline/", 302)
	}
}
示例#3
0
文件: NewReply.go 项目: rose312/mzr
func (self *NewReplyHandler) Post() {
	tid, _ := self.GetInt(":tid")
	sess_userid, _ := self.GetSession("userid").(int64)

	author := self.GetString("author")
	email := self.GetString("email")
	website := self.GetString("website")
	rc := self.GetString("comment")

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

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

					//如果回应内容中有@通知 则处理以下事件
					if users := helper.AtUsers(rc); len(users) > 0 {
						if tp, err := model.GetTopic(tid); 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='/topic/"+self.GetString(":tid")+"/#reply-"+strconv.Itoa(int(rid))+"'>"+tp.Title+"</a>]",
										tp.Cid, tp.Nid, u.Id, usr.Username, usr.Content)

								}

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

						}
					}

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

	}

}
示例#4
0
func (self *TimelineHandler) Post() {

	self.TplNames = "timeline.html"
	sess_userid, _ := self.GetSession("userid").(int64)
	sess_username, _ := self.GetSession("username").(string)

	tl := self.GetString("timeline")

	//不等于0,即是注册用户或管理层
	if sess_userid != 0 {
		if tl != "" {
			//获取当前用户信息
			if usr, err := model.GetUser(sess_userid); usr != nil && err == nil {

				//前一条是记录发送者自己的timeline  所以这里的接受者是自己  记录完自己的timeline后  再处理自己timeline的内容里的@通知
				if lid, err := model.AddTimeline("", tl, 0, 0, sess_userid, usr.Username, usr.Content); err != nil {
					fmt.Println("#", lid, ":", err)
				} else {
					//如果 内容tl中有@通知 则处理以下事件
					if users := helper.AtUsers(tl); len(users) > 0 {
						//todo := []string{}
						//被通知列表 k是uid v是username
						todolist := map[int64]string{}
						for _, v := range users {
							//判断被通知之用户名是否真实存在
							if u, e := model.GetUserByUsername(v); e == nil && u != nil {
								//存在的则加入待操作列
								//todo = append(todo, v)
								todolist[u.Id] = u.Username
								//替换被通知用户的用户名带上用户主页链接
								tl = strings.Replace(tl, "@"+v,
									"<a href='/user/"+u.Username+"/' title='"+u.Nickname+"' target='_blank'><span>@</span><span>"+u.Username+"</span></a>", -1)

								//发送通知内容到被通知用户的 时光记录 注意这里的uid不再是sess_userid 而是u.Id
								model.AddTimeline(usr.Username+"提到了你~",
									tl+"[<a href='/user/"+usr.Username+"/#timeline-"+strconv.Itoa(int(lid))+"'>"+usr.Username+"</a>]", 0, 0, u.Id, usr.Username, usr.Content)

							}

						}
						//如果有@通知操作 则重新替换一次发送者已存档的内容
						if len(todolist) > 0 {
							model.SetTimelineContentByRid(lid, tl)
						}
					}

					//处理@link
					if atpagez, _ := helper.AtPages(tl); len(atpagez) > 0 {
						tid := int64(0)
						if tid, tl, err = model.AtLinksPostImagesOnTopic(tl); err == nil {

							model.SetTimelineContentByRid(lid, tl+" <a href='/topic/"+strconv.Itoa(int(tid))+"/' target='_blank'>[#美图合辑("+strconv.Itoa(int(tid))+")#]</a>")
						}
					}
					self.Redirect("/user/"+sess_username+"/#timeline-"+strconv.Itoa(int(lid)), 302)
					return
				}
			}
			self.Redirect("/user/"+sess_username+"/", 302)
		} else {
			self.Redirect("/timeline/", 302)
		}
	} else {
		self.Redirect("/timeline/", 302)

	}

}