Example #1
0
// ValidateUser validates user models
func ValidateUser(id, email, password string) (e []validate.ValidationMsg) {
	e = append(e, validate.NotNil("id", id)...)
	e = append(e, validate.NotNil("email", email)...)
	e = append(e, validate.NotNil("password", password)...)

	e = append(e, checkEmail(email, "")...)

	if !DB.Where(&User{ID: id}).First(&User{}).RecordNotFound() {
		e = append(e, validate.ValidationMsg{Field: "id", Msg: validate.UniqueMsg})
	}

	return e
}
Example #2
0
// TODO: Add CTCP support for newlines
// TODO: check length of message and break message into multiple lines
func msg(ircc *irc.IRC, w io.Writer, input string) int {
	cmd := events.Msg{}

	if err := json.Unmarshal([]byte(input), &cmd); err != nil {
		fmt.Fprint(w, events.JSONError(err.Error()))
		return -1 // Not a critical error.
	}

	e := []validate.ValidationMsg{}
	e = append(e, validate.NotNil("target", cmd.Target)...)
	e = append(e, validate.NotNil("msg", cmd.Msg)...)

	if len(e) > 0 {
		fmt.Fprint(w, events.ValidationError("join", e))
		return -1 // Not a critical error.
	}

	ircc.Msg(cmd.Target, cmd.Msg, cmd.Notice)
	return -1
}
Example #3
0
func part(ircc *irc.IRC, w io.Writer, input string) int {
	cmd := events.Part{}

	if err := json.Unmarshal([]byte(input), &cmd); err != nil {
		fmt.Fprint(w, events.JSONError(err.Error()))
		return -1 // Not a critical error.
	}

	e := []validate.ValidationMsg{}
	e = append(e, validate.NotNil("channel", cmd.Channel)...)

	if len(e) > 0 {
		fmt.Fprint(w, events.ValidationError("part", e))
		return -1 // Not a critical error.
	}

	ircc.Part(cmd.Channel)
	return -1
}