示例#1
0
// add a new topic background attach.
func (c Topic) AddBackground(sid, name, extention, file string) r.Result {
	session := c.Sess.GetSession(sid)
	if session.Id == 0 {
		return c.RenderLogin()
	}

	result, err := modules.NewAttach(c.Db).AddNew(session.SessionVal.UserId, name, extention, file)

	return c.Render(result, err)
}
示例#2
0
// 创建话题.
func (c Topic) AddNew(sid string, content string, keywords string, bg []byte) r.Result {
	session := c.Sess.GetSession(sid)
	if session.Id == 0 {
		return c.RenderLogin()
	}

	attach := &models.Attach{}
	if len(bg) > 0 {
		var err error
		// 尝试上传图片
		uploader := modules.NewAttach(c.Db)
		attach, err = uploader.Upload(c.Request, "bg")
		if err != nil {
			return c.Render(nil, err)
		}
	}

	// 保存topic
	topicModule := modules.NewTopic(c.Db, c.Rc)
	topic, err := topicModule.AddNew(session.SessionVal.UserId, content, keywords, attach)

	return c.Render(topic, err)
}