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 (this *UserRouter) getFollows(user *models.User, following bool) []map[string]interface{} { var follow models.Follow if following { follow.UserId = user.Id } else { follow.FollowUserId = user.Id } nums, _ := models.Count(&follow) limit := 20 pager := this.SetPaginator(limit, nums) var follows []*models.Follow models.ORM().Limit(limit, pager.Offset()).Find(&follows, &follow) if len(follows) == 0 { return nil } ids := make([]int, 0, len(follows)) for _, follow := range follows { if following { ids = append(ids, int(follow.FollowUserId)) } else { ids = append(ids, int(follow.UserId)) } } var fids = make(map[int]bool) models.ORM().In("follow_user_id", ids).Iterate(&models.Follow{UserId: this.User.Id}, func(idx int, bean interface{}) error { tid, _ := utils.StrTo(utils.ToStr(bean.(*models.Follow).Id)).Int() if tid > 0 { fids[tid] = true } return nil }) 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[int(u.Id)] } users = append(users, map[string]interface{}{ "User": u, "IsFollowed": IsFollowed, }) } return users }
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 }
// 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 (form *TopicAdminForm) CategorySelectData() [][]string { var cats []models.Category models.FindCategories(&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() }
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.Session.Get("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 int64, 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 } if err := models.UpdatePostBrowsersById(post.Id); err != nil { log.Error("PostCounterAdd ", err) } setting.Cache.Put(key, true, 60) }
func (form *UserAvatarForm) Valid(v *validation.Validation) { if len(utils.ToStr(form.AvatarType)) == 0 { v.SetError("AvatarType", "Please select") } }
func GenImagePath(img *models.Image) string { return "upload/img/" + utils.Date(img.Created, "y/m/d/s/") + utils.ToStr(img.Id) + "/" }
func (m *Notification) String() string { return utils.ToStr(m.Id) }
func (m *Comment) String() string { return utils.ToStr(m.Id) }
func (m *Topic) String() string { return utils.ToStr(m.Id) }
func (m *User) String() string { return utils.ToStr(m.Id) }
func (m *Category) String() string { return utils.ToStr(m.Id) }
func (m *Post) String() string { return utils.ToStr(m.Id) }
func (m *Image) GetToken() string { number := utils.Date(m.Created, "ymds") + utils.ToStr(m.Id) return utils.NumberEncode(number, setting.ImageLinkAlphabets) }