Пример #1
0
func (form *UserAdminForm) Valid(v *validation.Validation) {
	qs := models.Users()

	if models.CheckIsExist(qs, "UserName", form.UserName, form.Id) {
		v.SetError("UserName", "auth.username_already_taken")
	}

	if models.CheckIsExist(qs, "Email", form.Email, form.Id) {
		v.SetError("Email", "auth.email_already_taken")
	}

	if len(i18n.GetLangByIndex(form.Lang)) == 0 {
		v.SetError("Lang", "Can not be empty")
	}

	if len(form.LangAdds) > 0 {
		adds := make(models.SliceStringField, 0, len(form.LangAdds))
		for _, l := range form.LangAdds {
			if d, err := utils.StrTo(l).Int(); err == nil {
				if form.Lang == d {
					continue
				}
				if len(i18n.GetLangByIndex(form.Lang)) == 0 {
					v.SetError("Lang", "Can not be empty")
					return
				}
				adds = append(adds, l)
			}
		}
		form.LangAdds = adds
	}
}
Пример #2
0
func (form *CategoryAdminForm) Valid(v *validation.Validation) {
	qs := models.Categories()

	if models.CheckIsExist(qs, "Name", form.Name, form.Id) {
		v.SetError("Name", "admin.field_need_unique")
	}

	if models.CheckIsExist(qs, "Slug", form.Slug, form.Id) {
		v.SetError("Slug", "admin.field_need_unique")
	}
}
Пример #3
0
func (form *UserAdminForm) Valid(v *validation.Validation) {
	qs := models.Users()

	if models.CheckIsExist(qs, "UserName", form.UserName, form.Id) {
		v.SetError("UserName", "auth.username_already_taken")
	}

	if models.CheckIsExist(qs, "Email", form.Email, form.Id) {
		v.SetError("Email", "auth.email_already_taken")
	}

	if len(i18n.GetLangByIndex(form.Lang)) == 0 {
		v.SetError("Lang", "Can not be empty")
	}
}