Beispiel #1
0
 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $username = Token::get(self::name, $userid);
     $request = new HTTP_Request2('https://hacker-news.firebaseio.com/v0/user/' . $username . '.json');
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $karma = json_decode($response)->karma;
     Score::update(self::name, $userid, $karma);
 }
Beispiel #2
0
 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $username = Token::get(self::name, $userid);
     $request = new HTTP_Request2('http://open.dapper.net/transform.php?dappName=CodeChefProblemsSolved&transformer=JSON&v_username=' . $username);
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $score = json_decode($response)->fields->solved[32]->value;
     Score::update(self::name, $userid, $score);
 }
Beispiel #3
0
 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $lastFMUsername = Token::get(self::name, $userid);
     $request = new HTTP_Request2('http://ws.audioscrobbler.com/2.0/?method=user.getinfo&user='******'&api_key=' . LASTFM_APP_ID . '&format=json');
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $playcount = trim(json_decode($response)->user->playcount);
     Score::update(self::name, $userid, $playcount);
     //Update in database
 }
Beispiel #4
0
 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $id = Token::get(self::name, $userid);
     $request = new HTTP_Request2('https://api.stackexchange.com/2.1/users/' . $id . '?site=askubuntu&key=' . STACKEXCHANGE_KEY);
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $reputation = json_decode($response)->items[0]->reputation;
     Score::update(self::name, $userid, $reputation);
     //Update in database
 }
Beispiel #5
0
 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $access_token = Token::get(self::name, $userid);
     $request = new HTTP_Request2("https://graph.facebook.com/me/subscribers?access_token={$access_token}");
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $subscribersCount = json_decode($response)->summary->total_count;
     Score::update(self::name, $userid, $subscribersCount);
     //Update in database
 }
Beispiel #6
0
 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $twitterScreenName = Token::get(self::name, $userid);
     $request = new HTTP_Request2('https://api.twitter.com/1/users/show.json?screen_name=' . $twitterScreenName);
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $followers_count = json_decode($response)->followers_count;
     Score::update(self::name, $userid, $followers_count);
     //Update in database
 }
Beispiel #7
0
 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $username = Token::get(self::name, $userid);
     //More information at http://geekraj.com/wordpress/?p=278
     //see http://geekraj.com/euler/euler.js
     $request = new HTTP_Request2('http://www.geekraj.com/euler/getscore.php?id=' . $username);
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $score = json_decode(str_replace("'", '"', substr($response, 12, -2)))->score;
     $score = substr($score, 7);
     Score::update(self::name, $userid, $score);
 }
Beispiel #8
0
 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $id = Token::get(self::name, $userid);
     $request = new HTTP_Request2('http://api.klout.com/v2/identity.json/twitter?screenName=' . $id . '&key=' . KLOUT_APP_KEY);
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $id = json_decode($response)->id;
     $request = new HTTP_Request2('http://api.klout.com/v2/user.json/' . $id . '/score?key=' . KLOUT_APP_KEY);
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $score = (int) json_decode($response)->score;
     Score::update(self::name, $userid, $score);
     //Update in database
 }
Beispiel #9
0
 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $username = Token::get(self::name, $userid);
     $request = new HTTP_Request2('http://open.dapper.net/transform.php?dappName=ScoreFromSpoj&transformer=JSON&v_username='******' ');
     $score = substr($score, 1, $spacePosition - 1);
     Score::update(self::name, $userid, $score);
 }
