public function indexAction()
 {
     $this->blockObj = new Loginradius_Sociallogin_Block_Sociallogin();
     $this->loginRadiusPopMsg = trim($this->blockObj->getPopupText());
     $this->loginRadiusPopMsg = $this->loginRadiusPopMsg == "" ? __("Please enter your email to proceed") : $this->loginRadiusPopMsg;
     $this->loginRadiusPopErr = trim($this->blockObj->getPopupError());
     $this->loginRadiusPopErr = $this->loginRadiusPopErr == "" ? __("Email you entered is either invalid or already registered. Please enter a valid email.") : $this->loginRadiusPopErr;
     if (isset($_REQUEST['token'])) {
         $this->tokenHandle();
         $this->loadLayout();
         $this->renderLayout();
         return;
     }
     // email verification
     if (isset($_GET['loginRadiusKey']) && !empty($_GET['loginRadiusKey'])) {
         $loginRadiusVkey = trim($_GET['loginRadiusKey']);
         // get entity_id and provider of the vKey
         $result = $this->loginRadiusRead("sociallogin", "verification", array($loginRadiusVkey), true);
         if ($temp = $result->fetch()) {
             // set verified status true at this verification key
             $tempUpdate = array("verified" => '1', "vkey" => '');
             $tempUpdateTwo = array("vkey = ?" => $loginRadiusVkey);
             $this->SocialLoginInsert("sociallogin", $tempUpdate, true, $tempUpdateTwo);
             SL_popUpWindow("Your email has been verified. Now you can login to your account.", "", false);
             // check if verification for same provider is still pending on this entity_id
             if ($this->loginRadiusRead("sociallogin", "verification2", array($temp['entity_id'], $temp['provider']))) {
                 $tempUpdate = array("vkey" => '');
                 $tempUpdateTwo = array("entity_id = ?" => $temp['entity_id'], "provider = ?" => $temp['provider']);
                 $this->SocialLoginInsert("sociallogin", $tempUpdate, true, $tempUpdateTwo);
             }
         }
     }
     $socialLoginProfileData = Mage::getSingleton('core/session')->getSocialLoginData();
     $sessionUserId = $socialLoginProfileData['lrId'];
     $loginRadiusPopProvider = $socialLoginProfileData['Provider'];
     $loginRadiusAvatar = $socialLoginProfileData['thumbnail'];
     if (isset($_POST['LoginRadiusRedSliderClick'])) {
         if (!empty($sessionUserId)) {
             $loginRadiusProfileData = array();
             // address
             if (isset($_POST['loginRadiusAddress'])) {
                 $loginRadiusProfileData['Address'] = "";
                 $profileAddress = trim($_POST['loginRadiusAddress']);
             }
             // city
             if (isset($_POST['loginRadiusCity'])) {
                 $loginRadiusProfileData['City'] = "";
                 $profileCity = trim($_POST['loginRadiusCity']);
             }
             // country
             if (isset($_POST['loginRadiusCountry'])) {
                 $loginRadiusProfileData['Country'] = "";
                 $profileCountry = trim($_POST['loginRadiusCountry']);
             }
             // phone number
             if (isset($_POST['loginRadiusPhone'])) {
                 $loginRadiusProfileData['PhoneNumber'] = "";
                 $profilePhone = trim($_POST['loginRadiusPhone']);
             }
             // email
             if (isset($_POST['loginRadiusEmail'])) {
                 $email = trim($_POST['loginRadiusEmail']);
                 if (!preg_match("/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})\$/", $email)) {
                     if ($this->blockObj->getProfileFieldsRequired() == 1) {
                         $hideZipCountry = false;
                     } else {
                         $hideZipCountry = true;
                     }
                     SL_popUpWindow($this->loginRadiusPopMsg, $this->loginRadiusPopErr, true, $loginRadiusProfileData, true, $hideZipCountry);
                     $this->SocialLoginShowLayout();
                     return false;
                 }
                 // check if email already exists
                 $userId = $this->loginRadiusRead("customer_entity", "email exists pop1", array($email), true);
                 if ($rowArray = $userId->fetch()) {
                     // email exists
                     //check if entry exists on same provider in sociallogin table
                     $verified = $this->loginRadiusRead("sociallogin", "email exists sl", array($rowArray['entity_id'], $loginRadiusPopProvider), true);
                     if ($rowArrayTwo = $verified->fetch()) {
                         // check verified field
                         if ($rowArrayTwo['verified'] == "1") {
                             // check sociallogin id
                             if ($rowArrayTwo['sociallogin_id'] == $sessionUserId) {
                                 $this->socialLoginUserLogin($rowArray['entity_id'], $rowArrayTwo['sociallogin_id']);
                                 return;
                             } else {
                                 SL_popUpWindow($this->loginRadiusPopMsg, $this->loginRadiusPopErr, true, array(), true, true);
                                 $this->SocialLoginShowLayout();
                                 return;
                             }
                         } else {
                             // check sociallogin id
                             if ($rowArrayTwo['sociallogin_id'] == $sessionUserId) {
                                 SL_popUpWindow("Please verify your email to login", "", false);
                                 $this->SocialLoginShowLayout();
                                 return;
                             } else {
                                 // send verification email
                                 $this->verifyUser($sessionUserId, $rowArray['entity_id'], $loginRadiusAvatar, $loginRadiusPopProvider, $email);
                                 return;
                             }
                         }
                     } else {
                         // send verification email
                         $this->verifyUser($sessionUserId, $rowArray['entity_id'], $loginRadiusAvatar, $loginRadiusPopProvider, $email);
                         return;
                     }
                 }
             }
             // validate other profile fields
             if (isset($profileAddress) && $profileAddress == "" || isset($profileCity) && $profileCity == "" || isset($profileCountry) && $profileCountry == "" || isset($profilePhone) && $profilePhone == "") {
                 SL_popUpWindow("", "Please fill all the fields", true, $loginRadiusProfileData, true);
                 $this->SocialLoginShowLayout();
                 return false;
             }
             $socialloginProfileData = Mage::getSingleton('core/session')->getSocialLoginData();
             // set provider class member variable
             $this->loginRadiusProvider = $socialloginProfileData['Provider'];
             // set Lr token
             $this->loginRadiusToken = $socialloginProfileData['lrToken'];
             // assign submitted profile fields to array
             // address
             if (isset($profileAddress)) {
                 $socialloginProfileData['Address'] = $profileAddress;
             }
             // city
             if (isset($profileCity)) {
                 $socialloginProfileData['City'] = $profileCity;
             }
             // Country
             if (isset($profileCountry)) {
                 $socialloginProfileData['Country'] = $profileCountry;
             }
             // Phone Number
             if (isset($profilePhone)) {
                 $socialloginProfileData['PhoneNumber'] = $profilePhone;
             }
             // Zipcode
             if (isset($_POST['loginRadiusZipcode'])) {
                 $socialloginProfileData['Zipcode'] = trim($_POST['loginRadiusZipcode']);
             }
             // Province
             if (isset($_POST['loginRadiusProvince'])) {
                 $socialloginProfileData['Province'] = trim($_POST['loginRadiusProvince']);
             }
             // Email
             if (isset($email)) {
                 $socialloginProfileData['Email'] = $email;
                 $verify = true;
             } else {
                 $verify = false;
             }
             Mage::getSingleton('core/session')->unsSocialLoginData();
             // unset session
             $this->socialLoginAddNewUser($socialloginProfileData, $verify);
         }
     } elseif (isset($_POST['LoginRadiusPopupCancel'])) {
         // popup cancelled
         Mage::getSingleton('core/session')->unsSocialLoginData();
         // unset session
         $url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
         header("Location:" . $url);
         // redirect to index page
         die;
     }
     // send message popup submission check
     if (isset($_POST['loginRadiusReferralSubmit'])) {
         // get temporary data saved in session before showing popup
         $sessionData = Mage::getSingleton('core/session')->getLoginRadiusTemporaryData();
         $token = isset($sessionData['token']) ? $sessionData['token'] : '';
         // check if identifier has been tampered
         if ($token == '') {
             // redirect to home page
             header("Location:" . Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK));
             // redirect to index page
             exit;
         }
         $provider = isset($sessionData['provider']) ? $sessionData['provider'] : '';
         if ($_POST['loginRadiusReferralSubmit'] == "Send Message") {
             // check if contacts are selected
             if (!isset($_POST['loginRadiusContacts']) || count($_POST['loginRadiusContacts']) <= 0) {
                 // get contacts' Social IDs
                 $this->login_radius_fetch_token($token);
                 $contacts = $this->blockObj->loginradius_get_contacts($this->loginRadiusAccessToken);
                 login_radius_message_popup($provider, $contacts->Data, '', 'Please select contacts to send referral to.');
                 return;
             }
             if ($provider == 'twitter') {
                 // send message to the contacts selected
                 $this->login_radius_fetch_token($token);
                 $this->blockObj->loginradius_send_message($this->loginRadiusAccessToken, $_POST['loginRadiusContacts'], 'test', strip_tags(trim($this->blockObj->twitterDMMessage())), $provider);
             } elseif ($provider == 'linkedin') {
                 // send message to the contacts selected
                 $this->login_radius_fetch_token($token);
                 $this->blockObj->loginradius_send_message($this->loginRadiusAccessToken, $_POST['loginRadiusContacts'], strip_tags(trim($this->blockObj->linkedinDMSubject())), strip_tags(trim($this->blockObj->linkedinDMMessage())), $provider);
             } elseif ($provider == 'google') {
                 $subject = strip_tags(trim($this->blockObj->gmailDMSubject()));
                 $message = strip_tags(trim($this->blockObj->gmailDMMessage()));
                 // send email to all recipients
                 foreach ($_POST['loginRadiusContacts'] as $email) {
                     $this->loginRadiusEmail($subject, $message, $email, '');
                 }
             } elseif ($provider == 'yahoo') {
                 $subject = strip_tags(trim($this->blockObj->yahooDMSubject()));
                 $message = strip_tags(trim($this->blockObj->yahooDMMessage()));
                 // send email to all recipients
                 foreach ($_POST['loginRadiusContacts'] as $email) {
                     $this->loginRadiusEmail($subject, $message, $email, '');
                 }
             }
             // get user id and social id
             $userId = $sessionData['user_id'];
             $socialId = $sessionData['social_id'];
             // delete temporary data
             Mage::getSingleton('core/session')->unsLoginRadiusTemporaryData();
             if ($userId == '' || $socialId == '') {
                 // redirect to home page
                 header("Location:" . Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK));
                 // redirect to index page
                 exit;
             }
             // login user
             $this->socialLoginUserLogin($userId, $socialId, false, $token, $provider);
         } elseif ($_POST['loginRadiusReferralSubmit'] == "Skip") {
             // get user id and social id
             $userId = $sessionData['user_id'];
             $socialId = $sessionData['social_id'];
             // delete temporary data
             Mage::getSingleton('core/session')->unsLoginRadiusTemporaryData();
             if ($userId == '' || $socialId == '') {
                 // redirect to home page
                 header("Location:" . Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK));
                 // redirect to index page
                 exit;
             }
             // login user
             $this->socialLoginUserLogin($userId, $socialId, false, $token, $provider);
         } else {
             // delete temporary data
             Mage::getSingleton('core/session')->unsLoginRadiusTemporaryData();
             // redirect to home page
             header("Location:" . Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK));
             // redirect to index page
             exit;
         }
     }
     $this->SocialLoginShowLayout();
 }
