Ejemplo n.º 1
0
function user_session_set_secret($userId, $secret)
{
    lets_use('core_config', 'storage_db', 'storage_nosql');
    $dbResult = storage_db_insert_row(USER_SESSION_DB_TABLE, ['user_id' => $userId, 'secret' => $secret]);
    if (!$dbResult) {
        core_error('cannot write new session to db: ' . storage_db_get_last_error(USER_SESSION_DB_TABLE));
        return false;
    }
    storage_nosql_set_prefix(CORE_CONFIG_REDIS_MAIN, USER_SESSION_REDIS_KEY_PREFIX, $userId, null);
    return true;
}
Ejemplo n.º 2
0
function billing_account_get_account($ownerId, $type, $autoCreate)
{
    lets_use('storage_db');
    $accountId = storage_db_get_value(BILLING_ACCOUNT_DB_TABLE, BILLING_ACCOUNT_FIELD_ID, [[BILLING_ACCOUNT_FIELD_OWNER_ID, $ownerId], [BILLING_ACCOUNT_FIELD_TYPE, $type]], ['LIMIT' => 1]);
    if (storage_db_get_last_error(BILLING_ACCOUNT_DB_TABLE)) {
        core_error('cant fetch account ' . json_encode(func_get_args()));
        return false;
    }
    // create account
    if (!$accountId && $autoCreate) {
        $bind = [BILLING_ACCOUNT_FIELD_OWNER_ID => $ownerId, BILLING_ACCOUNT_FIELD_TYPE => $type, BILLING_ACCOUNT_FIELD_CREATED => time()];
        $accountId = storage_db_insert_row(BILLING_ACCOUNT_DB_TABLE, $bind);
        if (!$accountId) {
            core_error('cant create an account ' . json_encode(func_get_args()));
            return false;
        }
    }
    return $accountId;
}
Ejemplo n.º 3
0
function user_register_new_user($name, $email, $pass)
{
    lets_use('storage_db');
    storage_db_transaction_begin('users');
    $userId = storage_db_insert_row('users', ['name' => $name, 'email' => $email]);
    if (!$userId) {
        storage_db_transaction_rollback('users');
        core_error('cannot save user data to db table');
        return false;
    }
    lets_use('user_session');
    $token = user_session_create_token($userId, $pass);
    if (!$token) {
        storage_db_transaction_rollback('users');
        core_error('cannot save user token');
        return false;
    }
    storage_db_transaction_commit('users');
    return $userId;
}
Ejemplo n.º 4
0
function billing_transaction_register($accountFrom, $accountTo, $sum, $type = 0, $relatedId = 0)
{
    lets_use('storage_db');
    $transactionId = storage_db_insert_row(BILLING_TRANSACTION_DB_TABLE, [BILLING_TRANSACTION_FIELD_ACC_FROM => $accountFrom, BILLING_TRANSACTION_FIELD_ACC_TO => $accountTo, BILLING_TRANSACTION_FIELD_AMOUNT => $sum, BILLING_TRANSACTION_FIELD_TYPE => $type, BILLING_TRANSACTION_FIELD_RELATED_ID => $relatedId, BILLING_TRANSACTION_FIELD_STARTED => time(), BILLING_TRANSACTION_FIELD_STATUS => BILLING_TRANSACTION_STATUS_STARTED]);
    return $transactionId;
}
Ejemplo n.º 5
0
function order_storage_create_order($title, $desc, $author, $cost)
{
    lets_use('storage_db');
    $orderId = storage_db_insert_row(ORDER_STORAGE_DB_TABLE, ['title' => $title, 'description' => $desc, 'author_id' => $author, 'cost' => $cost, 'created_at' => time(), 'status' => ORDER_STORAGE_ORDER_STATUS_CREATING]);
    return $orderId;
}