// 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 }
// validateParams checks these params pass validation checks func validateParams(params map[string]string) error { // Now check params are as we expect err := validate.Length(params["id"], 0, -1) if err != nil { return err } err = validate.Length(params["name"], 0, 255) if err != nil { return err } return err }
// 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 }
// validateParams these parameters conform to AcceptedParams, and pass validation func validateParams(unsafeParams map[string]string) error { // Now check params are as we expect err := validate.Length(unsafeParams["id"], 0, -1) if err != nil { return err } err = validate.Length(unsafeParams["name"], 3, 100) if err != nil { return err } err = validate.Length(unsafeParams["email"], 3, 100) if err != nil { return err } // 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 err } ep, err := auth.EncryptPassword(unsafeParams["password"]) if err != nil { return err } unsafeParams["encrypted_password"] = ep } // Finally, always delete the password param delete(unsafeParams, "password") return err }
// validateParams checks these params pass validation checks // TODO: reconsider best interface for this - don't like the bool func validateParams(params map[string]string, checkAll bool) error { if checkAll || len(params["name"]) > 0 { err := validate.Length(params["name"], 2, 300) if err != nil { return router.BadRequestError(err, "Invalid Name", "The name must be over 2 characters") } } if checkAll || len(params["url"]) > 0 { err := validate.Length(params["url"], 5, 1000) if err != nil { return router.BadRequestError(err, "Invalid URL", "The URL must be over 5 characters") } if !strings.HasPrefix(params["url"], "http://") && !strings.HasPrefix(params["url"], "https://") { return router.BadRequestError(nil, "Invalid URL", "The URL must have scheme https:// or http://") } } return nil }