Пример #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;
}
Пример #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;
}