usertoken not updating in the database

edited April 2016 in Social Login
i did the following for my call back url as below code
<?php // Check if we have received a connection_token if ( ! empty ($_POST['connection_token'])) { // Get connection_token $token = $_POST['connection_token']; // Your Site Settings $site_subdomain = '#';// i used my values $site_public_key = '#'; $site_private_key = '#'; // API Access domain $site_domain = $site_subdomain.''; // Connection Endpoint // $resource_uri = 'https://'.$site_domain.'/connections/'.$token .'.json'; // Setup connection $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $resource_uri); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_USERPWD, $site_public_key . ":" . $site_private_key); curl_setopt($curl, CURLOPT_TIMEOUT, 15); curl_setopt($curl, CURLOPT_VERBOSE, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($curl, CURLOPT_FAILONERROR, 0); // Send request $result_json = curl_exec($curl); // Error if ($result_json === false) { //You may want to implement your custom error handling here echo 'Curl error: ' . curl_error($curl). '<br />'; echo 'Curl info: ' . curl_getinfo($curl). '<br />'; curl_close($curl); } // Success else { // Close connection curl_close($curl); // Decode $json = json_decode ($result_json); // Extract data $data = $json->response->result->data; // Check for service switch ($data->plugin->key) { // Social Login case 'social_login': // Single Sign On case 'single_sign_on': // Operation successful if ($data->plugin->data->status == 'success') { // The user_token uniquely identifies the user // that has connected with his social network account $user_token = $data->user->user_token; // The identity_token uniquely identifies the social network account // that the user has used to connect with $identity_token = $data->user->identity->identity_token; $stmt = $db->prepare("SELECT uid FROM employee WHERE user_token ='$user_token' "); $stmt->execute(); $user_id = $stmt->fetchColumn(); // 1) Check if you have a userID for this token in your database //$user_id = GetUserIdForUserToken($user_token); // 1a) If the userID is empty then this is the first time that this user // has connected with a social network account on your website if ($user_id === null) { $stmt = $db->prepare("INSERT INTO employee(email,ename) VALUES(' ',' ')"); //i used db connection in pdo not displyed here for security reaons $stmt->execute(); $user_id = $stmt->lastInsertId(); // 1a1) Create a new user account and store it in your database // Optionally display a form to collect more data about the user. // $user_id = {The ID of the user that you have created} $stmt = $db->prepare("UPDATE employee SET user_token='$user_token' WHERE uid='$uid' "); // 1a2) Attach the user_token to the userID of the created account. } // 1b) If you DO have an userID for the user_token then this user has // already connected before else { // 1b1) The account already exists } // 2) You have either created a new user or read the details of an existing // 2a) Create a Single Sign On session // If you would like to use Single Sign on then you should now call our API // to generate a new SSO Session: // 2b) Login this user // You now need to login this user, exactly like you would login a user // after a traditional (username/password) login (i.e. set cookies, setup // the session) and forward him to another page (i.e. his account dashboard) } break; } } }?>

it is redirecting to member page but values are not updating in database

Best Answer

  • Claude_SchlesserClaude_SchlesserAdministratorOneAll Team
    edited April 2016 Answer ✓

    there is no

    $stmt = $db->prepare("UPDATE employee SET user_token='$user_token' WHERE uid='$uid' ");

    So basically you are preparing the sql query, but actually not executing it.


    Please sign in to your OneAll account to ask a new question or to contribute to the discussions.

    Please click on the link below to connect to the forum with your OneAll account.