Ejemplo n.º 1
0
// validateParams checks these params pass validation checks
func validateParams(params map[string]string) error {

	err := validate.Length(params["name"], 0, 100)
	if err != nil {
		return router.InternalError(err, "Name invalid length", "Your name must be between 0 and 100 characters long")
	}

	err = validate.Length(params["key"], 1000, 5000)
	if err != nil {
		return router.InternalError(err, "Key too short", "Your key must be at least 1000 characters long")
	}

	// Password may be blank
	if len(params["password"]) > 0 {
		// check length
		err := validate.Length(params["password"], 5, 100)
		if err != nil {
			return router.InternalError(err, "Password too short", "Your password must be at least 5 characters")
		}

		// HASH the password before storage at all times
		hash, err := auth.HashPassword(params["password"])
		if err != nil {
			return err
		}

		params["password"] = hash

	} else {
		// Delete password param
		delete(params, "password")
	}

	return err
}
Ejemplo n.º 2
0
// validateParams these parameters conform to AcceptedParams, and pass validation
func validateParams(unsafeParams map[string]string) error {

	// Now check params are as we expect

	if len(unsafeParams["name"]) > 0 {
		err := validate.Length(unsafeParams["name"], 1, 100)
		if err != nil {
			return router.BadRequestError(err, "Name too short", "Your name must be between 1 and 100 characters long.")
		}
	}

	if len(unsafeParams["email"]) > 0 {
		err := validate.Length(unsafeParams["email"], 3, 100)
		if err != nil {
			return router.BadRequestError(err, "Email too short", "Your email must be between 3 and 100 characters long.")
		}
	}

	// Password may be blank
	if len(unsafeParams["password"]) > 0 {
		// Report error for length between 0 and 5 chars
		err := validate.Length(unsafeParams["password"], 5, 100)
		if err != nil {
			return router.BadRequestError(err, "Password too short", "Your password must be at least 5 characters long.")
		}

		ep, err := auth.HashPassword(unsafeParams["password"])
		if err != nil {
			return err
		}
		unsafeParams["encrypted_password"] = ep

	}

	// Delete password param
	delete(unsafeParams, "password")

	return nil
}