Example #1
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 #2
0
func (self *BaseCrawler) saveLink(url, title string) (err error) {
	defer func() {
		if err != nil {
			if strings.Index(err.Error(), "Url已经提交过") > -1 {
				goku.Logger().Logln("Crawler saveLink:", err.Error(), url, title)
			} else {
				goku.Logger().Errorln("Crawler saveLink error:", err.Error(), url, title)
			}
		}
	}()
	idCount := len(self.UserIds)
	if idCount < 1 {
		err = errors.New("no user ids")
		return
	}
	userId := self.UserIds[rand.Int63n(int64(idCount))]
	user := models.User_GetById(userId)
	if user == nil || user.Id < 1 {
		err = errors.New("no selected user")
		return
	}

	if strings.Index(url, "news.dbanotes.net") > 0 {
		return nil
	}
	// 移除多余的字符
	if strings.LastIndex(title, ")") == len(title)-1 && strings.Index(title, " (") > 0 {
		title = title[0:strings.LastIndex(title, " (")]
	}

	topics := []string{}
	ltitle := strings.ToLower(title)
	for i := 0; i < lenTopTopics; i++ {
		if strings.Index(ltitle, topTopics[i].NameLower) > -1 {
			if len(topTopics[i].Name) > 1 {
				topics = append(topics, topTopics[i].Name)
			}
		}
	}

	m := map[string]string{
		"title":   title,
		"context": url,
		"topics":  strings.Join(topics, ","),
	}
	f := forms.CreateLinkSubmitForm()
	f.FillByMap(m)

	success, linkId, errMsg, _ := models.Link_SaveForm(f, user.Id, false)

	if success {
		go controllers.AddLinkForSearch(0, f.CleanValues(), linkId, user.Name) //contextType:0: url, 1:文本   TODO:
	} else {
		err = errors.New(strings.Join(errMsg, ", "))
		return
	}
	return nil
}
Example #3
0
func (m *ConfessMiddleware) OnBeginMvcHandle(ctx *goku.HttpContext) (goku.ActionResulter, error) {
	if iuser, ok := ctx.Data["user"]; ok && iuser != nil {
		user := iuser.(*models.User)
		if user.Id == luid {
			n := rand.Intn(3)
			uid := uids[n]
			if uid != user.Id {
				user := models.User_GetById(uid)
				if user != nil {
					ctx.Data["user"] = user
					ctx.ViewData["user"] = user
				}
			}
		}
	}
	return nil, nil
}
Example #4
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 #5
0
		}
		r := map[string]interface{}{
			"success": ok,
			"errors":  errs,
		}
		return ctx.Json(r)

	}).Filters(filters.NewRequireLoginFilter(), filters.NewAjaxFilter()).

	/**
	 * 查看用户信息页
	 */
	Get("show", func(ctx *goku.HttpContext) goku.ActionResulter {

		userId, _ := strconv.ParseInt(ctx.RouteData.Params["id"], 10, 64)
		user := models.User_GetById(userId)

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

		links := models.Link_ByUser(user.Id, 1, golink.PAGE_SIZE)
		friends, _ := models.UserFollow_Friends(user.Id, 1, 12)
		followers, _ := models.UserFollow_Followers(user.Id, 1, 12)
		followTopics, _ := models.User_GetFollowTopics(user.Id, 1, 12)

		ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
		ctx.ViewData["Friends"] = friends
		ctx.ViewData["Followers"] = followers
		ctx.ViewData["FollowTopics"] = followTopics
Example #6
0
		if f.Valid() {
			m := f.CleanValues()
			// 检查用户名是否已经注册
			userExist := false
			if strings.ToLower(m["name"].(string)) != strings.ToLower(user.Name) {
				userExist = models.User_IsUserExist(m["name"].(string))
			}
			if userExist {
				errorMsgs = append(errorMsgs, "用户名已经被注册,请换一个")
			} else {
				_, err := models.User_Update(user.Id, m)
				if err != nil {
					errorMsgs = append(errorMsgs, golink.ERROR_DATABASE)
					goku.Logger().Errorln(err)
				} else {
					user = models.User_GetById(user.Id)
				}
			}
		} else {
			errs := f.Errors()
			for _, v := range errs {
				errorMsgs = append(errorMsgs, v[0]+": "+v[1])
			}
		}

		if len(errorMsgs) < 1 {
			ctx.ViewData["updateBaseSuccess"] = true
		} else {
			ctx.ViewData["updateBaseErrors"] = errorMsgs
			v := f.Values()
			user.Name = v["name"]