Ejemplo n.º 1
0
NEOERR* member_check_login_data_get(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses)
{
    mdb_conn *db = hash_lookup(dbh, "main");
    char *mname, *mmsn;
    NEOERR *err;
    
    MCS_NOT_NULLB(cgi->hdf, db);

    HDF_FETCH_STR(cgi->hdf, PRE_QUERY".mname", mname);
    HDF_FETCH_STR(cgi->hdf, PRE_QUERY".mmsn", mmsn);
    if (!mname || !mmsn) {
        HDF_GET_STR_IDENT(cgi->hdf, PRE_COOKIE".mname", mname);
        HDF_GET_STR_IDENT(cgi->hdf, PRE_COOKIE".mmsn", mmsn);
    }
    hdf_set_value(cgi->hdf, PRE_RESERVE".mname", mname);

    MDB_QUERY_RAW(db, "member", _COL_MEMBER, "mname=$1", "s", mname);
    err = mdb_set_row(cgi->hdf, db, _COL_MEMBER, PRE_OUTPUT".member", MDB_FLAG_Z);
    if (err != STATUS_OK) return nerr_pass(err);

    char *mmsndb = hdf_get_value(cgi->hdf, PRE_OUTPUT".member.mmsn", NULL);
    if (!mmsndb || strcmp(mmsndb, mmsn)) {
        hdf_remove_tree(cgi->hdf, PRE_OUTPUT".member");
        return nerr_raise(LERR_NOTLOGIN, "msn don't match");
    }
    
    return STATUS_OK;
}
Ejemplo n.º 2
0
NEOERR* member_check_login_data_get(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses)
{
    mevent_t *evt = hash_lookup(evth, "member");
    char *mname, *mmsn;

    MCS_NOT_NULLB(cgi->hdf, evt);

    HDF_FETCH_STR(cgi->hdf, PRE_QUERY".mname", mname);
    HDF_FETCH_STR(cgi->hdf, PRE_QUERY".mmsn", mmsn);
    if (!mname || !mmsn) {
        HDF_GET_STR_IDENT(cgi->hdf, PRE_COOKIE".mname", mname);
        HDF_GET_STR_IDENT(cgi->hdf, PRE_COOKIE".mmsn", mmsn);
    }
    hdf_set_value(cgi->hdf, PRE_RESERVE".mname", mname);

    hdf_set_value(evt->hdfsnd, "mname", mname);
    hdf_set_value(evt->hdfsnd, "mmsn", mmsn);

    MEVENT_TRIGGER(evt, mname, REQ_CMD_MEMBER_CHECK_MMSN, FLAGS_SYNC);

    hdf_copy(cgi->hdf, PRE_OUTPUT".member", evt->hdfrcv);

    return STATUS_OK;
}
Ejemplo n.º 3
0
Archivo: ooms.c Proyecto: kingiol/cmoon
NEOERR* oms_users_data_add(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses)
{
    mevent_t *evt = (mevent_t*)hash_lookup(evth, "aic");
    char *aname, *pname, *email;
    int cost;
    NEOERR *err;

    APP_CHECK_ADMIN();

    HDF_GET_STR_IDENT(cgi->hdf, PRE_COOKIE".aname", pname);
    HDF_GET_STR(cgi->hdf, PRE_QUERY".aname", aname);
    HDF_GET_STR(cgi->hdf, PRE_QUERY".email", email);
    LEGAL_CK_ANAME(pname);
    LEGAL_CK_ANAME(aname);
    LEGAL_CK_EMAIL(email);

    /*
     * check
     */
    int state = hdf_get_int_value(evt->hdfrcv, "state", LCS_ST_FREE);
    if (state <= LCS_ST_FREE)
        return nerr_raise(LERR_NEEDUP, "%s want to add users %s", pname, aname);
    else if (state >= LCS_ST_VIP) goto add;

    /*
     * chargeback
     */
    cost = hdf_get_int_value(g_cfg, "Cost.account", 0);
    evt = (mevent_t*)hash_lookup(evth, "bank");
    hdf_set_value(evt->hdfsnd, "aname", pname);
    hdf_set_int_value(evt->hdfsnd, "btype", BANK_OP_ADDACCOUNT);
    hdf_set_int_value(evt->hdfsnd, "fee", cost);
    hdf_set_value(evt->hdfsnd, "account", aname);

    MEVENT_TRIGGER(evt, pname, REQ_CMD_BANK_ADDBILL, FLAGS_SYNC);

add:
    /*
     * add
     */
    evt = (mevent_t*)hash_lookup(evth, "aic");
    hdf_copy(evt->hdfsnd, NULL, hdf_get_obj(cgi->hdf, PRE_QUERY));
    hdf_set_value(evt->hdfsnd, "pname", pname);
    hdf_set_value(evt->hdfsnd, "aname", aname);
    hdf_set_int_value(evt->hdfsnd, "state",
                      hdf_get_int_value(evt->hdfrcv, "state", LCS_ST_FREE));
    hdf_set_value(evt->hdfsnd, "masn", aname);

    if (PROCESS_NOK(mevent_trigger(evt, aname, REQ_CMD_APPNEW, FLAGS_SYNC))) {
        char *zpa = NULL;
        hdf_write_string(evt->hdfrcv, &zpa);
        mtc_foo("add %s failure %d %s", aname, evt->errcode, zpa);
        SAFE_FREE(zpa);

        if (state < LCS_ST_VIP) {
            /*
             * roll back
             */
            evt = (mevent_t*)hash_lookup(evth, "bank");
            hdf_set_value(evt->hdfsnd, "aname", pname);
            hdf_set_int_value(evt->hdfsnd, "btype", BANK_OP_ROLLBACK);
            hdf_set_int_value(evt->hdfsnd, "fee", -cost);
            hdf_set_valuef(evt->hdfsnd, "remark = 客服帐号 %s 创建失败", aname);

            if (PROCESS_NOK(mevent_trigger(evt, pname, REQ_CMD_BANK_ADDBILL,
                                           FLAGS_SYNC))) {
                /*
                 * ATTENTION we need pay back to customer manually
                 */
                hdf_write_string(evt->hdfrcv, &zpa);
                mtc_foo("rollback %s failure %d %s", aname, evt->errcode, zpa);
                SAFE_FREE(zpa);
            }
        }

        return nerr_raise(evt->errcode, "add %s failure %d", aname, evt->errcode);
    }

    return STATUS_OK;
}