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

	// Get signed in user
	loggedUser := auth.GetSignedInUser(r)

	if rcv.Name == loggedUser.Name && rcv.Email == loggedUser.Email {
		errs = append(errs, binding.Error{
			FieldNames:     []string{"Name"},
			Classification: "NameError",
			Message:        rcv.Translate("text14"),
		})

		return errs
	}

	// Validate if the same name
	if rcv.Name != loggedUser.Name {
		if rcv.Name == "" {
			errs = append(errs, binding.Error{
				FieldNames:     []string{"Name"},
				Classification: "EmptyError",
				Message:        rcv.Translate("text01"),
			})
		} else if err := maccount.ValidateName(rcv.Name, rcv.Local); err != nil {
			errs = append(errs, binding.Error{
				FieldNames:     []string{"Name"},
				Classification: "NameError",
				Message:        err.Error(),
			})
		}
	}

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

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

	if rcv.Name == "" {
		errs = append(errs, binding.Error{
			FieldNames:     []string{"Name"},
			Classification: "EmptyError",
			Message:        rcv.Translate("text01"),
		})
	} else if err := maccount.ValidateName(rcv.Name, rcv.Local); err != nil {
		errs = append(errs, binding.Error{
			FieldNames:     []string{"Name"},
			Classification: "NameError",
			Message:        err.Error(),
		})
	}

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

	if rcv.Emailconfirm == "" {
		errs = append(errs, binding.Error{
			FieldNames:     []string{"Emailconfirm"},
			Classification: "EmptyError",
			Message:        rcv.Translate("text03"),
		})
	} else if rcv.Emailconfirm != rcv.Email {
		errs = append(errs, binding.Error{
			FieldNames:     []string{"Email equality"},
			Classification: "NotEqualError",
			Message:        rcv.Translate("text07"),
		})
	}

	if rcv.Password == "" {
		errs = append(errs, binding.Error{
			FieldNames:     []string{"Password"},
			Classification: "EmptyError",
			Message:        rcv.Translate("text04"),
		})
	} else if err := maccount.ValidatePassword(rcv.Password, rcv.Local); err != nil {
		errs = append(errs, binding.Error{
			FieldNames:     []string{"Password"},
			Classification: "PasswordError",
			Message:        err.Error(),
		})
	}

	if rcv.TermOf == false {
		errs = append(errs, binding.Error{
			FieldNames:     []string{"Emailconfirm"},
			Classification: "EmptyError",
			Message:        rcv.Translate("text06"),
		})
	}

	return errs
}