/**
  * Connceting to Twitter network for retreiving profile informaion
  *
  * @access public
  * @since 1.0
  * @return void 
  */
 public function login()
 {
     $callback_url = upme_add_query_string($this->callback_url(), 'upme_social_login=Twitter&upme_social_action=verify');
     $upme_social_action = isset($_GET['upme_social_action']) ? $_GET['upme_social_action'] : '';
     $response = new stdClass();
     /* Configuring settings for Twitter application */
     $app_config = array('appKey' => $this->upme_settings['social_login_twitter_app_key'], 'appSecret' => $this->upme_settings['social_login_twitter_app_secret']);
     @session_start();
     if ($upme_social_action == 'login') {
         $twitter_api = new upme_TwitterOAuth($app_config['appKey'], $app_config['appSecret']);
         /* Retrive access token from Twitter */
         $response_twitter = $twitter_api->getRequestToken($callback_url);
         $_SESSION['oauth_token'] = $response_twitter['oauth_token'];
         $_SESSION['oauth_token_secret'] = $response_twitter['oauth_token_secret'];
         if ($twitter_api->http_code == 200) {
             /* Generate the URL and redirect to Twitter for authentication */
             $url = $twitter_api->getAuthorizeURL($response_twitter['oauth_token']);
             $this->redirect($url);
         } else {
             $response->error_code = $twitter_api->http_code;
             $response->error_message = upme_language_entry('Request token retrieval failed');
             $this->handle_social_error('Twitter', $response->error_code);
         }
     } elseif (isset($_REQUEST['oauth_token']) && isset($_REQUEST['oauth_verifier'])) {
         $twitter_api = new upme_TwitterOAuth($app_config['appKey'], $app_config['appSecret'], $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
         $access_token = $twitter_api->getAccessToken($_GET['oauth_verifier']);
         $_SESSION['access_token'] = $access_token;
         $user_info = $twitter_api->get('account/verify_credentials');
         if ($user_info) {
             $response->status = TRUE;
             $response->upme_network_type = 'twitter';
             $response->first_name = str_replace(' ', '', $user_info->name);
             $response->last_name = '';
             $response->email = $user_info->screen_name . '@twitter.com';
             $response->username = $user_info->screen_name;
             $response->error_message = '';
         } else {
             /* Handling Twitter specific errors */
             $response->status = FALSE;
             $response->error_code = 'user_profile_failed';
             $response->error_message = upme_language_entry('Error retrieving profile information');
             $this->handle_social_error('Twitter', $response->error_code);
         }
     }
     return $response;
 }
 /**
  * Connceting to Facebook network for retreiving profile informaion
  *
  * @access public
  * @since 1.0
  * @return void 
  */
 public function login()
 {
     $callback_url = upme_add_query_string($this->callback_url(), 'upme_social_login=Facebook&upme_social_action=verify');
     $upme_social_action = isset($_GET['upme_social_action']) ? $_GET['upme_social_action'] : '';
     $response = new stdClass();
     /* Configuring settings for LinkedIn application */
     $app_config = array('appId' => $this->upme_settings['social_login_facebook_app_id'], 'secret' => $this->upme_settings['social_login_facebook_app_secret']);
     $facebook = new upme_Facebook($app_config);
     if ($upme_social_action == 'login') {
         /* Get the login URL and redirect the user to Facebook for authentication */
         $loginUrl = $facebook->getLoginUrl(array('redirect_uri' => $callback_url, 'scope' => 'email'));
         $this->redirect($loginUrl);
         exit;
     } else {
         /* Retreive the user information from Facebook */
         $user = $facebook->getUser();
         if ($user) {
             try {
                 $user_profile = $facebook->api('/me');
             } catch (FacebookApiException $e) {
                 /* Handling Facebook specific errors */
                 $user = null;
                 $response->error_code = $e->getCode();
                 $response->error_message = $e->getMessage();
                 $this->handle_social_error('Facebook', $response->error_code);
             }
         }
         if ($user) {
             /* Create the user profile object from response */
             $response->status = TRUE;
             $response->upme_network_type = 'facebook';
             $response->first_name = $user_profile['first_name'];
             $response->last_name = $user_profile['last_name'];
             $response->email = $user_profile['email'];
             $response->username = $user_profile['email'];
             $response->error_message = '';
         } else {
             /* Handling Facebook specific errors */
             $response->error_code = 'auth_invalid';
             $response->error_message = upme_language_entry('Invalid Authorization');
             $this->handle_social_error('Facebook', $response->error_code);
         }
     }
     return $response;
 }
function upme_login_after_head($display)
{
    if (isset($_GET['upme_err_code'])) {
        $err_code = $_GET['upme_err_code'];
        $message = '';
        switch ($err_code) {
            case 'user_profile_failed':
                $message = upme_language_entry('Error retrieving profile information. Please try again later.');
                break;
            case 'req_token_fail':
                $message = upme_language_entry('Request token retrieval failed. Please try again later.');
                break;
            case 'req_profile_fail':
                $message = upme_language_entry('Error retrieving profile information. Please try again later.');
                break;
            case 'access_token_fail':
                $message = upme_language_entry('Access token retrieval failed. Please try again later.');
                break;
            case 'user_refused':
                $message = upme_language_entry('User refused by application. Please try again later.');
                break;
            case 'req_cancel':
                $message = upme_language_entry('Request cancelled by user.');
                break;
            case 'auth_invalid':
                $message = upme_language_entry('Invalid authorization.  Please try again later.');
                break;
            default:
                $message = upme_language_entry('Social login request failed.');
                break;
        }
        if (!$_POST) {
            $display = '<div class="upme-main">
							<div class="upme-errors">
								<span class="upme-error upme-error-block">
									<i class="upme-icon-remove"></i>' . $message . '
								</span>
							</div>
					</div>';
        }
        return $display;
    }
}
 /**
  * Connceting to Google network for retreiving profile informaion
  *
  * @access public
  * @since 1.0
  * @return void 
  */
 public function login()
 {
     $callback_url = upme_add_query_string($this->callback_url(), 'upme_social_login=Google&upme_social_action=verify');
     $redirect_url = upme_add_query_string($this->callback_url(), 'upme_social_login=Google&upme_social_action=verify');
     $upme_social_action = isset($_GET['upme_social_action']) ? $_GET['upme_social_action'] : '';
     $response = new stdClass();
     /* Configuring settings for Google application */
     $client_id = $this->upme_settings['social_login_google_client_id'];
     $client_secret = $this->upme_settings['social_login_google_client_secret'];
     @session_start();
     $client = new Google_Client();
     $client->setClientId($client_id);
     $client->setClientSecret($client_secret);
     $client->setRedirectUri($callback_url);
     $client->addScope("https://www.googleapis.com/auth/plus.profile.emails.read");
     $service = new Google_Service_Plus($client);
     if ($upme_social_action == 'login') {
         if (!(isset($_SESSION['googleplus_access_token']) && $_SESSION['googleplus_access_token'])) {
             $authUrl = $client->createAuthUrl();
             $this->redirect($authUrl);
             die;
         } else {
             $this->redirect($callback_url);
             die;
         }
     } elseif (isset($_GET['code'])) {
         // Perform HTTP Request to OpenID server to validate key
         $client->authenticate($_GET['code']);
         $_SESSION['googleplus_access_token'] = $client->getAccessToken();
         $this->redirect($callback_url);
         die;
     } elseif (isset($_SESSION['googleplus_access_token']) && $_SESSION['googleplus_access_token']) {
         $client->setAccessToken($_SESSION['googleplus_access_token']);
         try {
             $user = $service->people->get("me", array());
         } catch (Exception $fault) {
             unset($_SESSION['googleplus_access_token']);
             $this->redirect($callback_url);
             die;
         }
         if (!empty($user)) {
             // OK HERE KEY IS VALID
             if (!empty($user->emails)) {
                 $response->email = $user->emails[0]->value;
                 $response->username = $user->emails[0]->value;
                 $response->first_name = $user->name->givenName;
                 $response->upme_network_type = 'google';
                 $response->status = TRUE;
                 $response->error_message = '';
             } else {
                 $response->status = FALSE;
                 $response->error_code = 'auth_invalid';
                 $response->error_message = upme_language_entry('Invalid Authorization.');
                 $this->handle_social_error('Google', $response->error_code);
             }
         } else {
             $response->status = FALSE;
             $response->error_code = "signature_verify_failed";
             $response->error_message = upme_language_entry('Invalid Authorization.');
             $this->handle_social_error('Google', $response->error_code);
         }
     } elseif ($get['openid_mode'] == 'cancel') {
         $response->status = FALSE;
         $response->error_code = 'cancel_request';
         $response->error_message = upme_language_entry('User Canceled Request.');
         $this->handle_social_error('Google', $response->error_code);
     } else {
         $response->status = FALSE;
         $response->error_code = 'auth_invalid';
         $response->error_message = upme_language_entry('User Login Failed.');
         $this->handle_social_error('Google', $response->error_code);
     }
     return $response;
 }
 /**
  * Connceting to LinkedIn network for retreiving profile informaion
  *
  * @access public
  * @since 1.0
  * @return void 
  */
 public function login()
 {
     $callback_url = upme_add_query_string($this->callback_url(), 'upme_social_login=Linkedin&upme_social_action=verify');
     $upme_social_action = isset($_GET['upme_social_action']) ? $_GET['upme_social_action'] : '';
     $response = new stdClass();
     /* Configuring settings for LinkedIn application */
     $app_config = array('appKey' => $this->upme_settings['social_login_linkedin_app_key'], 'appSecret' => $this->upme_settings['social_login_linkedin_app_secret'], 'callbackUrl' => $callback_url);
     @session_start();
     $linkedin_api = new upme_LinkedIn($app_config);
     if ($upme_social_action == 'login') {
         /* Retrive access token from LinkedIn */
         $response_linkedin = $linkedin_api->retrieveTokenRequest(array('scope' => 'r_emailaddress'));
         if ($response_linkedin['success'] === TRUE) {
             /* Redirect the user to LinkedIn for login and authorizing the application */
             $_SESSION['oauth']['linkedin']['request'] = $response_linkedin['linkedin'];
             $this->redirect(upme_LinkedIn::_URL_AUTH . $response_linkedin['linkedin']['oauth_token']);
         } else {
             $response->error_code = 'req_token_fail';
             $response->error_message = upme_language_entry('Request token retrieval failed');
             $this->handle_error('Linkedin', $response->error_code);
         }
     } elseif (isset($_GET['oauth_verifier'])) {
         /* LinkedIn has sent a response, user has granted permission, take the temp access 
            token, the user's secret and the verifier to request the user's real secret key */
         $response_linkedin = $linkedin_api->retrieveTokenAccess($_SESSION['oauth']['linkedin']['request']['oauth_token'], $_SESSION['oauth']['linkedin']['request']['oauth_token_secret'], $_GET['oauth_verifier']);
         if ($response_linkedin['success'] === TRUE) {
             $linkedin_api->setTokenAccess($response_linkedin['linkedin']);
             $linkedin_api->setResponseFormat(upme_LinkedIn::_RESPONSE_JSON);
             /* Get user profile information using the retrived access token */
             $user_result = $linkedin_api->profile('~:(email-address,id,first-name,last-name,picture-url)');
             if ($user_result['success'] === TRUE) {
                 /* setting the user data object from the response */
                 $data = json_decode($user_result['linkedin']);
                 $response->status = TRUE;
                 $response->upme_network_type = 'linkedin';
                 $response->first_name = $data->firstName;
                 $response->last_name = $data->lastName;
                 $response->email = $data->emailAddress;
                 $response->username = $data->emailAddress;
                 $response->error_message = '';
             } else {
                 /* Handling LinkedIn specific errors */
                 $response->status = FALSE;
                 $response->error_code = 'req_profile_fail';
                 $response->error_message = upme_language_entry('Error retrieving profile information');
                 $this->handle_social_error('Linkedin', $response->error_code);
             }
         } else {
             /* Handling LinkedIn specific errors */
             $response->status = FALSE;
             $response->error_code = 'access_token_fail';
             $response->error_message = upme_language_entry('Access token retrieval failed');
             $this->handle_social_error('Linkedin', $response->error_code);
         }
     } else {
         /* Handling LinkedIn specific errors */
         if (isset($_GET['oauth_problem']) && $_GET['oauth_problem'] == 'user_refused') {
             $response->status = FALSE;
             $response->error_code = 'user_refused';
             $response->error_message = upme_language_entry('User refused by application.');
             $this->handle_social_error('Linkedin', $response->error_code);
         } else {
             $response->status = FALSE;
             $response->error_code = 'req_cancel';
             $response->error_message = upme_language_entry('Request cancelled by user!');
             $this->handle_social_error('Linkedin', $response->error_code);
         }
     }
     return $response;
 }