Beispiel #10
0
 public static function callback()
 {
     global $HTTP_CONFIG;
     //exchange the code you get for a access_token
     $code = $_GET['code'];
     $request = new HTTP_Request2(self::ACCESS_TOKEN_URL);
     $request->setMethod(HTTP_Request2::METHOD_POST);
     $request->setConfig($HTTP_CONFIG);
     $request->addPostParameter(['client_id' => GITHUB_APP_ID, 'client_secret' => GITHUB_APP_SECRET, 'code' => $code]);
     $request->setHeader('Accept', 'application/json');
     $response = $request->send();
     $response = json_decode($response->getBody());
     $access_token = $response->access_token;
     //Use this access token to get user details
     $request = new HTTP_Request2(self::USER_URL . '?access_token=' . $access_token, HTTP_Request2::METHOD_GET, $HTTP_CONFIG);
     $response = $request->send()->getBody();
     $userid = json_decode($response)->login;
     //get the userid
     //If such a user already exists in the database
     //Just log him in and don't touch the access_token
     $already_present_token = Token::get('github', $userid);
     if ($already_present_token) {
         $_SESSION['userid'] = $userid;
         redirect_to('/');
     }
     if (defined('GITHUB_ORGANIZATION')) {
         // perform the organization check
         $request = new HTTP_Request2(json_decode($response)->organizations_url . '?access_token=' . $access_token, HTTP_Request2::METHOD_GET, $HTTP_CONFIG);
         $response = $request->send()->getBody();
         //List of organizations
         $organizations_list = array_map(function ($repo) {
             return $repo->login;
         }, json_decode($response));
         if (in_array(GITHUB_ORGANIZATION, $organizations_list)) {
             $_SESSION['userid'] = $userid;
             Token::add('github', $userid, $access_token);
         } else {
             throw new Exception('You are not in the listed members.');
         }
     } else {
         $_SESSION['userid'] = $userid;
         Token::add('github', $userid, $access_token);
     }
     redirect_to('/');
 }
Beispiel #11
0
 public function auth()
 {
     $client_id = $this->input->get('clent_id');
     $application = new Application();
     $application->client_id = $client_id;
     $application->get();
     if (!$application->exists()) {
         $data['title'] = 'Auth Page';
         $data['content'] = 'oauth/noapplication';
         $this->load->view('master', $data);
     } elseif (!$this->user_id) {
         $redirect = 'users/login?redirect_url=oauth/auth?client_id=' . $application->id;
         redirect($redirect);
     } elseif ($this->input->post()) {
         $allow = $this->input->post('allow');
         if ($allow) {
             $user = new User($this->user_id);
             $existing_token = new Token();
             $existing_token->where('user_id', $user->id);
             $existing_token->where('application_id', $application->id);
             $existing_token->get();
             if ($existing_token->exists()) {
                 $existing_token->delete();
             }
             $token = $this->generate_token();
             $token->save(array($application, $user));
             die;
             echo 'here';
         }
     } else {
         $this->load->helper('form');
         $data['application'] = array('id' => $application->id, 'name' => $application->name, 'client_id' => $application->client_id, 'client_secret' => $application->client_secret, 'redirect_url' => $application->redirect_url);
         $data['title'] = 'Auth Page';
         $data['content'] = 'oauth/authorize';
         $this->load->view('master', $data);
     }
 }
Beispiel #12
0
 private function cleanExpire()
 {
     $arch = new Archiviste();
     $token = new Token();
     $tokens = $arch->restituer($token);
     $toDay = time();
     foreach ($tokens as $tokenTemp) {
         $token = new Token();
         $token->setAttributs($tokenTemp->getAttributs());
         $expire = $token->get("expire");
         if ($expire < $toDay) {
             $arch->supprimer($token);
         }
     }
 }
Beispiel #13
0
 * Home page shows all scores
 * for all users
 */
dispatch('/', 'Score::view_all');
dispatch('/debug', function () {
    return json($_SESSION);
});
/* Authentication Related Stuff */
dispatch('/login/:service', function () {
    $serviceClassName = ucfirst(params('service'));
    //since github is our main authentication method
    //we allow that to run unauthenticated
    if (!@$_SESSION['userid'] && $serviceClassName != 'Github') {
        throw new Exception('You need to be logged in');
    }
    set('username', Token::get(params('service'), $_SESSION['userid']));
    return $obj = $serviceClassName::login();
});
dispatch('/login/:service/callback', function () {
    $serviceClassName = ucfirst(params('service'));
    if (!@$_SESSION['userid'] && $serviceClassName != 'Github') {
        throw new Exception('You need to be logged in');
    }
    return $serviceClassName::callback();
});
dispatch('/logout', function () {
    unset($_SESSION['userid']);
    redirect_to('/');
});
/*
 * Update score for a particular