func (form *UserAvatarForm) AvatarTypeSelectData() [][]string { var data = make([][]string, 0, 2) data = append(data, []string{"auth.user_avatar_use_gravatar", utils.ToStr(setting.AvatarTypeGravatar)}) data = append(data, []string{"auth.user_avatar_use_personal", utils.ToStr(setting.AvatarTypePersonalized)}) return data }
func (form *BulletinAdminForm) TypeSelectData() [][]string { data := [][]string{ []string{"model.bulletin_friend_link", utils.ToStr(setting.BULLETIN_FRIEND_LINK)}, []string{"model.bulletin_new_comer", utils.ToStr(setting.BULLETIN_NEW_COMER)}, []string{"model.bulletin_mobile_app", utils.ToStr(setting.BULLETIN_MOBILE_APP)}, []string{"model.bulletin_open_source", utils.ToStr(setting.BULLETIN_OPEN_SOURCE)}, } return data }
func (form *PostForm) TopicSelectData() [][]string { data := make([][]string, 0, len(form.Topics)) for _, topic := range form.Topics { data = append(data, []string{topic.Name, utils.ToStr(topic.Id)}) } return data }
func (form *PostForm) LangSelectData() [][]string { langs := setting.Langs data := make([][]string, 0, len(langs)) for i, lang := range langs { data = append(data, []string{lang, utils.ToStr(i)}) } return data }
func (form *TopicAdminForm) CategorySelectData() [][]string { var cats []models.Category ListCategories(&cats) data := make([][]string, 0, len(cats)) for _, cat := range cats { data = append(data, []string{cat.Name, utils.ToStr(cat.Id)}) } return data }
func GenImageFilePath(img *models.Image, width int) string { var size string if width == 0 { size = "full" } else { size = utils.ToStr(width) } return GenImagePath(img) + size + img.GetExt() }
// create a time limit code for user reset password func CreateUserResetPwdCode(user *models.User, startInf interface{}) string { minutes := setting.ResetPwdCodeLives data := utils.ToStr(user.Id) + user.Email + user.UserName + user.Password + user.Rands + user.Updated.String() code := utils.CreateTimeLimitCode(data, minutes, startInf) // add tail hex username code += hex.EncodeToString([]byte(user.UserName)) return code }
func (m *User) avatarLink(size int) string { if m.AvatarType == setting.AvatarTypePersonalized { if m.AvatarKey != "" { return fmt.Sprintf("%s", utils.GetQiniuZoomViewUrl(utils.GetQiniuPublicDownloadUrl(setting.QiniuAvatarDomain, m.AvatarKey), size, size)) } else { return fmt.Sprintf("http://golanghome-public.qiniudn.com/golang_avatar.png?imageView/0/w/%s/h/%s/q/100", utils.ToStr(size), utils.ToStr(size)) } } else { return fmt.Sprintf("%s%s?size=%s", setting.AvatarURL, m.GrEmail, utils.ToStr(size)) } }
// check flash redirect, ensure browser redirect to uri and display flash message. func (this *BaseRouter) CheckFlashRedirect(value string) (match bool, redirect bool) { v := this.GetSession("on_redirect") if params, ok := v.([]interface{}); ok { if len(params) != 5 { this.EndFlashRedirect() goto end } uri := utils.ToStr(params[0]) code := 302 if c, ok := params[1].(int); ok { if c/100 == 3 { code = c } } flag := utils.ToStr(params[2]) flagVal := utils.ToStr(params[3]) times := 0 if v, ok := params[4].(int); ok { times = v } times += 1 if times > 3 { // if max retry times reached then end this.EndFlashRedirect() goto end } // match uri or flash flag if uri == value || flag == value { match = true } else { // if no match then continue redirect this.FlashRedirect(uri, code, flag, flagVal, times) redirect = true } } end: return match, redirect }
// verify code when reset password func VerifyUserResetPwdCode(user *models.User, code string) bool { minutes := setting.ResetPwdCodeLives if getVerifyUser(user, code) { // time limit code prefix := code[:utils.TimeLimitCodeLength] data := utils.ToStr(user.Id) + user.Email + user.UserName + user.Password + user.Rands + user.Updated.String() return utils.VerifyTimeLimitCode(data, minutes, prefix) } return false }
func (m *Image) LinkSize(width int) string { if m.Ext == 3 { // if image is gif then return full size width = 0 } var size string switch width { case setting.ImageSizeSmall, setting.ImageSizeMiddle: size = utils.ToStr(width) default: size = "full" } return "/img/" + m.GetToken() + "." + size + m.GetExt() }
func PostBrowsersAdd(uid int, ip string, post *models.Post) { var key string if uid == 0 { key = ip } else { key = utils.ToStr(uid) } key = fmt.Sprintf("PCA.%d.%s", post.Id, key) if setting.Cache.Get(key) != nil { return } _, err := models.Posts().Filter("Id", post.Id).Update(orm.Params{ "Browsers": orm.ColValue(orm.Col_Add, 1), }) if err != nil { beego.Error("PostCounterAdd ", err) } setting.Cache.Put(key, true, 60) }
func (m *Image) GetToken() string { number := beego.Date(m.Created, "ymds") + utils.ToStr(m.Id) return utils.NumberEncode(number, setting.ImageLinkAlphabets) }
func (m *Notification) String() string { return utils.ToStr(m.Id) }
func (this *UserRouter) getFollows(user *models.User, following bool) []map[string]interface{} { limit := 20 var qs orm.QuerySeter if following { qs = user.FollowingUsers() } else { qs = user.FollowerUsers() } nums, _ := qs.Count() pager := this.SetPaginator(limit, nums) qs = qs.Limit(limit, pager.Offset()) var follows []*models.Follow if following { qs.RelatedSel("FollowUser").All(&follows, "FollowUser") } else { qs.RelatedSel("User").All(&follows, "User") } if len(follows) == 0 { return nil } ids := make([]int, 0, len(follows)) for _, follow := range follows { if following { ids = append(ids, follow.FollowUser.Id) } else { ids = append(ids, follow.User.Id) } } var eids orm.ParamsList this.User.FollowingUsers().Filter("FollowUser__in", ids).ValuesFlat(&eids, "FollowUser__Id") var fids map[int]bool if len(eids) > 0 { fids = make(map[int]bool) for _, id := range eids { tid, _ := utils.StrTo(utils.ToStr(id)).Int() if tid > 0 { fids[tid] = true } } } users := make([]map[string]interface{}, 0, len(follows)) for _, follow := range follows { IsFollowed := false var u *models.User if following { u = follow.FollowUser } else { u = follow.User } if fids != nil { IsFollowed = fids[u.Id] } users = append(users, map[string]interface{}{ "User": u, "IsFollowed": IsFollowed, }) } return users }
func GenImagePath(img *models.Image) string { return "upload/img/" + beego.Date(img.Created, "y/m/d/s/") + utils.ToStr(img.Id) + "/" }
func (form *UserAvatarForm) Valid(v *validation.Validation) { if len(utils.ToStr(form.AvatarType)) == 0 { v.SetError("AvatarType", "Please select") } }
func (m *User) String() string { return utils.ToStr(m.Id) }
func (m *Post) String() string { return utils.ToStr(m.Id) }
func (m *Comment) String() string { return utils.ToStr(m.Id) }