Ejemplo n.º 1
0
func (c *ChgPass) Post() {
	oldPass := c.Req().FormValue("old_pass")
	newPass := c.Req().FormValue("new_pass")
	cfmPass := c.Req().FormValue("cfm_pass")

	defer c.Redirect("/chgpass")

	if newPass != cfmPass {
		c.Flash.Set("cfmError", i18n.Tr(c.CurLang(), "password_not_eq"))
		return
	}

	user := c.Auther.LoginUser()
	if user != nil {
		if models.EncodePassword(oldPass) != user.Password {
			c.Flash.Set("oldError", i18n.Tr(c.CurLang(), "ori_password_not_correct"))
			return
		}
	} else {
		c.Flash.Set("otherError", i18n.Tr(c.CurLang(), "unknown_error"))
		return
	}

	user.Password = newPass
	err := models.UpdateUser(user)
	if err != nil {
		c.Flash.Set("otherError", err.Error())
		return
	}

	c.Flash.Set("changeSuccess", i18n.Tr(c.CurLang(), "password_change_success"))
}
Ejemplo n.º 2
0
// pager to HTML with navigator elements
func Pager2HTMLSimple(p *Pager, layout, lang string) template.HTML {
	tpl := `<div class="pager clear">`
	if p.Current > 1 {
		tpl += `<a class="prev left" href="` + fmt.Sprintf(layout, p.Current-1) + `">` + i18n.Tr(lang, "pager.prev") + `</a>`
	}
	if p.Current < p.Pages {
		tpl += `<a class="next right" href="` + fmt.Sprintf(layout, p.Current+1) + `">` + i18n.Tr(lang, "pager.next") + `</a>`
	}
	tpl += "</div>"
	return template.HTML(tpl)
}
Ejemplo n.º 3
0
func getbulletintype(lang string, t int) string {
	var typeStr string
	switch t {
	case setting.BULLETIN_FRIEND_LINK:
		typeStr = i18n.Tr(lang, "model.bulletin_friend_link")
	case setting.BULLETIN_MOBILE_APP:
		typeStr = i18n.Tr(lang, "model.bulletin_mobile_app")
	case setting.BULLETIN_NEW_COMER:
		typeStr = i18n.Tr(lang, "model.bulletin_new_comer")
	case setting.BULLETIN_OPEN_SOURCE:
		typeStr = i18n.Tr(lang, "model.bulletin_open_source")
	}
	return typeStr
}
Ejemplo n.º 4
0
func timesince(lang string, t time.Time) string {
	seconds := int(time.Since(t).Seconds())
	switch {
	case seconds < 60:
		return i18n.Tr(lang, "seconds_ago", seconds)
	case seconds < 60*60:
		return i18n.Tr(lang, "minutes_ago", seconds/60)
	case seconds < 60*60*24:
		return i18n.Tr(lang, "hours_ago", seconds/(60*60))
	case seconds < 60*60*24*100:
		return i18n.Tr(lang, "days_ago", seconds/(60*60*24))
	default:
		return Date(t, setting.DateFormat)
	}
}
Ejemplo n.º 5
0
func (c *Addb) Post() {
	var engine models.Engine
	if err := c.MapForm(&engine); err != nil {
		c.Flash.Set("ErrAdd", i18n.Tr(c.CurLang(), "err_param"))
		c.Redirect("/addb")
		return
	}

	if err := models.AddEngine(&engine); err != nil {
		c.Flash.Set("ErrAdd", i18n.Tr(c.CurLang(), "err_add_failed"))
		c.Redirect("/addb")
		return
	}

	c.Redirect("/")
}
Ejemplo n.º 6
0
func (c *Addb) Post() {
	var engine models.Engine
	engine.Name = c.Form("name")
	engine.Driver = c.Form("driver")
	host := c.Form("host")
	port := c.Form("port")
	dbname := c.Form("dbname")
	username := c.Form("username")
	passwd := c.Form("passwd")

	engine.DataSource = fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8",
		username, passwd, host, port, dbname)

	/*if err := c.MapForm(&engine); err != nil {
		c.Flash.Set("ErrAdd", i18n.Tr(c.CurLang(), "err_param"))
		c.Redirect("/addb")
		return
	}*/

	if err := models.AddEngine(&engine); err != nil {
		c.Flash.Set("ErrAdd", i18n.Tr(c.CurLang(), "err_add_failed"))
		c.Redirect("/addb")
		return
	}

	c.Redirect("/")
}
Ejemplo n.º 7
0
func Since(t time.Time) string {
	//now := time.Now()

	s := since(time.Since(t))

	if s <= 0 {
		return i18n.Tr("ru-RU", "now")
	}

	if ms := int(s.Minutes()); ms <= 45 {
		return fmt.Sprintf("%d %s назад", ms, plural("минута_минуты_минут", ms))
	} else if ms <= 90 {
		return fmt.Sprintf("час назад")
	}

	if hs := int(s.Hours()); hs < 22 {
		return i18n.Tr("ru-RU", "%d %s назад", hs, plural("час_часа_часов", hs))
	} else if hs < 36 {
		return fmt.Sprintf("вчера")
	}

	if ds := int(s.Days()); ds < 6 {
		return fmt.Sprintf("%d %s назад", ds, plural("день_дня_дней", ds))
	} else if ds < 8 {
		return fmt.Sprintf("неделю назад")
	}

	if ws := int(s.Weeks()); ws < 3 {
		return fmt.Sprintf("%d %s назад", ws+1, plural("неделя_недели_недель", ws+1))
	} else if ws < 5 {
		return "месяц назад"
	}
	if ms := int(s.Months()); ms < 11 {
		return fmt.Sprintf("%d %s назад", ms+1, plural("месяц_месяца_месяцев", ms+1))
	} else if ms < 14 {
		return "год назад"
	}

	return fmt.Sprintf("%d %s назад", s.Years(), plural("год_года_лет", s.Years()))
}
Ejemplo n.º 8
0
func (c *Login) Post() {
	c.Req().ParseForm()
	name := c.Req().FormValue("user")
	password := c.Req().FormValue("password")

	user, err := models.GetUserByName(name)
	if err != nil {
		c.Flash.Set("user", name)
		c.Flash.Set("AuthError", i18n.Tr(c.CurLang(), "pasword_error"))
		c.Redirect("/login")
		return
	}

	if user.Password != models.EncodePassword(password) {
		c.Flash.Set("user", name)
		c.Flash.Set("AuthError", i18n.Tr(c.CurLang(), "pasword_error"))
		c.Redirect("/login")
	} else {
		c.SetLogin(user.Id)
		c.Redirect("/")
	}
}
Ejemplo n.º 9
0
func timeSince(then time.Time, lang string) string {
	now := time.Now()

	lbl := i18n.Tr(lang, "tool.ago")
	diff := now.Unix() - then.Unix()
	if then.After(now) {
		lbl = i18n.Tr(lang, "tool.from_now")
		diff = then.Unix() - now.Unix()
	}

	switch {
	case diff <= 0:
		return i18n.Tr(lang, "tool.now")
	case diff <= 2:
		return i18n.Tr(lang, "tool.1s", lbl)
	case diff < 1*Minute:
		return i18n.Tr(lang, "tool.seconds", diff, lbl)

	case diff < 2*Minute:
		return i18n.Tr(lang, "tool.1m", lbl)
	case diff < 1*Hour:
		return i18n.Tr(lang, "tool.minutes", diff/Minute, lbl)

	case diff < 2*Hour:
		return i18n.Tr(lang, "tool.1h", lbl)
	case diff < 1*Day:
		return i18n.Tr(lang, "tool.hours", diff/Hour, lbl)

	case diff < 2*Day:
		return i18n.Tr(lang, "tool.1d", lbl)
	case diff < 1*Week:
		return i18n.Tr(lang, "tool.days", diff/Day, lbl)

	case diff < 2*Week:
		return i18n.Tr(lang, "tool.1w", lbl)
	case diff < 1*Month:
		return i18n.Tr(lang, "tool.weeks", diff/Week, lbl)

	case diff < 2*Month:
		return i18n.Tr(lang, "tool.1mon", lbl)
	case diff < 1*Year:
		return i18n.Tr(lang, "tool.months", diff/Month, lbl)

	case diff < 2*Year:
		return i18n.Tr(lang, "tool.1y", lbl)
	default:
		return i18n.Tr(lang, "tool.years", diff/Year, lbl)
	}
}
Ejemplo n.º 10
0
// get HTML i18n string
func i18nHTML(lang, format string, args ...interface{}) template.HTML {
	return template.HTML(i18n.Tr(lang, format, args...))
}
Ejemplo n.º 11
0
func (i *i18nHandle) Tr(format string, args ...interface{}) string {
	return i18n.Tr(i.Lang, format, args...)
}
Ejemplo n.º 12
0
// current translate method
func (bl *BaseLanguager) LangTr(format string, args ...interface{}) string {
	return i18n.Tr(bl.Lang, format, args...)
}