function main()
{
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        print_r($_POST);
        echo "<br />";
        // Required Fields in the POST data //
        if (!isset($_POST['type'])) {
            return;
        }
        if (!isset($_POST['subtype'])) {
            return;
        }
        if (!isset($_POST['name'])) {
            return;
        }
        if (!isset($_POST['author'])) {
            return;
        }
        if (!isset($_POST['parent'])) {
            return;
        }
        if (!isset($_POST['publish'])) {
            return;
        }
        // Node Type //
        $type = sanitize_NodeType($_POST['type']);
        if (empty($type)) {
            return;
        }
        $subtype = sanitize_NodeType($_POST['subtype']);
        // Name/Title //
        $name = $_POST['name'];
        // TODO: Sanitize
        // Slug //
        if (empty($_POST['slug'])) {
            $slug = $_POST['name'];
        } else {
            $slug = $_POST['slug'];
        }
        $slug = sanitize_Slug($slug);
        if (empty($slug)) {
            return;
        }
        // Body //
        $body = $_POST['body'];
        // TODO: Sanitize
        // Relationships //
        $author = intval($_POST['author']);
        $parent = intval($_POST['parent']);
        // Do we publish? //
        $publish = mb_strtolower($_POST['publish']) == "true";
        $id = node_Add($type, $subtype, $slug, $name, $body, $author, $parent, $publish);
        echo "Added " . $id . ".<br />";
        echo "<br />";
    }
}
function main()
{
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        print_r($_POST);
        echo "<br />";
        // Required Fields in the POST data //
        if (!isset($_POST['_type'])) {
            return;
        }
        if (!isset($_POST['_subtype'])) {
            return;
        }
        if (!isset($_POST['_name'])) {
            return;
        }
        if (!isset($_POST['_mail'])) {
            return;
        }
        if (!isset($_POST['_password'])) {
            return;
        }
        if (!isset($_POST['_publish'])) {
            return;
        }
        // Node Type //
        $type = sanitize_NodeType($_POST['_type']);
        if (empty($type)) {
            return;
        }
        $subtype = sanitize_NodeType($_POST['_subtype']);
        // Name/Title //
        $name = $_POST['_name'];
        // TODO: Sanitize
        // Slug //
        if (empty($_POST['_slug'])) {
            $slug = $_POST['_name'];
        } else {
            $slug = $_POST['_slug'];
        }
        $slug = sanitize_Slug($slug);
        if (empty($slug)) {
            return;
        }
        // TODO: Confirm slug is legal
        // Body //
        $body = $_POST['_body'];
        // TODO: Sanitize
        // Do we publish? //
        $publish = mb_strtolower($_POST['_publish']) == "true";
        // Email //
        $mail = sanitize_Email($_POST['_mail']);
        if (empty($mail)) {
            return;
        }
        // Password //
        $password = $_POST['_password'];
        if (empty($password)) {
            return;
        }
        $id = node_Add($type, $subtype, $slug, $name, $body, 0, 2, $publish);
        user_Add($id, $mail, $password);
        echo "Added " . $id . ".<br />";
        echo "<br />";
    }
}
Exemple #3
0
 }
 // Does that name already exist?
 if (node_GetIdByParentAndSlug(SH_NODE_ID_USER, $slug)) {
     json_EmitFatalError_Server("Name ({$slug}) already exists", $RESPONSE);
 } else {
     /// @TODO Check if on the reserved list
     if (false) {
         /// @TODO Does this e-mail address match the one on the reserve list?
         if (false) {
             /// @TODO: Add
         } else {
             json_EmitFatalError_Server("Name is reserved. Is this you? Try using your original e-mail address instead", $RESPONSE);
         }
     } else {
         // @TODO wrap these so we can rollback
         $user_id = node_Add($slug, $name);
         if ($user_id) {
             // @TODO wrap these so we can rollback
             if (!user_SetNode($id, $user_id)) {
                 json_EmitFatalError_Server("Unable to set node", $RESPONSE);
             }
             if (!user_SetHash($id, userPassword_Hash($pw))) {
                 json_EmitFatalError_Server("Unable to set password", $RESPONSE);
             }
             if (!user_AuthKeyClear($id)) {
                 json_EmitFatalError_Server("Unable to clear key", $RESPONSE);
             }
             // @TODO send confirmation e-mail
             // Successfully Created.
             json_RespondCreated();
         } else {