开发者

Connect to Vbulletin forum with android app

I'm trying to make a small app that connect to a vbulletin forum to retrieve the numbers of unread subjects in user panel.

I found how to retrieve info from a website, but the problem is I 开发者_如何学编程have no idea how to login to the forum.

Can someone give me an advice or a least a link to help me start ?


There are several ways to login to web site: form login, http authentication, login via AJAX, etc..

You need to investigate how login is done in case of your particular site.

Check the http connections (e.g. Firefox with Firebug can see connections) to see what kind of connection is made when you click the login button on the site.


You'll need to send a _POST request via your app with the username and an md5 hash of the user's password. The username field name should be "vb_login_username" and the password field name should be "vb_login_md5password". Once you figure that out, you can create your own custom login page that your app talks to. Here's something similar to what I use. It returns the user's information in JSON format on a successful login.

require_once('./global.php');
require_once(DIR . '/includes/functions_login.php');

define("BADLOGIN"              , "You have entered an invalid username or password.");
define("BADLOGIN_STRIKES"      , "You have entered an invalid username or password. You have %s login attempts left, after which you will be unable to login for 15 minutes.");
define("BADLOGIN_STRIKES_ZERO" , "You have entered an invalid username or password and used up your failed login quota. Please wait 15 minutes before trying to login again.");

// ################################ start login #################################
if ($_POST['do'] == 'login') {

    $vbulletin->input->clean_array_gpc('p', array(
        'vb_login_username'        => TYPE_STR,
        'vb_login_password'        => TYPE_STR,
        'vb_login_md5password'     => TYPE_STR,
        'vb_login_md5password_utf' => TYPE_STR,
        'cookieuser'               => TYPE_BOOL,
    ));

    // can the user login?
    $strikes = verify_strike_status($vbulletin->GPC['vb_login_username']);

    // make sure our user info stays as whoever we were (for example, we might be logged in via cookies already)
    $original_userinfo = $vbulletin->userinfo;

    if (!verify_authentication(
        $vbulletin->GPC['vb_login_username'], $vbulletin->GPC['vb_login_password'], 
        $vbulletin->GPC['vb_login_md5password'], $vbulletin->GPC['vb_login_md5password_utf'], 
        $vbulletin->GPC['cookieuser'], true)) 
    {       
        exec_strike_user($vbulletin->userinfo['username']);

        // load original user
        $vbulletin->userinfo = $original_userinfo;

        if ($vbulletin->options['usestrikesystem'])
        {
            if ((5 - $strikes) == 0)
            {
                die(json_encode(array(
                    'hasErrors' => (int) 1,
                    'errorMsg'  => BADLOGIN_STRIKES_ZERO
                ))); 
            }
            else
            {
                die(json_encode(array(
                    'hasErrors' => (int) 1,
                    'errorMsg'  => sprintf(BADLOGIN_STRIKES, 5 - $strikes)
                ))); 
            }
        }
        else
        {
            die(json_encode(array(
                'hasErrors' => (int) 1,
                'errorMsg'  => BADLOGIN
            ))); 
        }
    }

    exec_unstrike_user($vbulletin->GPC['vb_login_username']);

    // create new session
    process_new_login($vbulletin->GPC['logintype'], $vbulletin->GPC['cookieuser'], $vbulletin->GPC['cssprefs']);
    $userinfo = fetch_user($vbulletin->userinfo['userid']);

    // is banned user?
    if ($userinfo['usergroupid'] == 8) {
        process_logout();
    }

    // return userinfo
    die(json_encode(array(
        'success' => (int) 1,
        'user'    => $userinfo
    ))); 
}

Hopefully this helps get you started. By the way, set the field name "cookieuser" to true and the user will be remembered the next time a request is made.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