You are here

function twitter_signin_user in Twitter 6.3

Same name and namespace in other branches
  1. 6.5 twitter_signin/twitter_signin.module \twitter_signin_user()
  2. 6.4 twitter_signin/twitter_signin.module \twitter_signin_user()

Implementation of hook_user().

Relates a Twitter account with a just created user account if the user signed in with Twitter but did not have an account in the site yet.

File

twitter_signin/twitter_signin.module, line 187

Code

function twitter_signin_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'insert':
    case 'login':
      if (isset($_SESSION['twitter']['values'])) {
        module_load_include('lib.php', 'oauth');
        module_load_include('inc', 'twitter');
        $key = variable_get('twitter_consumer_key', '');
        $secret = variable_get('twitter_consumer_secret', '');
        $response = $_SESSION['twitter']['values'];
        $twitter = new TwitterOAuth($key, $secret, $response['oauth_token'], $response['oauth_token_secret']);
        $twitter_account = $twitter
          ->users_show($response['screen_name']);
        $twitter_account
          ->set_auth($response);
        twitter_account_save($twitter_account, TRUE, $account);
        unset($_SESSION['twitter']);
        drupal_set_message(t('You have related a Twitter account with your user. Next time you can sign in with Twitter.'));
      }
      break;
  }
}