示例#1
0
文件: post.c 项目: ppslinux/esp
/*
    Create a new resource in the database
 */ 
static void createPost() { 
    if (updateRec(createRec("post", params()))) {
        flash("inform", "New post Created");
        renderView("post/post-list");
    } else {
        flash("error", "Cannot Create Post");
        renderView("post/post-edit");
    }
}
示例#2
0
文件: bst.cpp 项目: jzsun/work
void
createRec (BST * root, int d)
{
  if (root)
    {
      if (d > root->data)
	{
	  if (root->right)
	    createRec (root->right, d);
	  else
	    root->right = _new (d);
	}
      else if (d < root->data)
	{
	  if (root->left)
	    createRec (root->left, d);
	  else
	    root->left = _new (d);
	}
    }
}
示例#3
0
/*
    ${UCONTROLLER} Controller (esp-angular-mvc)
 */
#include "esp.h"

/*
    Create a new resource in the database
 */
static void create${UCONTROLLER}() { 
    sendResult(updateRec(createRec("${TABLE}", params())));
}

/*
    Get a resource
 */
static void get${UCONTROLLER}() { 
    sendRec(readRec("${TABLE}", "1"));
}

/*
    Initialize a new resource for the client to complete
 */
static void init${UCONTROLLER}() { 
    sendRec(createRec("${TABLE}", 0));
}

/*
    Remove a resource identified by the "id" parameter
 */
static void remove${UCONTROLLER}() { 
    sendResult(removeRec("${TABLE}", "1"));
示例#4
0
文件: espAbbrev.c 项目: embedthis/esp
PUBLIC bool createRecFromParams(cchar *table)
{
    return updateRec(createRec(table, params()));
}
示例#5
0
文件: pak.c 项目: embedthis/catalog
/*
    Can call this without being authenticated
 */
static void publishPackage() {
    HttpConn    *conn;
    EdiRec      *rec;
    cchar       *email, *password, *name, *endpoint;
    bool        checkPassword;

    name = param("name");
    endpoint = param("endpoint");
    password = param("password");
    email = param("email");

    conn = getConn();
    if (!name || !*name || !endpoint || !*endpoint) {
        sendResult(feedback("error", "Missing name or endpoint parameters"));
        return;
    }
    if (!email || !*email) {
        sendResult(feedback("error", "Missing email parameter"));
        return;
    }
    if (canUser("edit", 0) && smatch(conn->username, name)) {
        checkPassword = 0;
        httpTrace(conn, "auth.login.authenticated", "context", "msg=\"Authenticated for package\", pak=%s", name);
    } else {
        if (!password || !*password) {
            sendResult(feedback("error", "Missing password parameter"));
            return;
        }
        checkPassword = 1;
    }
    if ((rec = readRecWhere("pak", "name", "==", name)) != 0) {
        if (checkPassword && !mprCheckPassword(password, getField(rec, "password"))) {
            sendResult(feedback("error", "Package already exists but invalid password"));
            return;
        }
        setFields(rec, params());

    } else {
#if FUTURE
        cchar   *uri, *response, *err;
        uri = strim(endpoint, ".git", MPR_TRIM_END);
        uri = sjoin(uri, "/raw/master/package.json", NULL);
        status = httpRequest("GET", uri, NULL, &response, &err);

        if (status != 200) {
            feedback("warn", "Could not verify endpoint");
        } else {
            if (!response || mprParseJson(response) == 0) {
                feedback("warn", "Could not verify endpoint package.json");
            }
        }
#endif
        if ((rec = createRec("pak", params())) == 0) {
            sendResult(feedback("error", "Cannot create package record"));
            return;
        }
    }
    setField(rec, "password", mprMakePassword(password, PASSWORD_SALT, PASSWORD_ROUNDS));

    if (!(updateRec(rec))) {
        sendResult(feedback("error", "Cannot save package details"));
        return;
    }
    sendRec(rec);
}
示例#6
0
文件: pak.c 项目: embedthis/catalog
/*
    Initialize a new resource for the client to complete
    MOB - is this used?
 */
static void initPak() { 
    sendRec(createRec("pak", 0));
}
示例#7
0
文件: post.c 项目: ppslinux/esp
/*
    Initialize a new resource for the client to complete
 */
static void initPost() { 
    httpTrace(getConn(), "INIT POST", "context", NULL);
    createRec("post", 0);
    httpTrace(getConn(), "RENDER VIEW", "context", NULL);
    renderView("post/post-edit");
}
示例#8
0
/*
    ${CONTROLLER} Controller for esp-html-mvc (esp-html-mvc)
 */
#include "esp.h"

/*
    Create a new resource in the database
 */ 
static void create${UCONTROLLER}() { 
    if (updateRec(createRec("${CONTROLLER}", params()))) {
        flash("inform", "New ${CONTROLLER} Created");
        renderView("${CONTROLLER}/${CONTROLLER}-list");
    } else {
        flash("error", "Cannot Create ${UCONTROLLER}");
        renderView("${CONTROLLER}/${CONTROLLER}-edit");
    }
}

/*
    Prepare a template for editing a resource
 */
static void edit${UCONTROLLER}() { 
    readRec("${CONTROLLER}", param("id"));
}

/*
    Get a resource
 */ 
static void get${UCONTROLLER}() { 
    readRec("${CONTROLLER}", param("id"));
    renderView("${CONTROLLER}/${CONTROLLER}-edit");