示例#1
0
文件: form.go 项目: netxfly/wetalk
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
}
示例#2
0
文件: post.go 项目: wildex/wetalk
func (this *PostRouter) NewSubmit() {
	this.TplName = "post/new.html"

	if this.CheckActiveRedirect() {
		return
	}

	form := post.PostForm{Locale: this.Locale}
	slug := this.GetString("topic")
	if len(slug) > 0 {
		topic := models.Topic{Slug: slug}
		topic.Read("Slug")
		form.Topic = topic.Id
		this.Data["Topic"] = &topic
	}

	post.ListCategories(&form.Categories)
	post.ListTopics(&form.Topics)
	if !this.ValidFormSets(&form) {
		return
	}

	var post models.Post
	if err := form.SavePost(&post, &this.User); err == nil {

		this.Ctx.SetCookie("post_topic", utils.ToStr(form.Topic), 1<<31-1, "/")
		this.Ctx.SetCookie("post_cat", utils.ToStr(form.Category), 1<<31-1, "/")
		this.Ctx.SetCookie("post_lang", utils.ToStr(form.Lang), 1<<31-1, "/")

		this.JsStorage("deleteKey", "post/new")
		this.Redirect(post.Link(), 302)
	}
}
示例#3
0
文件: form.go 项目: netxfly/wetalk
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
}
示例#4
0
文件: post.go 项目: wildex/wetalk
func (this *PostListRouter) postsFilter(qs orm.QuerySeter) orm.QuerySeter {
	if !this.IsLogin {
		return qs
	}
	args := []string{utils.ToStr(this.Locale.Index())}
	args = append(args, this.User.LangAdds...)
	args = append(args, utils.ToStr(this.User.Lang))
	qs = qs.Filter("Lang__in", args)
	return qs
}
示例#5
0
文件: form.go 项目: oyoy8629/XWetalk
func (form *PostForm) TopicSelectData() [][]string {
	data := make([][]string, 0, len(form.Topics))
	for _, topic := range form.Topics {
		data = append(data, []string{topic.GetName(form.Locale.Lang), utils.ToStr(topic.Id)})
	}
	return data
}
示例#6
0
文件: form.go 项目: oyoy8629/XWetalk
func (form *PostForm) CategorySelectData() [][]string {
	data := make([][]string, 0, len(form.Categories))
	for _, cat := range form.Categories {
		data = append(data, []string{"category." + cat.Name, utils.ToStr(cat.Id)})
	}
	return data
}
示例#7
0
文件: form.go 项目: JessonChan/wetalk
func (form *UserAdminForm) LangAddsSelectData() [][]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
}
示例#8
0
文件: auth.go 项目: wildex/wetalk
// 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
}
示例#9
0
文件: storage.go 项目: netxfly/wetalk
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()
}
示例#10
0
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
}
示例#11
0
文件: auth.go 项目: netxfly/wetalk
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))
	}
}
示例#12
0
文件: base.go 项目: wildex/wetalk
// 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
}
示例#13
0
文件: auth.go 项目: wildex/wetalk
// 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
}
示例#14
0
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()
}
示例#15
0
文件: util.go 项目: netxfly/wetalk
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)
}
示例#16
0
文件: form.go 项目: netxfly/wetalk
func (form *UserAvatarForm) Valid(v *validation.Validation) {
	if len(utils.ToStr(form.AvatarType)) == 0 {
		v.SetError("AvatarType", "Please select")
	}
}
示例#17
0
func (m *Category) String() string {
	return utils.ToStr(m.Id)
}
示例#18
0
文件: post.go 项目: netxfly/wetalk
func (m *Comment) String() string {
	return utils.ToStr(m.Id)
}
示例#19
0
func (m *Image) GetToken() string {
	number := beego.Date(m.Created, "ymds") + utils.ToStr(m.Id)
	return utils.NumberEncode(number, setting.ImageLinkAlphabets)
}
示例#20
0
func (m *Topic) String() string {
	return utils.ToStr(m.Id)
}
示例#21
0
文件: post.go 项目: netxfly/wetalk
func (m *Post) String() string {
	return utils.ToStr(m.Id)
}
示例#22
0
文件: storage.go 项目: netxfly/wetalk
func GenImagePath(img *models.Image) string {
	return "upload/img/" + beego.Date(img.Created, "y/m/d/s/") + utils.ToStr(img.Id) + "/"
}
示例#23
0
func (m *Article) String() string {
	return utils.ToStr(m.Id)
}
示例#24
0
文件: notice.go 项目: netxfly/wetalk
func (m *Notification) String() string {
	return utils.ToStr(m.Id)
}
示例#25
0
文件: user.go 项目: netxfly/wetalk
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
}
示例#26
0
文件: auth.go 项目: JessonChan/wetalk
func (m *User) String() string {
	return utils.ToStr(m.Id)
}