You are here

function _ulogin_user_save in uLogin (advanced version) 7

2 calls to _ulogin_user_save()
ulogin_callback in ./ulogin.pages.inc
ulogin_exit in ./ulogin.module
Implements hook_exit(). Intercepts drupal_goto() calls from Legal legal_user_login().

File

./ulogin.module, line 543
Main file for the uLogin module.

Code

function _ulogin_user_save($data, $uid = NULL) {
  global $user;
  if ($uid) {
    $account = user_load($uid);
  }
  else {
    $account = $user;
  }
  _ulogin_identity_save($data, $uid);
  $user_save_trigger = FALSE;
  $edit = array();

  //save user picture
  if (variable_get('user_pictures', 0) && variable_get('ulogin_pictures', 1)) {
    $photo_url = '';
    if (!empty($data['photo_big']) && $data['photo_big'] != 'http://ulogin.ru/img/photo_big.png') {
      $photo_url = $data['photo_big'];
    }
    elseif (!empty($data['photo']) && $data['photo'] != 'http://ulogin.ru/img/photo.png') {
      $photo_url = $data['photo'];
    }
    if ($photo_url) {
      $photo = drupal_http_request($photo_url);
      $file = file_save_data($photo->data);
      $file->status = 0;

      //to make user_save() to process the file and move it
      $edit['picture'] = $file;
      $user_save_trigger = TRUE;
    }
  }

  //email_confirm: if email was manually entered - trigger email change confirmation
  if (!empty($data['email']) && !empty($data['manual']) && in_array('email', explode(',', $data['manual'])) && variable_get('ulogin_email_confirm', 0) && module_exists('email_confirm')) {
    $edit['mail'] = $data['email'];
    $user_save_trigger = TRUE;
    if ($uid) {

      //backup original user
      $user_backup = $user;

      //replace user with fake one so that email_confirm module works without notices
      $user = $account;
    }
  }
  if ($user_save_trigger) {

    //hack to remove one notice from Legal module
    if (module_exists('legal')) {
      $edit['legal_accept'] = NULL;
    }
    user_save($account, $edit);
  }

  //return original user back
  if (isset($user_backup)) {
    $user = $user_backup;
  }
}