public function request($path, $query_array = array(), $options = array()) { $parse_url = parse_url($path); if (isset($parse_url['scheme']) && !empty($parse_url['scheme'])) { $validate_url = $path; } else { $validate_url = API_DOMAIN . $path; } $method = isset($options['method']) ? strtolower($options['method']) : 'get'; $post_data = isset($options['post_data']) ? $options['post_data'] : array(); $content_type = isset($options['content_type']) ? $options['content_type'] : 'form_params'; $ssl_verify = isset($options['ssl_verify']) ? $options['ssl_verify'] : FALSE; $httpclient_options['verify'] = $ssl_verify; if ($method == 'post') { $httpclient_options[$content_type] = $post_data; } if ($query_array !== FALSE) { $validate_url .= '?' . LoginRadius::queryBuild(LoginRadius::authentication($query_array)); } try { $response = \Drupal::httpClient()->{$method}($validate_url, $httpclient_options); $data = (string) $response->getBody(); return $data; } catch (RequestException $e) { throw new LoginRadiusException($e->getMessage(), $e); } catch (ClientException $e) { throw new LoginRadiusException($e->getMessage(), $e); } catch (Exception $e) { throw new LoginRadiusException($e->getMessage(), $e); } }
public function execute(\Magento\Framework\Event\Observer $observer) { $activationHelper = $this->_objectManager->get('LoginRadius\\Activation\\Model\\Helper\\Data'); $customerRegistrationHelper = $this->_objectManager->get("LoginRadius" . "\\" . $activationHelper->getAuthDirectory() . "\\Model\\Helper\\Data"); if ($customerRegistrationHelper->enableRaas() != '1') { return; } $events = $observer->getEvent(); $customer = $events->getCustomerDataObject(); $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#\$%^&*()_-=?"; $birthDate = date("m-d-Y", strtotime($customer->getDob())); $newUserData = array('emailid' => $customer->getEmail(), 'firstname' => $customer->getFirstname(), 'lastname' => $customer->getLastname(), 'password' => substr(str_shuffle($chars), 0, 8), 'gender' => $this->getGenderValue($customer->getGender()), 'birthdate' => $birthDate); $userAPI = new \LoginRadiusSDK\CustomerRegistration\UserAPI($activationHelper->siteApiKey(), $activationHelper->siteApiSecret(), array('authentication' => true, 'output_format' => 'json')); $homeDomain = $this->_objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore()->getBaseUrl(); if (!isset($_POST['customer']['entity_id'])) { try { $userCreatedata = $userAPI->create($newUserData); try { $rsetPasswordUrl = 'https://api.loginradius.com/raas/client/password/forgot?apikey=' . $activationHelper->siteApiKey() . '&emailid=' . $customer->getEmail() . '&resetpasswordurl=' . $homeDomain . 'customer/account/login/'; $result = \LoginRadiusSDK\LoginRadius::apiClient($rsetPasswordUrl, FALSE, array('output_format' => 'json')); } catch (\LoginRadiusSDK\LoginRadiusException $e) { $errorDescription = isset($e->getErrorResponse()->description) ? $e->getErrorResponse()->description : ''; $this->_messageManager->addError($errorDescription); } try { $this->socialLinkingData($customer->getId(), $userCreatedata); } catch (\Exception $e) { } } catch (\LoginRadiusSDK\LoginRadiusException $e) { } return; } }
/** * LoginRadius function - To fetch social login providers * * @param string $apikey data to validate. * * @return object Social Login Providers/error messages. * * try{ * $providers = $GetProvidersAPIObject->getProvidersList(); * } * catch (LoginRadiusException $e){ * $e->getMessage(); * } */ public function getProvidersList() { $url = LR_CDN_ENDPOINT . "/interface/json/" . LoginRadius::getApiKey() . ".json"; $response = LoginRadius::apiClient($url); $jsonResponse = explode('(', $response); if ($jsonResponse[0] == 'loginRadiusAppJsonLoaded') { return str_replace(')', '', $jsonResponse[1]); } throw new LoginRadiusException('Error Retrieving Providers List'); }
public function execute() { $this->_helperActivation = $this->_objectManager->get('LoginRadius\\Activation\\Model\\Helper\\Data'); $this->_helperCustomerRegistration = $this->_objectManager->get('LoginRadius\\' . $this->_helperActivation->getAuthDirectory() . '\\Model\\Helper\\Data'); if ($this->_helperCustomerRegistration->enableRaas() != '1') { return parent::execute(); } $resultRedirect = $this->resultRedirectFactory->create(); $accountApi = new \LoginRadiusSDK\CustomerRegistration\AccountAPI($this->_helperActivation->siteApiKey(), $this->_helperActivation->siteApiSecret(), array('authentication' => true, 'output_format' => 'json')); $customerId = (int) $this->getRequest()->getParam('customer_id', 0); $customer = $this->_customerRepository->getById($customerId); $homeDomain = $this->_objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore()->getBaseUrl(); try { $rsetPasswordUrl = 'https://api.loginradius.com/raas/client/password/forgot?apikey=' . rawurlencode(trim($this->_helperActivation->siteApiKey())) . '&emailid=' . $customer->getEmail() . '&resetpasswordurl=' . $homeDomain . 'customer/account/login/'; $this->messageManager->addSuccess(__('The customer will receive an email with a link to reset password.')); } catch (\LoginRadiusSDK\LoginRadiusException $e) { $errorDescription = isset($e->getErrorResponse()->description) ? $e->getErrorResponse()->description : ''; $this->_messageManager->addError($errorDescription); } $result = \LoginRadiusSDK\LoginRadius::apiClient($rsetPasswordUrl, FALSE, array('output_format' => 'json')); $resultRedirect->setPath('customer/*/edit', ['id' => $customerId, '_current' => true]); return $resultRedirect; }
/** * handle account APIs * * @param type $path * @param type $query_array * @param type $options * @return type */ private function apiClientHandler($path, $query_array = array(), $options = array()) { return LoginRadius::apiClient("/raas/v1/account/" . $path, $query_array, $options); }
/** * Access LoginRadius API server by fsockopen method * * @param type $request_url * @param type $options * @return type */ private function fsockopenApiMethod($request_url, $options = array()) { $ssl_verify = isset($options['ssl_verify']) ? $options['ssl_verify'] : false; $method = isset($options['method']) ? strtolower($options['method']) : 'get'; $data = isset($options['post_data']) ? $options['post_data'] : array(); $content_type = isset($options['content_type']) ? $options['content_type'] : 'form_params'; if (!empty($data)) { $options = array('http' => array('method' => strtoupper($method), 'timeout' => 50, 'header' => 'Content-type :application/' . $content_type, 'content' => $content_type == 'json' ? json_encode($data) : LoginRadius::queryBuild($data)), "ssl" => array("verify_peer" => $ssl_verify)); $context = stream_context_create($options); } else { $context = NULL; } $json_response = @file_get_contents($request_url, false, $context); if (!$json_response) { throw new LoginRadiusException('file_get_contents error'); } return $json_response; }
/** * Manage LoginRadius Authentication * * @param type $array * @return type */ public static function authentication($array = array()) { $result = array("appkey" => LoginRadius::getApiKey(), "appsecret" => LoginRadius::getApiSecret()); if (is_array($array) && sizeof($array) > 0) { $result = array_merge($result, $array); } return $result; }
<?php require_once __DIR__ . '/vendor/autoload.php'; use LoginRadiusSDK\LoginRadius; $api_secret = 'your_api_secret'; if (LoginRadius::loginradius_is_callback()) { /* This will not be triggered since there is no _REQUEST['token']*/ echo "call back succeed"; } else { /* Will run this*/ echo "Call back failed, but loginradius class is found."; }
/** * Social API heandler * * @param type $path * @param type $raw_data * @param type $query_array * @param type $options * @return type */ private function apiClientHandler($path, $raw_data, $query_array = array(), $options = array()) { $raw = $raw_data ? '/raw' : ''; return LoginRadius::apiClient("/api/v2/" . $path . $raw, $query_array, $options); }