Пример #1
0
func (this *PostListRouter) postsFilter(qs orm.QuerySeter) orm.QuerySeter {
	args := []string{utils.ToStr(this.Locale.Index())}
	if this.isLogin {
		args = append(args, this.user.LangAdds...)
		args = append(args, utils.ToStr(this.user.Lang))
	}
	qs = qs.Filter("Lang__in", args)
	return qs
}
Пример #2
0
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
}
Пример #3
0
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
}
Пример #4
0
func (form *PostForm) LangSelectData() [][]string {
	langs := utils.Langs
	data := make([][]string, 0, len(langs))
	for i, lang := range langs {
		data = append(data, []string{lang, utils.ToStr(i)})
	}
	return data
}
Пример #5
0
// create a time limit code for user reset password
func CreateUserResetPwdCode(user *User, startInf interface{}) string {
	hours := utils.ResetPwdCodeLives
	data := utils.ToStr(user.Id) + user.Email + user.UserName + user.Password + user.Rands + user.Updated.String()
	code := utils.CreateTimeLimitCode(data, hours, startInf)

	// add tail hex username
	code += hex.EncodeToString([]byte(user.UserName))
	return code
}
Пример #6
0
func GenImageFilePath(img *Image, width int) string {
	var size string
	if width == 0 {
		size = "full"
	} else {
		size = utils.ToStr(width)
	}
	return GenImagePath(img) + size + img.GetExt()
}
Пример #7
0
// 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
}
Пример #8
0
// verify code when reset password
func VerifyUserResetPwdCode(user *User, code string) bool {
	hours := utils.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, hours, prefix)
	}

	return false
}
Пример #9
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 utils.ImageSizeSmall, utils.ImageSizeMiddle:
		size = utils.ToStr(width)
	default:
		size = "full"
	}
	return "/img/" + m.GetToken() + "." + size + m.GetExt()
}
Пример #10
0
func PostBrowsersAdd(uid int, ip string, post *Post) {
	var key string
	if uid == 0 {
		key = ip
	} else {
		key = utils.ToStr(uid)
	}
	key = fmt.Sprintf("PCA.%d.%s", post.Id, key)
	if utils.Cache.Get(key) != nil {
		return
	}
	_, err := Posts().Filter("Id", post.Id).Update(orm.Params{
		"Browsers": orm.ColValue(orm.Col_Add, 1),
	})
	if err != nil {
		beego.Error("PostCounterAdd ", err)
	}
	utils.Cache.Put(key, true, 60)
}
Пример #11
0
func (m *Category) String() string {
	return utils.ToStr(m.Id)
}
Пример #12
0
func (m *Article) String() string {
	return utils.ToStr(m.Id)
}
Пример #13
0
func GenImagePath(img *Image) string {
	return "upload/img/" + beego.Date(img.Created, "y/m/d/s/") + utils.ToStr(img.Id) + "/"
}
Пример #14
0
func (m *Post) String() string {
	return utils.ToStr(m.Id)
}
Пример #15
0
func (m *Comment) String() string {
	return utils.ToStr(m.Id)
}
Пример #16
0
func (m *Topic) String() string {
	return utils.ToStr(m.Id)
}
Пример #17
0
func (m *User) String() string {
	return utils.ToStr(m.Id)
}
Пример #18
0
func (m *Image) GetToken() string {
	number := beego.Date(m.Created, "ymds") + utils.ToStr(m.Id)
	return utils.NumberEncode(number, utils.ImageLinkAlphabets)
}