Exemplo n.º 1
0
func (rcv *account) Validate(r *http.Request, errs binding.Errors) binding.Errors {

	if rcv.Email == "" {
		errs = append(errs, binding.Error{
			FieldNames:     []string{"Email"},
			Classification: "EmptyError",
			Message:        rcv.Translate("text02"),
		})
	} else if _, err := maccount.Read(rcv.Email, rcv.Local); err != nil {
		errs = append(errs, binding.Error{
			FieldNames:     []string{"Email"},
			Classification: "EmailNotExists",
			Message:        err.Error(),
		})
	}

	return errs
}
Exemplo n.º 2
0
// Validate entered data, included if the entered email is exist
func (rcv *controller) validate() []error {

	var errs []error

	// Map html input value to fields
	if fieldsErrs := binding.Bind(rcv.Request, rcv.formUser); fieldsErrs != nil {

		for _, e := range fieldsErrs {
			errs = append(errs, errors.New(e.Message))
		}
		return errs
	}

	if _, err := maccount.Read(rcv.formUser.Email, rcv.Local); err != nil {
		return []error{err}
	}

	// Validate captcha
	if err := captcha.Validate(rcv.Request, rcv.formUser.Certification, rcv.formUser.Human); err != nil {
		return []error{err}
	}

	return errs
}