/**
  * 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;
 }
 function userregistration_unlink_account($raas_uid, $provider, $provider_id)
 {
     try {
         $accountObj = new AccountAPI($this->apiKey, $this->apiSecret, array('output_format' => 'json'));
         return $accountObj->accountUnlink($raas_uid, $provider_id, $provider);
     } catch (LoginRadiusException $e) {
         if (isset($e->getErrorResponse()->description) && $e->getErrorResponse()->description) {
             return $e->getErrorResponse()->description;
         }
         //$message = explode('"description": "', $e->getMessage());
         //return (isset($message[1]) ? (($msg = explode('"errorCode', $message[1])) ? str_replace('",', '.', $msg[0]) : $e->getMessage() ): $e->getMessage());
     }
 }
 public function provideLogin($new_user, $userprofile, $status = FALSE)
 {
     $config = \Drupal::config('sociallogin.settings');
     $apiSecret = trim($config->get('api_secret'));
     $apiKey = trim($config->get('api_key'));
     $accountObj = new AccountAPI($apiKey, $apiSecret, array('output_format' => 'json'));
     try {
         $result = $accountObj->getAccounts($userprofile->Uid);
     } catch (LoginRadiusException $e) {
         watchdog_exception('type', $e);
     }
     if (isset($result) && !empty($result)) {
         foreach ($result as $value) {
             if (is_array($value) || is_object($value)) {
                 $check_aid = db_query("SELECT user_id FROM {loginradius_mapusers} WHERE user_id = :uid AND provider_id = :providerid", array(':uid' => $new_user->id(), ':providerid' => $value->ID))->fetchField();
                 if (isset($check_aid) && !$check_aid) {
                     $this->insertSocialData($new_user->id(), $value->ID, $value->Provider);
                 }
             }
         }
     }
     $_SESSION['spd_userprofile'] = $userprofile;
     if ($new_user->isActive() && $new_user->getLastLoginTime() != 0) {
         $url = '';
         $isNew = FALSE;
         if ($userprofile->FirstLogin) {
             $url = 'register_redirection';
         }
         if ($this->module_config->get('update_user_profile') == 1 && !$new_user->isNew()) {
             $this->field_create_user_object($new_user, $userprofile);
             $new_user->save();
             $this->downloadProfilePic($userprofile->ImageUrl, $userprofile->ID, $new_user);
         }
         \Drupal::service('session')->migrate();
         \Drupal::service('session')->set('lrID', $userprofile->ID);
         \Drupal::service('session')->set('provide_name', $userprofile->Provider);
         $_SESSION['emailVerified'] = false;
         if (isset($userprofile->EmailVerified)) {
             $_SESSION['emailVerified'] = $userprofile->EmailVerified;
         }
         if (\Drupal::moduleHandler()->moduleExists('userregistration')) {
             $user_name = $this->usernameOption($userprofile);
             $user_manager = \Drupal::service('userregistration.user_manager');
             $dbuname = $user_manager->userregistration_get_raas_uname($new_user->id());
             if (isset($dbuname) && $dbuname != '') {
                 if (isset($user_name) && $user_name != '' && $dbuname != $user_name) {
                     $this->connection->update('users_field_data')->fields(array('name' => $user_name))->condition('uid', $new_user->id())->execute();
                 }
             }
         }
         user_login_finalize($new_user);
         if ($status) {
             drupal_set_message(t('You are now logged in as %username.', array('%username' => $new_user->getUsername())));
         } else {
             drupal_set_message(t('You are now logged in as %username.', array('%username' => $new_user->getUsername())));
         }
         return $this->redirectUser($url);
     } else {
         drupal_set_message(t('You are either blocked, or have not activated your account. Please check your email.'), 'error');
         return new RedirectResponse(Url::fromRoute('<front>')->toString());
     }
 }
Esempio n. 4
0
 /**
  * @param $post_value
  * Link user account
  */
 public static function linkAccount($post_value)
 {
     $userRegBasic = new SocialLoginAPI(LR_API_KEY, LR_API_SECRET, array('authentication' => false, 'output_format' => 'json'));
     if (!empty($post_value['token'])) {
         $profile_data = array();
         try {
             $result_accesstoken = $userRegBasic->exchangeAccessToken($post_value['token']);
             $accessToken = $result_accesstoken->access_token;
         } catch (LoginRadiusException $e) {
             self::setMessage($e->getErrorResponse()->description);
         }
         if (!empty($accessToken)) {
             try {
                 $profile_data = $userRegBasic->getUserProfiledata($accessToken);
             } catch (LoginRadiusException $e) {
                 self::setMessage($e->getErrorResponse()->description);
             }
         }
         $data = $_SESSION['userprofile'];
         if (isset($profile_data->ID) && !empty($profile_data->ID) && isset($data->Uid) && !empty($data->Uid)) {
             try {
                 $accountApi = new AccountAPI(LR_API_KEY, LR_API_SECRET, array('output_format' => 'json'));
                 $result = $accountApi->accountLink($data->Uid, $profile_data->ID, $profile_data->Provider);
                 if (isset($result->isPosted) && $result->isPosted) {
                     self::setMessage('Account Linked Successfully');
                 }
             } catch (LoginRadiusException $e) {
                 self::setMessage($e->getErrorResponse()->description);
             }
         } else {
             self::setMessage('You cannot link this account either it is already linked with another account or email is not verified.');
         }
     }
 }