Exemplo n.º 1
0
/*
    tabs(makeGrid("[{ name: 'Status', uri: 'pane-1' }, { name: 'Edit', uri: 'pane-2' }]"))

    Options:
        click
        toggle
        remote
 */
PUBLIC void espTabs(HttpConn *conn, EdiGrid *grid, cchar *optionString)
{
    MprHash     *options;
    EdiRec      *rec;
    cchar       *attr, *uri, *name, *klass;
    int         r, toggle;

    options = httpGetOptions(optionString);
    httpInsertOption(options, "class", ESTYLE("tabs"));

    attr = httpGetOption(options, "toggle", EDATA("click"));
    if ((toggle = smatch(attr, "true")) != 0) {
        attr = EDATA("toggle");
    }
    espRender(conn, "<div%s>\r\n    <ul>\r\n", map(conn, options));
    for (r = 0; r < grid->nrecords; r++) {
        rec = grid->records[r];
        name = ediGetFieldValue(rec, "name");
        uri = ediGetFieldValue(rec, "uri");
        uri = toggle ? uri : httpUri(conn, uri);
        if ((r == 0 && toggle) || smatch(uri, conn->rx->pathInfo)) {
            klass = smatch(uri, conn->rx->pathInfo) ? " class='esp-selected'" : "";
        } else {
            klass = "";
        }
        espRender(conn, "          <li %s='%s'%s>%s</li>\r\n", attr, uri, klass, name);
    }
    espRender(conn, "        </ul>\r\n    </div>\r\n");
}
Exemplo n.º 2
0
/*
    dropdown("priority", makeGrid("[{ id: 0, low: 0}, { id: 1, med: 1}, {id: 2, high: 2}]"), 0)
    dropdown("priority", makeGrid("[{ low: 0}, { med: 1}, {high: 2}]"), 0)
    dropdown("priority", makeGrid("[0, 10, 100]"), 0)

    Options can provide the defaultValue in a "value" property.
 */
PUBLIC void espDropdown(HttpConn *conn, cchar *field, EdiGrid *choices, cchar *optionString) 
{
    EdiRec      *rec;
    MprHash     *options;
    cchar       *id, *currentValue, *selected, *value;
    int         r;

    if (choices == 0) {
        return;
    }
    options = httpGetOptions(optionString);
    currentValue = getValue(conn, field, options);
    if (field == 0) {
        field = httpGetOption(options, "field", "id");
    }
    espRender(conn, "<select name='%s'%s>\r\n", field, map(conn, options));
    for (r = 0; r < choices->nrecords; r++) {
        rec = choices->records[r];
        if (rec->nfields == 1) {
            value = rec->fields[0].value;
        } else {
            value = ediGetFieldValue(rec, field);
        }
        if ((id = ediGetFieldValue(choices->records[r], "id")) == 0) {
            id = value;
        }
        selected = (smatch(value, currentValue)) ? " selected='yes'" : "";
        espRender(conn, "        <option value='%s'%s>%s</option>\r\n", id, selected, value);
    }
    espRender(conn, "    </select>");
}
Exemplo n.º 3
0
static cchar *getValue(HttpConn *conn, cchar *fieldName, MprHash *options)
{
    EdiRec      *record;
    MprKey      *field;
    cchar       *value, *msg;

    record = conn->record;
    value = 0;

    if (record) {
        value = ediGetFieldValue(record, fieldName);
        if (record->errors) {
            for (ITERATE_KEY_DATA(record->errors, field, msg)) {
                if (smatch(field->key, fieldName)) {
                    httpInsertOption(options, "class", ESTYLE("field-error"));
                }
            }
        }
    }
    if (value == 0) {
        value = httpGetOption(options, "value", 0);
    }
    if (httpGetOption(options, "escape", 0)) {
        value = mprEscapeHtml(value);
    }
    return value;
}
Exemplo n.º 4
0
Arquivo: app.c Projeto: embedthis/esp
/*
    Callback from httpLogin to verify credentials using the password defined in the database.
 */
static bool verifyUser(HttpStream *stream, cchar *username, cchar *password)
{
    HttpAuth    *auth;
    HttpUser    *user;
    HttpRx      *rx;
    EdiRec      *urec;

    rx = stream->rx;
    auth = rx->route->auth;

    if ((urec = readRecWhere("user", "username", "==", username)) == 0) {
        httpLog(stream->trace, "auth.login.error", "error", "msg: 'Cannot verify user', username: '******'", username);
        return 0;
    }
    if (!mprCheckPassword(password, getField(urec, "password"))) {
        httpLog(stream->trace, "auth.login.error", "error", "msg: 'Password failed to authenticate', username: '******'", username);
        mprSleep(500);
        return 0;
    }
    /*
        Cache the user and define the user roles. Thereafter, the app can use "httpCanUser" to test if the user
        has the required abilities (defined by their roles) to perform a given request or operation.
     */
    if ((user = httpLookupUser(auth, username)) == 0) {
        user = httpAddUser(auth, username, 0, ediGetFieldValue(urec, "roles"));
    }
    /*
        Define this as the authenticated and authorized user for this session
     */
    httpSetStreamUser(stream, user);

    httpLog(stream->trace, "auth.login.authenticated", "context", "msg: 'User authenticated', username: '******'", username);
    return 1;
}
Exemplo n.º 5
0
PUBLIC cchar *getField(EdiRec *rec, cchar *field)
{
    return ediGetFieldValue(rec, field);
}
Exemplo n.º 6
0
PUBLIC cchar *getField(cchar *field)
{
    return ediGetFieldValue(getRec(), field);
}