// 查看粉丝 func user_Fans(ctx *goku.HttpContext) goku.ActionResulter { var isSelf bool 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" isSelf = true } } 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 if isSelf { models.Remind_Reset(user.Id, models.REMIND_FANS) } return ctx.View(models.User_ToVUser(user, ctx)) }
// 查看关注的人 func user_Follows(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-follows" } } if user == nil { ctx.ViewData["errorMsg"] = "用户不存在" return ctx.Render("error", nil) } page, pagesize := utils.PagerParams(ctx.Request) friends, _ := models.UserFollow_Friends(user.Id, page, pagesize) ctx.ViewData["Friends"] = models.User_ToVUsers(friends, ctx) ctx.ViewData["HasMoreFriends"] = len(friends) >= pagesize return ctx.View(models.User_ToVUser(user, ctx)) }
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 }
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 }
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"]
} 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, 24) followers, _ := models.UserFollow_Followers(user.Id, 1, 24) followTopics, _ := models.User_GetFollowTopics(user.Id, 1, 24, "") ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx) ctx.ViewData["Friends"] = friends ctx.ViewData["Followers"] = followers ctx.ViewData["FollowTopics"] = followTopics