Example #2
0
 public function indexAction()
 {
     $this->blockObj = new Loginradius_Sociallogin_Block_Sociallogin();
     $this->loginRadiusPopMsg = trim($this->blockObj->getPopupText());
     $this->loginRadiusPopMsg = $this->loginRadiusPopMsg == "" ? __("Please enter your email to proceed") : $this->loginRadiusPopMsg;
     $this->loginRadiusPopErr = trim($this->blockObj->getPopupError());
     $this->loginRadiusPopErr = $this->loginRadiusPopErr == "" ? __("Email you entered is either invalid or already registered. Please enter a valid email.") : $this->loginRadiusPopErr;
     if (isset($_REQUEST['token'])) {
         $this->tokenHandle();
         $this->loadLayout();
         $this->renderLayout();
         return;
     }
     // email verification
     if (isset($_GET['loginRadiusKey']) && !empty($_GET['loginRadiusKey'])) {
         $loginRadiusVkey = trim($_GET['loginRadiusKey']);
         // get entity_id and provider of the vKey
         $result = $this->loginRadiusRead("sociallogin", "verification", array($loginRadiusVkey), true);
         if ($temp = $result->fetch()) {
             // set verified status true at this verification key
             $tempUpdate = array("verified" => '1', "vkey" => '');
             $tempUpdate2 = array("vkey = ?" => $loginRadiusVkey);
             $this->SocialLoginInsert("sociallogin", $tempUpdate, true, $tempUpdate2);
             $this->setTmpSession("Your email has been verified. Now you can login to your account.", "", false);
             $this->redirect(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK) . "sociallogin?loginradiuspopup=1");
             // check if verification for same provider is still pending on this entity_id
             if ($this->loginRadiusRead("sociallogin", "verification2", array($temp['entity_id'], $temp['provider']))) {
                 $tempUpdate = array("vkey" => '');
                 $tempUpdate2 = array("entity_id = ?" => $temp['entity_id'], "provider = ?" => $temp['provider']);
                 $this->SocialLoginInsert("sociallogin", $tempUpdate, true, $tempUpdate2);
             }
         }
     }
     $socialLoginProfileData = Mage::getSingleton('core/session')->getSocialLoginData();
     $session_user_id = $socialLoginProfileData['lrId'];
     $loginRadiusPopProvider = $socialLoginProfileData['Provider'];
     $loginRadiusAvatar = $socialLoginProfileData['thumbnail'];
     // popup check
     if (isset($_GET['loginradiuspopup'])) {
         SL_popUpWindow(Mage::getSingleton('core/session')->getTmpPopupTxt(), Mage::getSingleton('core/session')->getTmpPopupMsg(), Mage::getSingleton('core/session')->getTmpShowForm(), Mage::getSingleton('core/session')->getTmpProfileData(), Mage::getSingleton('core/session')->getTmpEmailRequired(), Mage::getSingleton('core/session')->getTmpHideZipcode());
         $this->SocialLoginShowLayout();
         return;
     }
     if (isset($_POST['LoginRadiusRedSliderClick'])) {
         if (!empty($session_user_id)) {
             $loginRadiusProfileData = array();
             // address
             if (isset($_POST['loginRadiusAddress'])) {
                 $loginRadiusProfileData['Address'] = "";
                 $profileAddress = trim($_POST['loginRadiusAddress']);
             }
             // city
             if (isset($_POST['loginRadiusCity'])) {
                 $loginRadiusProfileData['City'] = "";
                 $profileCity = trim($_POST['loginRadiusCity']);
             }
             // country
             if (isset($_POST['loginRadiusCountry'])) {
                 $loginRadiusProfileData['Country'] = "";
                 $profileCountry = trim($_POST['loginRadiusCountry']);
             }
             // phone number
             if (isset($_POST['loginRadiusPhone'])) {
                 $loginRadiusProfileData['PhoneNumber'] = "";
                 $profilePhone = trim($_POST['loginRadiusPhone']);
             }
             // email
             if (isset($_POST['loginRadiusEmail'])) {
                 $email = trim($_POST['loginRadiusEmail']);
                 if (!preg_match("/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})\$/", $email)) {
                     if ($this->blockObj->getProfileFieldsRequired() == 1) {
                         $hideZipCountry = false;
                     } else {
                         $hideZipCountry = true;
                     }
                     $this->setTmpSession($this->loginRadiusPopMsg, $this->loginRadiusPopErr, true, $loginRadiusProfileData, true, $hideZipCountry);
                     $this->redirect(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK) . "sociallogin?loginradiuspopup=1");
                     $this->SocialLoginShowLayout();
                     return false;
                 }
                 // check if email already exists
                 $userId = $this->loginRadiusRead("customer_entity", "email exists pop1", array($email), true);
                 if ($rowArray = $userId->fetch()) {
                     // email exists
                     //check if entry exists on same provider in sociallogin table
                     $verified = $this->loginRadiusRead("sociallogin", "email exists sl", array($rowArray['entity_id'], $loginRadiusPopProvider), true);
                     if ($rowArray2 = $verified->fetch()) {
                         // check verified field
                         if ($rowArray2['verified'] == "1") {
                             // check sociallogin id
                             if ($rowArray2['sociallogin_id'] == $session_user_id) {
                                 $this->socialLoginUserLogin($rowArray['entity_id'], $rowArray2['sociallogin_id']);
                                 return;
                             } else {
                                 $this->setTmpSession($this->loginRadiusPopMsg, $this->loginRadiusPopErr, true, array(), true, true);
                                 $this->redirect(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK) . "sociallogin?loginradiuspopup=1");
                                 $this->SocialLoginShowLayout();
                                 return;
                             }
                         } else {
                             // check sociallogin id
                             if ($rowArray2['sociallogin_id'] == $session_user_id) {
                                 $this->setTmpSession("Please provide following details", "", true, $socialloginProfileData, false);
                                 $this->redirect(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK) . "sociallogin?loginradiuspopup=1");
                                 $this->SocialLoginShowLayout();
                                 return;
                             } else {
                                 // send verification email
                                 $this->verifyUser($session_user_id, $rowArray['entity_id'], $loginRadiusAvatar, $loginRadiusPopProvider, $email);
                                 return;
                             }
                         }
                     } else {
                         // send verification email
                         $this->verifyUser($session_user_id, $rowArray['entity_id'], $loginRadiusAvatar, $loginRadiusPopProvider, $email);
                         return;
                     }
                 }
             }
             // validate other profile fields
             if (isset($profileAddress) && $profileAddress == "" || isset($profileCity) && $profileCity == "" || isset($profileCountry) && $profileCountry == "" || isset($profilePhone) && $profilePhone == "") {
                 $this->setTmpSession("", "Please fill all the fields", true, $loginRadiusProfileData, true);
                 $this->redirect(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK) . "sociallogin?loginradiuspopup=1");
                 $this->SocialLoginShowLayout();
                 return false;
             }
             $socialloginProfileData = Mage::getSingleton('core/session')->getSocialLoginData();
             // assign submitted profile fields to array
             // address
             if (isset($profileAddress)) {
                 $socialloginProfileData['Address'] = $profileAddress;
             }
             // city
             if (isset($profileCity)) {
                 $socialloginProfileData['City'] = $profileCity;
             }
             // Country
             if (isset($profileCountry)) {
                 $socialloginProfileData['Country'] = $profileCountry;
             }
             // Phone Number
             if (isset($profilePhone)) {
                 $socialloginProfileData['PhoneNumber'] = $profilePhone;
             }
             // Zipcode
             if (isset($_POST['loginRadiusZipcode'])) {
                 $socialloginProfileData['Zipcode'] = trim($_POST['loginRadiusZipcode']);
             }
             // Province
             if (isset($_POST['loginRadiusProvince'])) {
                 $socialloginProfileData['Province'] = trim($_POST['loginRadiusProvince']);
             }
             // Email
             if (isset($email)) {
                 $socialloginProfileData['Email'] = $email;
                 $verify = true;
             } else {
                 $verify = false;
             }
             Mage::getSingleton('core/session')->unsSocialLoginData();
             // unset session
             $this->socialLoginAddNewUser($socialloginProfileData, $verify);
         }
     } elseif (isset($_POST['LoginRadiusPopupCancel'])) {
         // popup cancelled
         Mage::getSingleton('core/session')->unsSocialLoginData();
         // unset session
         Mage::getSingleton('core/session')->unsTmpPopupTxt();
         Mage::getSingleton('core/session')->unsTmpPopupMsg();
         Mage::getSingleton('core/session')->unsTmpShowForm();
         Mage::getSingleton('core/session')->unsTmpProfileData();
         Mage::getSingleton('core/session')->unsTmpEmailRequired();
         Mage::getSingleton('core/session')->unsTmpHideZipcode();
         $url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
         $this->redirect($url);
         // redirect to index page
     }
     $this->SocialLoginShowLayout();
 }