Example #1
0
// 增加链接的点击统计数
func link_incClick(ctx *goku.HttpContext) goku.ActionResulter {
	var success bool
	var errorMsgs string
	id := ctx.Get("id")
	if id == "" {
		errorMsgs = "参数错误"
	} else {
		linkId, err := strconv.ParseInt(id, 10, 64)
		if err == nil && linkId > 0 {
			_, err = models.Link_IncClickCount(linkId, 1)
			if err == nil {
				success = true
			}
		}
		if err != nil {
			goku.Logger().Error(err.Error())
			errorMsgs = err.Error()
		}
	}

	r := map[string]interface{}{
		"success": success,
		"errors":  errorMsgs,
	}
	return ctx.Json(r)
}
Example #2
0
// 加载更多link
func discover_loadMoreLink(ctx *goku.HttpContext) goku.ActionResulter {
	page, err := strconv.Atoi(ctx.Get("page"))
	success, hasmore := false, false
	errorMsgs, html := "", ""
	if err == nil && page > 1 {
		ot := ctx.Get("o")
		if ot == "" {
			ot = "hot"
		}
		dt, _ := strconv.Atoi(ctx.Get("dt"))
		links, _ := models.LinkForHome_GetByPage(ot, dt, page, golink.PAGE_SIZE)
		if links != nil && len(links) > 0 {
			ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
			vr := ctx.RenderPartial("loadmorelink", nil)
			vr.Render(ctx, vr.Body)
			html = vr.Body.String()
			hasmore = len(links) >= golink.PAGE_SIZE
		}
		success = true
	} else {
		errorMsgs = "参数错误"
	}
	r := map[string]interface{}{
		"success": success,
		"errors":  errorMsgs,
		"html":    html,
		"hasmore": hasmore,
	}
	return ctx.Json(r)
}
Example #3
0
func (f *ThirdPartyBindFilter) OnActionExecuting(ctx *goku.HttpContext) (ar goku.ActionResulter, err error) {

	sessionIdBase, err := ctx.Request.Cookie(config.ThirdPartyCookieKey)
	if err != nil || len(sessionIdBase.Value) == 0 {
		ar = ctx.NotFound("no user binding context found.")
		return
	}
	ctx.Data["thirdPartySessionIdBase"] = sessionIdBase.Value

	profileSessionId := models.ThirdParty_GetThirdPartyProfileSessionId(sessionIdBase.Value)
	profile := models.ThirdParty_GetThirdPartyProfileFromSession(profileSessionId)

	if profile == nil {
		ar = ctx.NotFound("no user binding context found.")
		return
	}

	ctx.ViewData["profile"] = profile
	if len(profile.Email) > 0 {
		sensitiveInfoRemovedEmail := utils.GetSensitiveInfoRemovedEmail(profile.Email)
		ctx.ViewData["directCreateEmail"] = sensitiveInfoRemovedEmail
	}

	var profileShow struct {
		Avatar bool
		Link   bool
		Name   string
	}
	profileShow.Avatar = (len(profile.AvatarUrl) > 0)
	profileShow.Link = (len(profile.Link) > 0)
	profileShow.Name = profile.GetDisplayName()
	ctx.ViewData["profileShow"] = profileShow

	return
}
Example #4
0
// 查看粉丝
func user_Fans(ctx *goku.HttpContext) goku.ActionResulter {

	userId, _ := strconv.ParseInt(ctx.RouteData.Params["id"], 10, 64)
	var user *models.User
	if userId > 0 {
		user = models.User_GetById(userId)
	} else {
		if u, ok := ctx.Data["user"]; ok {
			user = u.(*models.User)
			ctx.ViewData["UserMenu"] = "um-fans"
		}
	}

	if user == nil {
		ctx.ViewData["errorMsg"] = "用户不存在"
		return ctx.Render("error", nil)
	}

	page, pagesize := utils.PagerParams(ctx.Request)
	followers, _ := models.UserFollow_Followers(user.Id, page, pagesize)

	ctx.ViewData["Followers"] = models.User_ToVUsers(followers, ctx)
	ctx.ViewData["HasMoreFollowers"] = len(followers) >= pagesize
	return ctx.View(models.User_ToVUser(user, ctx))

}
Example #5
0
//为别的平台用户写cookie
func setCookieForOtherPlatformUser(userId int64, email string, seconds int, ctx *goku.HttpContext) {
	//注册成功,写cookie
	now := time.Now()
	h := md5.New()
	h.Write([]byte(fmt.Sprintf("%v-%v", email, now.Unix())))
	ticket := fmt.Sprintf("%x_%v", h.Sum(nil), now.Unix())
	expires := now.Add(time.Duration(seconds) * time.Second)
	redisClient := models.GetRedis()
	defer redisClient.Quit()
	err := redisClient.Set(ticket, userId)
	if err != nil {
		goku.Logger().Errorln(err.Error())
	} else {
		_, err = redisClient.Expireat(ticket, expires.Unix())
		if err != nil {
			goku.Logger().Errorln(err.Error())
		}
		c := &http.Cookie{
			Name:     "_glut",
			Value:    ticket,
			Expires:  expires,
			Path:     "/",
			HttpOnly: true,
		}
		ctx.SetCookie(c)
	}
}
Example #6
0
// 删除link
func link_ajaxDel(ctx *goku.HttpContext) goku.ActionResulter {
	var errs string
	var ok = false

	linkId, err := strconv.ParseInt(ctx.RouteData.Params["id"], 10, 64)
	if err == nil {
		user := ctx.Data["user"].(*models.User)
		link, err := models.Link_GetById(linkId)
		if err == nil {
			// 只可以删除自己的链接
			if link.UserId == user.Id {
				err = models.Link_DelById(linkId)
				if err == nil {
					ok = true
				}
			} else {
				errs = "不允许的操作"
			}
		}
	}

	if err != nil {
		errs = err.Error()
	}

	r := map[string]interface{}{
		"success": ok,
		"errors":  errs,
	}

	return ctx.Json(r)
}
Example #7
0
func admin_index(ctx *goku.HttpContext) goku.ActionResulter {
	var db *goku.MysqlDB = models.GetDB()
	defer db.Close()

	linkCount, err := db.Count("link", "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["linkCount"] = linkCount

	userCount, err := db.Count("user", "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["userCount"] = userCount

	topicCount, err := db.Count("topic", "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["topicCount"] = topicCount

	commentCount, err := db.Count("comment", "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["commentCount"] = commentCount

	return ctx.View(nil)
}
Example #8
0
func ThirdParty_SaveThirdPartyProfileToSession(
	ctx *goku.HttpContext,
	profile *ThirdPartyUserProfile) (err error) {

	providerName := profile.ProviderName
	sessionKeyBase := thirdParty_GetSessionKeyBase(providerName, profile.Id)
	profileSessionId := ThirdParty_GetThirdPartyProfileSessionId(sessionKeyBase)
	expires := time.Now().Add(time.Duration(3600) * time.Second)

	b, _ := json.Marshal(profile)
	s := string(b)
	err = SaveItemToSession(profileSessionId, s, expires)
	if err != nil {
		return
	}

	c := &http.Cookie{
		Name:     config.ThirdPartyCookieKey,
		Value:    sessionKeyBase,
		Expires:  expires,
		Path:     "/",
		HttpOnly: true,
	}
	ctx.SetCookie(c)

	return
}
Example #9
0
/**
 * 上传话题图片
 */
func actionUpimg(ctx *goku.HttpContext) goku.ActionResulter {
	var ok = false
	var errs string
	topicId, err := strconv.ParseInt(ctx.RouteData.Params["id"], 10, 64)
	if err == nil && topicId > 0 {
		imgFile, header, err2 := ctx.Request.FormFile("topic-image")
		err = err2
		defer func() {
			if imgFile != nil {
				imgFile.Close()
			}
		}()

		if err == nil {
			ext := path.Ext(header.Filename)
			if acceptFileTypes.MatchString(ext[1:]) == false {
				errs = "错误的文件类型"
			} else {
				sid := strconv.FormatInt(topicId, 10)
				saveDir := path.Join(ctx.RootDir(), golink.PATH_IMAGE_AVATAR, "topic", sid[len(sid)-2:])
				err = os.MkdirAll(saveDir, 0755)
				if err == nil {
					saveName := fmt.Sprintf("%v_%v%v",
						strconv.FormatInt(topicId, 36),
						strconv.FormatInt(time.Now().UnixNano(), 36),
						ext)
					savePath := path.Join(saveDir, saveName)
					var f *os.File
					f, err = os.Create(savePath)
					defer f.Close()
					if err == nil {
						_, err = io.Copy(f, imgFile)
						if err == nil {
							// update to db
							_, err2 := models.Topic_UpdatePic(topicId, path.Join(sid[len(sid)-2:], saveName))
							err = err2
							if err == nil {
								ok = true
							}
						}
					}
				}
			}
		}
	} else if topicId < 1 {
		errs = "参数错误"
	}

	if err != nil {
		errs = err.Error()
	}
	r := map[string]interface{}{
		"success": ok,
		"errors":  errs,
	}
	return ctx.Json(r)
}
Example #10
0
func loginThirdPartyUser(u *models.ThirdPartyUser, ctx *goku.HttpContext) goku.ActionResulter {
	user := u.User()
	userId, email, expireInSeconds := user.Id, user.Email, 24*3600
	/*if !u.TokenExpireTime.IsZero() {
	    utcNow := time.Now().UTC()
	    expireInSeconds = int(u.TokenExpireTime.Sub(utcNow) / time.Second)
	}*/
	setCookieForOtherPlatformUser(userId, email, expireInSeconds, ctx)

	return ctx.Redirect("/")
}
Example #11
0
func thirdParty_ClearThirdPartyProfileFromSession(ctx *goku.HttpContext) {
	sessionIdBase := ctx.Data["thirdPartySessionIdBase"].(string)
	sessinId := ThirdParty_GetThirdPartyProfileSessionId(sessionIdBase)
	RemoveItemFromSession(sessinId)

	c := &http.Cookie{
		Name:    config.ThirdPartyCookieKey,
		Expires: time.Now().Add(-10 * time.Second),
		Path:    "/",
	}
	ctx.SetCookie(c)
}
Example #12
0
func admin_users(ctx *goku.HttpContext) goku.ActionResulter {
	page, pagesize := utils.PagerParams(ctx.Request)
	users, total, err := models.User_GetList(page, pagesize, "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["UserList"] = users
	ctx.ViewData["UserCount"] = total
	ctx.ViewData["Page"] = page
	ctx.ViewData["Pagesize"] = pagesize
	return ctx.View(nil)
}
Example #13
0
func admin_comments(ctx *goku.HttpContext) goku.ActionResulter {
	page, pagesize := utils.PagerParams(ctx.Request)
	comments, total, err := models.Comment_GetByPage(page, pagesize, "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["CommentList"] = comments
	ctx.ViewData["CommentCount"] = total
	ctx.ViewData["Page"] = page
	ctx.ViewData["Pagesize"] = pagesize
	return ctx.View(nil)
}
Example #14
0
func admin_links(ctx *goku.HttpContext) goku.ActionResulter {
	page, pagesize := utils.PagerParams(ctx.Request)
	links, total, err := models.Link_GetByPage(page, pagesize, "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["LinkList"] = links
	ctx.ViewData["TotalLinks"] = total
	ctx.ViewData["Page"] = page
	ctx.ViewData["Pagesize"] = pagesize
	return ctx.View(nil)
}
Example #15
0
func admin_topics(ctx *goku.HttpContext) goku.ActionResulter {
	page, pagesize := utils.PagerParams(ctx.Request)
	topics, total, err := models.Topic_GetByPage(page, pagesize, "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["TopicList"] = topics
	ctx.ViewData["TopicCount"] = total
	ctx.ViewData["Page"] = page
	ctx.ViewData["Pagesize"] = pagesize
	ctx.ViewData["TabName"] = "topics"
	return ctx.View(nil)
}
Example #16
0
// 加载更多的搜索link
func link_search_loadMore(ctx *goku.HttpContext) goku.ActionResulter {
	term, _ := url.QueryUnescape(ctx.Get("term"))
	page, err := strconv.Atoi(ctx.Get("page"))
	success, hasmore := false, false
	errorMsgs, html := "", ""
	if err == nil && page > 1 {
		ls := utils.LinkSearch{}
		searchResult, err := ls.SearchLink(term, page, golink.PAGE_SIZE)
		if err == nil && searchResult.TimedOut == false && searchResult.HitResult.HitArray != nil {
			if len(searchResult.HitResult.HitArray) > 0 {
				links, _ := models.Link_GetByIdList(searchResult.HitResult.HitArray)
				if links != nil && len(links) > 0 {
					ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
					vr := ctx.RenderPartial("loadmorelink", nil)
					vr.Render(ctx, vr.Body)
					html = vr.Body.String()
					hasmore = len(links) >= golink.PAGE_SIZE
				}
			}
			success = true
		}
	} else {
		errorMsgs = "参数错误"
	}
	r := map[string]interface{}{
		"success": success,
		"errors":  errorMsgs,
		"html":    html,
		"hasmore": hasmore,
	}
	return ctx.Json(r)
}
Example #17
0
/**
 * 提交一个链接并保存到数据库
 */
func link_submit(ctx *goku.HttpContext) goku.ActionResulter {

	f := forms.CreateLinkSubmitForm()
	f.FillByRequest(ctx.Request)

	var resubmit bool
	if ctx.Get("resubmit") == "true" {
		resubmit = true
	}
	user := ctx.Data["user"].(*models.User)
	success, linkId, errorMsgs, _ := models.Link_SaveForm(f, user.Id, resubmit)

	if success {
		go addLinkForSearch(0, f.CleanValues(), linkId, user.Name) //contextType:0: url, 1:文本   TODO:

		return ctx.Redirect(fmt.Sprintf("/link/%d", linkId))
	} else if linkId > 0 {
		return ctx.Redirect(fmt.Sprintf("/link/%d?already_submitted=true", linkId))
	} else {
		ctx.ViewData["Errors"] = errorMsgs
		ctx.ViewData["Values"] = f.Values()
	}
	return ctx.View(nil)

}
Example #18
0
/**
 * 提交一个链接并保存到数据库
 */
func link_submit(ctx *goku.HttpContext) goku.ActionResulter {

	f := forms.CreateLinkSubmitForm()
	f.FillByRequest(ctx.Request)

	success, linkId, errorMsgs := models.Link_SaveForm(f, (ctx.Data["user"].(*models.User)).Id)

	if success {
		return ctx.Redirect(fmt.Sprintf("/link/%d", linkId))
	} else {
		ctx.ViewData["Errors"] = errorMsgs
		ctx.ViewData["Values"] = f.Values()
	}
	return ctx.View(nil)

}
Example #19
0
/**
 * 提交评论并保存到数据库
 */
func link_ajax_comment(ctx *goku.HttpContext) goku.ActionResulter {

	f := forms.NewCommentSubmitForm()
	f.FillByRequest(ctx.Request)

	var success bool
	var errorMsgs, commentHTML string
	var commentId int64
	if ctx.RouteData.Params["id"] != f.Values()["link_id"] {
		errorMsgs = "参数错误"
	} else {
		var errors []string
		user := ctx.Data["user"].(*models.User)
		success, commentId, errors = models.Comment_SaveForm(f, user.Id)
		if errors != nil {
			errorMsgs = strings.Join(errors, "\n")
		} else {
			linkId, _ := strconv.ParseInt(ctx.RouteData.Params["id"], 10, 64)
			m := f.CleanValues()
			cn := models.CommentNode{}
			cn.Id = commentId
			cn.LinkId = linkId
			cn.UserId = user.Id
			cn.Status = 1
			cn.Content = m["content"].(string)
			cn.ParentId = m["parent_id"].(int64)
			cn.ChildrenCount = 0
			cn.VoteUp = 1
			cn.CreateTime = time.Now()
			cn.UserName = user.Name

			sortType := ""
			var b *bytes.Buffer = new(bytes.Buffer)
			cn.RenderSelfOnly(b, sortType)
			commentHTML = b.String()
			//models.GetPermalinkComment(linkId, commentId, "")
		}
	}
	r := map[string]interface{}{
		"success":     success,
		"errors":      errorMsgs,
		"commentHTML": commentHTML,
	}
	return ctx.Json(r)
}
Example #20
0
/**
 * 收到的评论
 */
func comment_Inbox(ctx *goku.HttpContext) goku.ActionResulter {
	user := ctx.Data["user"].(*models.User)
	page, pagesize := utils.PagerParams(ctx.Request)
	comments, total, err := models.CommentForUser_GetByPage(user.Id, page, pagesize, "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["CommentList"] = comments
	ctx.ViewData["CommentCount"] = total
	ctx.ViewData["Page"] = page
	ctx.ViewData["Pagesize"] = pagesize
	err = models.Remind_Reset(user.Id, models.REMIND_COMMENT)
	if err != nil {
		goku.Logger().Errorln("Reset用户提醒信息数出错:", err.Error())
	}
	return ctx.View(nil)
}
Example #21
0
func userRecoverPreProcess(ctx *goku.HttpContext) (user *models.User, ur *models.UserRecovery, r goku.ActionResulter) {
	queryStrings := ctx.Request.URL.Query()
	token := queryStrings.Get("token")
	userId, _ := strconv.ParseInt(ctx.RouteData.Params["id"], 10, 64)
	ctx.ViewData["recoverPwdToken"] = token

	if ur = models.User_GetActiveRecoveryRequest(userId, token); ur == nil {
		r = ctx.NotFound("invalid token")
		return
	}

	user = models.User_GetById(userId)
	if user == nil {
		ur = nil
		r = ctx.NotFound("user not found")
	}

	return
}
Example #22
0
// 删除comment
func admin_del_comments(ctx *goku.HttpContext) goku.ActionResulter {
	var errs string
	var ok = false

	id, err := strconv.ParseInt(ctx.RouteData.Params["id"], 10, 64)
	if err == nil {
		err = models.Comment_DelById(id)
	}

	if err != nil {
		errs = err.Error()
	} else {
		ok = true
	}
	r := map[string]interface{}{
		"success": ok,
		"errors":  errs,
	}

	return ctx.Json(r)
}
Example #23
0
// 删除link
func admin_del_links(ctx *goku.HttpContext) goku.ActionResulter {
	var errs string
	var ok = false

	linkId, err := strconv.ParseInt(ctx.Get("id"), 10, 64)
	if err == nil {
		err = models.Link_DelById(linkId)
	}

	if err != nil {
		errs = err.Error()
	} else {
		ok = true
	}
	r := map[string]interface{}{
		"success": ok,
		"errors":  errs,
	}

	return ctx.Json(r)
}
Example #24
0
func home_index(ctx *goku.HttpContext) goku.ActionResulter {
	u, ok := ctx.Data["user"]
	if !ok || u == nil {
		return ctx.Redirect("/discover")
	}
	user := u.(*models.User)
	if user.FriendCount+user.FtopicCount < 1 {
		return home_guideForNew(ctx)
	}
	ot := ctx.Get("o")
	if ot == "" {
		ot = "hot"
	}
	ctx.ViewData["Order"] = ot
	links, _ := models.Link_ForUser(user.Id, ot, 1, golink.PAGE_SIZE) //models.Link_GetByPage(1, 20)
	ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
	ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE

	// 最新链接的未读提醒
	if ot == "hot" {
		newestUnreadCount, _ := models.NewestLinkUnread_Friends(user.Id, user.LastReadFriendLinkId)
		ctx.ViewData["NewestUnreadCount"] = models.NewestLinkUnread_ToString(user.Id, newestUnreadCount)
	} else if ot == "time" && links != nil && len(links) > 0 {
		models.NewestLinkUnread_UpdateForUser(user.Id, links[0].Id)
	}

	return ctx.View(nil)
}
Example #25
0
func admin_banUser(ctx *goku.HttpContext) goku.ActionResulter {
	var err error
	var errs string
	var ok = false
	var userId, status int64

	userId, err = strconv.ParseInt(ctx.Get("id"), 10, 64)
	if err == nil {
		status, err = strconv.ParseInt(ctx.Get("status"), 10, 64)
	}
	if err == nil {
		_, err = models.User_Update(userId, map[string]interface{}{"Status": status})
	}

	if err != nil {
		errs = err.Error()
	} else {
		ok = true
	}
	r := map[string]interface{}{
		"success": ok,
		"errors":  errs,
	}

	return ctx.Json(r)
}
Example #26
0
func favorite_loadMoreLink(ctx *goku.HttpContext) goku.ActionResulter {
	page, err := strconv.Atoi(ctx.Get("page"))
	success, hasmore := false, false
	errorMsgs, html := "", ""
	if err == nil && page > 1 {
		user := ctx.Data["user"].(*models.User)

		links := models.FavoriteLink_ByUser(user.Id, page, golink.PAGE_SIZE)
		if links != nil && len(links) > 0 {
			ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
			vr := ctx.RenderPartial("loadmorelink", nil)
			vr.Render(ctx, vr.Body)
			html = vr.Body.String()
			hasmore = len(links) >= golink.PAGE_SIZE
		}
		success = true
	} else {
		errorMsgs = "参数错误"
	}
	r := map[string]interface{}{
		"success": success,
		"errors":  errorMsgs,
		"html":    html,
		"hasmore": hasmore,
	}
	return ctx.Json(r)
}
Example #27
0
// 发现 首页
func discover_index(ctx *goku.HttpContext) goku.ActionResulter {
	ot := ctx.Get("o")
	if ot == "" {
		ot = "hot"
	}
	dt, _ := strconv.Atoi(ctx.Get("dt"))
	ctx.ViewData["Order"] = ot
	links, _ := models.LinkForHome_GetByPage(ot, dt, 1, golink.PAGE_SIZE)
	ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
	ctx.ViewData["TopTab"] = "discover"
	ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE

	// 最新链接的未读提醒
	var userId, lastReadLinkId int64
	unreadCookieName := "newestUnrLinkId"
	u, ok := ctx.Data["user"]
	if ok && u != nil {
		user := u.(*models.User)
		userId = user.Id
		lastReadLinkId = user.LastReadLinkId
	} else {
		// 从Cook读取最后一次阅读的链接id
		cLastReadLinkId, err := ctx.Request.Cookie(unreadCookieName)
		if err == nil {
			lastReadLinkId, _ = strconv.ParseInt(cLastReadLinkId.Value, 10, 64)
		}
	}
	if ot == "hot" {
		newestUnreadCount, _ := models.NewestLinkUnread_All(userId, lastReadLinkId)
		ctx.ViewData["NewestUnreadCount"] = models.NewestLinkUnread_ToString(userId, newestUnreadCount)
	} else if ot == "time" && links != nil && len(links) > 0 {
		if userId > 0 {
			models.NewestLinkUnread_UpdateForAll(userId, links[0].Id)
		} else {
			c := &http.Cookie{
				Name:     unreadCookieName,
				Value:    fmt.Sprintf("%d", links[0].Id),
				Expires:  time.Now().AddDate(0, 1, 0),
				Path:     "/",
				HttpOnly: true,
			}
			ctx.SetCookie(c)
		}
	}

	return ctx.Render("/home/index", nil)
}
Example #28
0
/**
 * 修改话题名称
 */
func admin_topicEditName(ctx *goku.HttpContext) goku.ActionResulter {
	var ok = false
	var errs, name string
	topicId, err := strconv.ParseInt(ctx.Get("id"), 10, 64)
	name = ctx.Request.FormValue("name")
	if err == nil && topicId > 0 && name != "" {
		_, err = models.Topic_UpdateName(topicId, name)
		if err == nil {
			ok = true
		}
	} else if topicId < 1 || name == "" {
		errs = "参数错误"
	}

	if err != nil {
		errs = err.Error()
	}
	r := map[string]interface{}{
		"success": ok,
		"name":    name,
		"errors":  errs,
	}
	return ctx.Json(r)
}
Example #29
0
/**
 * 获取用户信息
 * 用于浮动层
 */
func actionPopupBoxInfo(ctx *goku.HttpContext) goku.ActionResulter {

	topicName := ctx.Get("t")
	topic, _ := models.Topic_GetByName(topicName)

	if topic != nil {
		return ctx.RenderPartial("pop-info", models.Topic_ToVTopic(topic, ctx))
	}
	return ctx.Html("")
}
Example #30
0
// 发现 首页
func discover_index(ctx *goku.HttpContext) goku.ActionResulter {
	ot := ctx.Get("o")
	if ot == "" {
		ot = "hot"
	}
	dt, _ := strconv.Atoi(ctx.Get("dt"))
	ctx.ViewData["Order"] = ot
	links, _ := models.LinkForHome_GetByPage(ot, dt, 1, golink.PAGE_SIZE)
	ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
	ctx.ViewData["TopTab"] = "discover"
	ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE
	return ctx.Render("/home/index", nil)
}