<commit_before><?php

use hyperRail\app\models\OAuthProviders\IOAuthProvider;

 /*
    |--------------------------------------------------------------------------
    | Twitter provider
    |--------------------------------------------------------------------------
 */

class TwitterProvider implements IOAuthProvider{

    /**
     * Login Twitter-service
     * 
     * @return mixed
     */
    public function getLogin() {
        $twitterService = OAuth::consumer("Twitter","irail.dev");

        // get data from input
        $code = Input::get('oauth_token');
        $verifier = Input::get('oauth_verifier');

        if (!empty($code)) {
            // This was a callback request from Twitter, get the token
            $token = $twitterService->requestAccessToken($code, $verifier);
            
            $access_token = $token->getAccessToken();
            $request_token = $token->getRequestTokenSecret();
            
            // Send a request with it
            $result = json_decode($twitterService->request('account/verify_credentials.json'));
           
            $credentials = array(
                'email' => $result->screen_name,
                'password' => $request_token
            );

           return $credentials;            
        }
        // if not ask for permission first
        else {

            // extra request needed for oauth1 to request a request token
            $token = $twitterService->requestRequestToken();

            // get twitterService authorization
            $url = $twitterService->getAuthorizationUri(array('oauth_token' => $token));

            header('Location: ' . (string) $url);
            die();
        }
    }

    /**
     * Save Twitter-user in userstable
     * 
     * @return void
     */
    private function saveUser($result, $request_token, $access_token){
        $twitteruser = DB::table('users')->where('email', $result->screen_name)->first();

        if (empty($twitteruser)) {
            $data = new User;
            
            $data->provider = 'twitter';
            $data->token = $access_token;
            $data->email = $result->screen_name;
            $data->first_name = $result->name;
            $data->password = <PASSWORD>($request_token);
            $data->activated = 1;
       
            $data->save();
        }
    }

    /**
     * Get Twitter-friends of the current logged in user
     * 
     * @return mixed
     */
    public function getFriends() {    
        if ( Sentry::check()){
            // get ID of current logged in user
            $user_id = Auth::user()->id;
            dd($user_id);

            // check if user is logged in with Twitter
            $results = DB::select('select * from users where id = ? and provider = "twitter"', array($user_id));

            dd($results);

            $twitterService = OAuth::consumer("Twitter","irail.dev/oauth/twitter");

            $result2 = json_decode($twitterService->request('friends/ids.json?cursor=-1&screen_name=brechtvdv&count=5000'));
            //$result2 = json_decode($twitterService->request('friends/list.json?cursor=-1&screen_name=brechtvdv&skip_status=true&include_user_entities=false'));
              
            dd($result2);   
        }  
    } 

} 

?><commit_msg>TwitterProvider fixed<commit_after><?php

use hyperRail\app\models\OAuthProviders\IOAuthProvider;

 /*
    |--------------------------------------------------------------------------
    | Twitter provider
    |--------------------------------------------------------------------------
 */

class TwitterProvider implements IOAuthProvider{

    /**
     * Login Twitter-service
     * 
     * @return mixed
     */
    public function getLogin() {
        // get data from input
        $code = Input::get('oauth_token');
        $verifier = Input::get('oauth_verifier');

        $twitterService = OAuth::consumer("Twitter","irail.dev/oauth/twitter");

        if (!empty($code)) {
            // This was a callback request from Twitter, get the token
            $token = $twitterService->requestAccessToken($code, $verifier);
            $token = $token->getRequestTokenSecret();

            // Send a request with it
            $result = json_decode($twitterService->request('account/verify_credentials.json'));

            $twitteruser = DB::table('users')->where('email', $result->screen_name)->first();

            if (empty($twitteruser)) {
                $data = new User;
                
                $data->provider = 'twitter';
                $data->token = $token;
                $data->email = $result->screen_name;
                $data->first_name = $result->name;
                $data->password = <PASSWORD>($token);
                $data->activated = 1;
           
                $data->save();
            }
               
                $credentials = array(
                    'email' => $result->screen_name,
                    'password' => <PASSWORD>
                );

               return $credentials;

            
        }
        // if not ask for permission first
        else {
            // extra request needed for oauth1 to request a request token
            $token = $twitterService->requestRequestToken();

            // get twitterService authorization
            $url = $twitterService->getAuthorizationUri(array('oauth_token' => $token->getRequestToken()));

            header('Location: ' . (string) $url);
            die();
        }
    }
}  

?>
{'fraction_non_alphanumeric': 0.17793529625590696, 'fraction_numerical': 0.002362777171937477, 'mean_word_length': 1.5488652153774896, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5281212', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1343, 'n_words': 281}