ngaakkk

Embed Size (px)

Citation preview

  • 7/31/2019 ngaakkk

    1/5

  • 7/31/2019 ngaakkk

    2/5

    } else {// Generate AUTH token request$params = array('oauth_callback' => BASE_URL.'oauth');$response = twitter_process('https://api.twitter.com/oauth/reque

    st_token', $params);parse_str($response, $token);

    // Save secret token to session to validate the result that comes back from Twitter

    $_SESSION['oauth_request_token_secret'] = $token['oauth_token_secret'];

    // redirect user to authorisation URL$authorise_url = 'https://api.twitter.com/oauth/authorize?oauth_

    token='.$token['oauth_token'];header("Location: $authorise_url");

    }}

    function user_oauth_sign(&$url, &$args = false) {require_once 'OAuth.php';

    $method = $args !== false ? 'POST' : 'GET';// Move GET parameters out of $url and into $argsif (preg_match_all('#[?&]([^=]+)=([^&]+)#', $url, $matches, PREG_SET_ORD

    ER)) {foreach ($matches as $match) {

    $args[$match[1]] = $match[2];}$url = substr($url, 0, strpos($url, '?'));

    }

    $sig_method = new OAuthSignatureMethod_HMAC_SHA1();$consumer = new OAuthConsumer(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET)

    ; $token = NULL;

    if (($oauth_token = $_GET['oauth_token']) && $_SESSION['oauth_request_token_secret']) {

    $oauth_token_secret = $_SESSION['oauth_request_token_secret'];} else {

    list($oauth_token, $oauth_token_secret) = explode('|', $GLOBALS['user']['password']);

    }if ($oauth_token && $oauth_token_secret) {

    $token = new OAuthConsumer($oauth_token, $oauth_token_secret);}

    $request = OAuthRequest::from_consumer_and_token($consumer, $token, $method, $url, $args);

    $request->sign_request($sig_method, $consumer, $token);

    switch ($method) {case 'GET':

    $url = $request->to_url();$args = false;return;

  • 7/31/2019 ngaakkk

    3/5

  • 7/31/2019 ngaakkk

    4/5

    function user_current_username() {return $GLOBALS['user']['username'];

    }

    function user_is_current_user($username) {return (strcasecmp($username, user_current_username()) == 0);

    }

    function user_type() {return $GLOBALS['user']['type'];

    }

    function _user_save_cookie($stay_logged_in = 0) {$cookie = _user_encrypt_cookie();$duration = 0;if ($stay_logged_in) {

    $duration = time() + (3600 * 24 * 365);}setcookie('USER_AUTH', $cookie, $duration, '/');

    }

    function _user_encryption_key() {return ENCRYPTION_KEY;

    }function _user_encrypt_cookie() {

    $plain_text = $GLOBALS['user']['username'] . ':' . $GLOBALS['user']['password'] . ':' . $GLOBALS['user']['type'];

    $td = mcrypt_module_open('blowfish', '', 'cfb', '');$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);mcrypt_generic_init($td, _user_encryption_key(), $iv);$crypt_text = mcrypt_generic($td, $plain_text);mcrypt_generic_deinit($td);return base64_encode($iv.$crypt_text);

    }

    function _user_decrypt_cookie($crypt_text) {$crypt_text = base64_decode($crypt_text);$td = mcrypt_module_open('blowfish', '', 'cfb', '');$ivsize = mcrypt_enc_get_iv_size($td);$iv = substr($crypt_text, 0, $ivsize);$crypt_text = substr($crypt_text, $ivsize);mcrypt_generic_init($td, _user_encryption_key(), $iv);$plain_text = mdecrypt_generic($td, $crypt_text);mcrypt_generic_deinit($td);

    list($GLOBALS['user']['username'], $GLOBALS['user']['password'], $GLOBALS['user']['type']) = explode(':', $plain_text);

    }

    function user_login() {return theme('page', 'Login','

    Username
    Password
    Stay logged in?

  • 7/31/2019 ngaakkk

    5/5

    Registration steps:

    Sign in via Twitter.com from any computerVisit the Dabr settings page to choose a passwordDone! You can now benefit from accessing Twitter through Dabr from a

    nywhere (even from computers that block Twitter.com)');}

    function theme_login() {$content = '';

    if (MYSQL_USERS == 'ON') $content .= '

    No access to Twitter.com? Sign in with your Dabr account

    ';

    $content .= '';return $content;

    }

    function theme_logged_out() {return '

    Logged out. Login again

    ';}