/** * Response for path 'user/sociallogin' * * Handle token and validate the user. * */ public function userRegisterValidate() { $config = \Drupal::config('sociallogin.settings'); if (isset($_GET['action_completed']) && $_GET['action_completed'] == 'register') { drupal_set_message('Email for verification has been sent to your provided email id, check email for further instructions'); return $this->redirect("<front>"); } if (isset($_GET['action_completed']) && $_GET['action_completed'] == 'forgotpassword') { drupal_set_message('Password reset information sent to your provided email id, check email for further instructions'); return $this->redirect("<front>"); } // handle email popup. if (isset($_POST['lr_emailclick'])) { return $this->user_manager->emailPopupSubmit(); } elseif (isset($_POST['lr_emailclick_cancel'])) { unset($_SESSION['lrdata']); return $this->redirect('<current>'); } elseif (isset($_REQUEST['token'])) { $apiSecret = trim($config->get('api_secret')); $apiKey = trim($config->get('api_key')); try { $socialLoginObj = new SocialLoginAPI($apiKey, $apiSecret, array('output_format' => TRUE, 'authentication' => FALSE)); } catch (LoginRadiusException $e) { \Drupal::logger('sociallogin')->error($e); drupal_set_message($e->getMessage(), 'error'); return $this->redirect('user.login'); } //Get Access token. try { $result_accesstoken = $socialLoginObj->exchangeAccessToken(trim($_REQUEST['token'])); } catch (LoginRadiusException $e) { \Drupal::logger('sociallogin')->error($e); drupal_set_message($e->getMessage(), 'error'); return $this->redirect('user.login'); } //Get Userprofile form Access Token. try { $userprofile = $socialLoginObj->getUserProfiledata($result_accesstoken->access_token); $userprofile->widget_token = $result_accesstoken->access_token; } catch (LoginRadiusException $e) { \Drupal::logger('sociallogin')->error($e); drupal_set_message($e->getMessage(), 'error'); return $this->redirect('user.login'); } // Advanced module LR Code Hook Start. // Make sure at least one module implements our hook. if (count(\Drupal::moduleHandler()->getImplementations('add_loginradius_userdata')) > 0) { // Call all modules that implement the hook, and let them. // Make changes to $variables. $result = \Drupal::moduleHandler()->invokeAll('add_loginradius_userdata', [$userprofile, $userprofile->widget_token]); $value = end($result); if (!empty($value)) { $userprofile = $value; } } // Advanced module LR Code Hook End. if (\Drupal::currentUser()->isAnonymous()) { if (isset($userprofile) && isset($userprofile->ID) && $userprofile->ID != '') { $userprofile = $this->user_manager->getUserData($userprofile); $_SESSION['user_verify'] = 0; if ($config->get('email_required') == 1 && empty($userprofile->Email_value)) { $uid = $this->user_manager->checkProviderID($userprofile->ID); if ($uid) { $drupal_user = User::load($uid); } if (isset($drupal_user) && $drupal_user->id()) { return $this->user_manager->provideLogin($drupal_user, $userprofile); } else { $_SESSION['lrdata'] = $userprofile; $text_email_popup = $config->get('popup_status'); $popup_params = array('msg' => $this->t($text_email_popup, array('@provider' => t($userprofile->Provider))), 'provider' => $userprofile->Provider, 'msgtype' => 'status'); $popup_params['message_title'] = $config->get('popup_title'); return $form['email_popup'] = $this->user_manager->getPopupForm($popup_params); } } return $this->user_manager->checkExistingUser($userprofile); } } else { return $this->user_manager->handleAccountLinking($userprofile); } } else { return $this->redirect('user.login'); } }
//use LoginRadiusSDK\CustomerRegistration\AccountAPI; //use LoginRadiusSDK\CustomerRegistration\CustomObjectAPI; $app->get('/', function ($request, $response) { // Render index view return $this->renderer->render($response, 'login.phtml'); }); $app->post('/login-callback', function ($request, $response, $args) { $this->logger->info("Callback "); $request_token = $request->getParams(); try { $responseArr = ['status' => "failure", "msg" => "Something went wrong. Would you mind giving a try again?"]; $socialLoginObject = new SocialLoginAPI(LR_API_KEY, LR_API_SECRET, array('authentication' => false, 'output_format' => 'json')); $accesstoken = $socialLoginObject->exchangeAccessToken($request_token['token']); //$request_token loginradius token get from social/traditional interface after success authentication. $accesstoken = $accesstoken->access_token; $userProfileData = $socialLoginObject->getUserProfiledata($accesstoken); if (!empty($userProfileData->Email)) { $responseArr = ['status' => "success", "msg" => "Successfully logged in"]; /* * Call MailChimp here */ $userData = ['FNAME' => $userProfileData->FirstName, 'LNAME' => $userProfileData->LastName]; foreach ($userProfileData->Email as $email) { $userData['EMAIL'] = $email->Value; } $mailChimpObj = new Mailchimp(MAILCHIMP_API_KEY); $mailChimpListsObj = new Mailchimp_Lists($mailChimpObj); //(MAILCHIMP_API_KEY); $allList = $mailChimpListsObj->getList(); if (intval($allList["total"]) >= 1) { $subscriberListId = null;
require_once __DIR__ . '/classes/authentication.php'; //If user is not logged in then return to index page if (!isset($_SESSION['user_id'])) { header("Location: index.php"); exit; } use LoginRadiusSDK\LoginRadius; use LoginRadiusSDK\SocialLogin\SocialLoginAPI; use LoginRadiusSDK\LoginRadiusException; $post_value = $_POST; $post_func = isset($post_value['func']) && !empty($post_value['func']) ? trim($post_value['func']) : ''; $accessToken = isset($_SESSION['access_token']) && !empty($_SESSION['access_token']) ? trim($_SESSION['access_token']) : ''; $userRegBasic = new SocialLoginAPI(LR_API_KEY, LR_API_SECRET, array('authentication' => false, 'output_format' => 'json')); try { if ($post_func == 'extendedProfile') { $output = $userRegBasic->getUserProfiledata($accessToken); } else { if ($post_func == 'contact') { $output = $userRegBasic->getContacts($accessToken); } else { if ($post_func == 'likes') { $output = $userRegBasic->getLikes($accessToken); } else { if ($post_func == 'albums') { $output = $userRegBasic->getPhotoAlbums($accessToken); } else { if ($post_func == 'checkins') { $output = $userRegBasic->getCheckins($accessToken); } else { if ($post_func == 'audio') { $output = $userRegBasic->getAudio($accessToken);
public static function getProfiles() { $userRegBasic = new SocialLoginAPI(LR_API_KEY, LR_API_SECRET, array('authentication' => false, 'output_format' => 'json')); $output = ''; try { $result_accesstoken = $userRegBasic->exchangeAccessToken($_REQUEST['token']); $accessToken = $result_accesstoken->access_token; } catch (LoginRadiusException $e) { self::setMessage($e->getErrorResponse()->description); } if (!empty($accessToken)) { $_SESSION['userprofile'] = $userRegBasic->getUserProfiledata($accessToken); $_SESSION['access_token'] = $accessToken; $output = "You're traditionally loggedin"; } return $output; }