Ultracart and username's with vBulletin

Discussion in 'Troubleshooting' started by smoove045, Jan 13, 2010.

  1. smoove045

    smoove045 New Member

    Joined:
    Aug 22, 2006
    Messages:
    13
    - There is an Ultracart.com integration with amember, as you are likely aware. I will paste their php file below for integration with amember.

    - The question is, when integrating with vBulletin, how can we make it so that when a user buys through Ultracart they get to choose a username instead of having their username be their email address?

    This would be better because email addresses when used with amember + vbulletin would not be as "standard" for forums and people often want to hide their email addresses.

    I am familiar with code, so if you could let me know what to modify, I can do that. And I appreciate your help - anyone out there - very much so.



    Code:
    <?php
    require_once('../config.inc.php');
    
    global $config;
    
    if ($config['use_xmlrpc'] != '1') {
    die("Error #8001 - XML-RPC is not enabled at aMember CP->Setup->Advanced");
    }
    if ($config['xmlrpc_login'] == '' && $config['xmlrpc_password'] == '') {
    die("Error #8002 - XML-RPC username or password is not set at aMember CP->Setup->Advanced");
    }
    
    if (!isset($_SERVER['PHP_AUTH_USER'])) { // HTTP Authentication
    header('WWW-Authenticate: Basic realm="aMember XML-RPC"');
    header('HTTP/1.0 401 Unauthorized');
    print "Error #8003 - XML-RPC username is not entered";
    exit();
    }
    
    // checking name and password
    if( ($_SERVER['PHP_AUTH_USER'] != $config['xmlrpc_login'])
    || ($_SERVER['PHP_AUTH_PW'] != $config['xmlrpc_password'])){
    header('WWW-Authenticate: Basic realm="aMember XML-RPC"');
    header('HTTP/1.0 401 Unauthorized');
    print "Error #8004 - Incorrect XML-RPC username or password entered";
    exit();
    }
    
    function add_save(){
    global $db;
    global $member_additional_fields;
    global $config;
    
    $errors = array();
    $vars = get_input_vars();
    
    if (strlen($vars['generate_login']))
    $vars['login'] = generate_login($vars);
    if (strlen($vars['generate_pass']))
    $vars['pass'] = generate_password($vars);
    
    $vars['pass0'] = $vars['pass'];
    if (!strlen($vars['login'])){
    $errors[] = "'Login' is a required field";
    } elseif ($db->check_uniq_login($vars['login'], $vars['email'], $vars['pass0'], 1)>=0) {
    $errors[] = "User '$vars[login] already exists' - please choose another username";
    }
    if (!strlen($vars['pass0'])){
    $errors[] = "'Password' is a required field";
    }
    foreach ($member_additional_fields as $f){
    $fname = $f['name'];
    if ($f['validate_func'])
    foreach ((array)$f['validate_func'] as $func){
    if (!function_exists($func))
    fatal_error("Validation function '$func' for field: '$fname' not defined. Internal error", 0);
    if ($err = $func($vars[$fname], $f['title'], $f))
    $errors[] ="$err";
    }
    }
    foreach ($member_additional_fields as $f){
    $fname = $f['name'];
    if (isset($vars[$fname]))
    $vars['data'][$fname] = $vars[$fname];
    }
    
    foreach ($member_additional_fields as $f){
    $fname = $f['name'];
    $vars[$fname] = $vars['data'][$fname];
    unset($vars['data'][$fname]);
    }
    
    $member_id = $db->add_pending_user( $vars);
    
    if ($config['use_affiliates'])
    $is_affiliate = $vars['is_affiliate'];
    else
    $is_affiliate = '0';
    $db->subscribe_member ($member_id, $is_affiliate);
    
    $db->add_member_threads($member_id, $vars['threads']);
    
    update_cc_info($member_id, $vars);
    $db->admin_log("Member added ($vars[login])", 'members', $member_id);
    print "OK " . $member_id;
    }
    
    function check_uniq_login(){
    global $db;
    global $member_additional_fields;
    global $config;
    
    $u = get_input_vars();
    
    if ($u['check_type'] == '2'){
    // new check type, not implemetned into mysql.inc.php yet
    // 2 - uniq user - return member_id if user exists, -1 if no and 0 if email/password failed
    
    $login = $db->escape($u['login']);
    $email = $db->escape($u['email']);
    $pass = $db->escape($u['pass']);
    $q = $db->query($s = "SELECT login,
    (email='$email'), member_id, pass='$pass'
    FROM {$db->config['prefix']}members
    WHERE login='$login'
    ");
    $db->log_error ($s);
    list($login_x, $same_email,$member_id, $same_pass) = mysql_fetch_row($q);
    if ( $member_id ) {
    if ($config['generate_pass']) {
    if (!$same_email) return 0; //check email
    } else {
    if (!$same_pass || !$same_email) return 0; //check email&pass
    }
    } else $member_id = -1;
    return $member_id;
    } else {
    return $db->check_uniq_login($u['login'], $u['email'], $u['pass'], $u['check_type']);
    }
    }
    
    function payment_add(){
    $vars = get_input_vars();
    global $db;
    
    $err = $db->add_payment($vars);
    if ($err) {
    fatal_error("Cannot add payment: $err");
    }
    $db->admin_log("Payment/subscription record added", 'members', $vars['member_id']);
    print "OK ";
    }
    
    function get_member_id(){
    
    // Used to check for existing, non-UC added aMember users
    global $db;
    global $member_additional_fields;
    global $config;
    
    $u = get_input_vars();
    
    $login = $db->escape($u['login']);
    $q = $db->query($s = "SELECT login,
    email, member_id, pass
    FROM {$db->config['prefix']}members
    WHERE login='$login'
    ");
    $db->log_error ($s);
    list($login_x, $same_email,$member_id, $same_pass) = mysql_fetch_row($q);
    if ( $member_id ) {
    print "OK " . $member_id;
    } else print "ERR Member Not Found";
    
    }
    
    function update_cc_info($member_id, $vars){
    global $db;
    if (!strlen($vars['cc_number'])) return;
    $vars['cc_number'] = preg_replace('/\D+/', '', $vars['cc_number']);
    ////////////////////////////////////////////////////////////////////
    $m = $db->get_user($member_id);
    $m['data']['cc-hidden'] = amember_crypt($vars['cc_number']);
    $m['data']['cc'] = get_visible_cc_number($vars['cc_number']);
    $m['data']['cc-expire'] = sprintf('%02d%02d',
    $vars['cc_expire_Month'],
    substr($vars['cc_expire_Year'], 2, 2));
    $db->update_user($member_id, $m);
    }
    
    header("Content-Type: text/html; charset=UTF-8");
    $vars = get_input_vars();
    switch (@$vars['action']){
    case 'add_save':
    add_save();
    break;
    case 'check_unique_login':
    check_uniq_login();
    break;
    case 'payment_add':
    payment_add();
    break;
    case 'get_member_id':
    get_member_id();
    break;
    default:
    }
    
    ?> 
  2. mehow

    mehow New Member

    Joined:
    Dec 29, 2009
    Messages:
    3
    good thought. that seems non-ideal that Ultracart always makes your email address your username. and then Vbulletin doesn't easily let you change your username. this equals a bunch of people stuck with their email address as their username - their privacy violated and getting spammed.

    good luck getting this to work though. most likely you'll have to pay Ultracart to do the feature you want
  3. smoove045

    smoove045 New Member

    Joined:
    Aug 22, 2006
    Messages:
    13
    I guess they said they are looking into it. I was thinking maybe it would be an easy code change to just switch the username up somehow depending on how amember handles it. Who knows thanks for the response though.

Share This Page