/**
  * Response for path 'user/raas'
  *
  * Handle token and validate the user.
  *
  * @todo add destination handling: https://www.drupal.org/node/2524328
  */
 public function userChangePassword($user)
 {
     $post_value = $_POST;
     $config = \Drupal::config('sociallogin.settings');
     $apiKey = trim($config->get('api_key'));
     $apiSecret = trim($config->get('api_secret'));
     $raasUid = $this->user_manager->userregistration_get_raas_uid($user);
     if (isset($post_value['emailid']) && !empty($post_value['emailid']) && isset($post_value['password']) && !empty($post_value['password'])) {
         $params = array('accountid' => $raasUid, 'password' => $post_value['password'], 'emailid' => $post_value['emailid']);
         $result = $this->user_manager->create_raas_profile($params);
         //  $response = $raas_sdk->raasGetRaasProfile($raasUid);
         //  lr_social_login_insert_into_mapping_table($response->ID, 'RAAS', $user);
         if (isset($result->isPosted) && $result->isPosted) {
             try {
                 $accountObj = new AccountAPI($apiKey, $apiSecret, array('output_format' => 'json'));
                 $response = $accountObj->getAccounts($raasUid);
                 $raasUname = '';
                 foreach ($response as $k => $val) {
                     if (isset($val->Provider) && strtolower($val->Provider) == 'raas') {
                         $raasUname = $val->UserName;
                         $raas_provider_id = $val->ID;
                         break;
                     }
                 }
                 if (empty($raasUname)) {
                     $provider_uname = $this->user_manager->userregistration_get_raas_uname($user);
                     $params = array('UserName' => $provider_uname);
                     if ($raas_provider_id) {
                         $userObject = new UserAPI($apiKey, $apiSecret, array('output_format' => 'json'));
                         $userObject->edit($raas_provider_id, $params);
                     }
                 }
                 drupal_set_message(t('Password set successfully.'));
             } catch (LoginRadiusException $e) {
                 $msg = isset($e->getErrorResponse()->description) ? $e->getErrorResponse()->description : 'Password is not set';
                 drupal_set_message(t($msg), 'error');
             }
         } else {
             $msg = isset($result) ? $result : 'Password is not set';
             drupal_set_message(t($msg), 'error');
         }
     } elseif (isset($post_value['newpassword']) && !empty($post_value['newpassword'])) {
         if (!empty($raasUid)) {
             $result = $this->user_manager->update_user_password($raasUid, $post_value['oldpassword'], $post_value['newpassword']);
             if (isset($result->isPosted) && $result->isPosted) {
                 drupal_set_message(t('Password changed successfully.'));
             } else {
                 $msg = isset($result) ? $result : 'Password is not changed';
                 drupal_set_message(t($msg), 'error');
             }
         }
     }
     $output = array('#title' => t('Change Password'), '#theme' => 'change_password', '#attributes' => array('class' => array('change-password')));
     return $output;
 }
Example #2
0
 /**
  * @param $post_value
  * Update User profile data.
  *
  */
 public static function updateProfile($post_value)
 {
     $userRegUser = new UserAPI(LR_API_KEY, LR_API_SECRET, array('output_format' => 'json'));
     $data = $_SESSION['userprofile'];
     unset($post_value['update']);
     if (!empty($data->ID)) {
         try {
             $result = $userRegUser->edit($data->ID, $post_value);
             if (isset($result->isPosted) && $result->isPosted) {
                 $user_profile = $userRegUser->getProfileByID($data->ID);
                 $profile_data = self::mapProfile($user_profile);
                 $_SESSION['userprofile'] = $profile_data;
                 self::setMessage("Profile updated successfully");
             }
         } catch (LoginRadiusException $e) {
             self::setMessage($e->getErrorResponse()->description);
         }
     }
 }
 function userregistration_create_user($data)
 {
     try {
         $userObj = new UserAPI($this->apiKey, $this->apiSecret, array('output_format' => 'json'));
         return $userObj->create($data);
     } catch (LoginRadiusException $e) {
         if (isset($e->getErrorResponse()->description) && $e->getErrorResponse()->description) {
             return $e->getErrorResponse()->description;
         }
     }
 }