示例#1
0
 /**
  * Method to validate the form data.
  *
  * @param   JForm   $form   The form to validate against.
  * @param   array   $data   The data to validate.
  * @param   string  $group  The name of the field group to validate.
  *
  * @return  mixed  Array of filtered data if valid, false otherwise.
  */
 public function validate($form, $data, $group = null)
 {
     // Fire HUBzero registration check here so that we don't have to duplicate validation code
     require_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'models' . DS . 'registration.php';
     $registration = new \Components\Members\Models\Registration();
     $registration->set('name', $data['name']);
     $registration->set('login', $data['username']);
     $registration->set('email', $data['email']);
     $registration->set('confirmEmail', $data['email']);
     if (!$registration->check('create', $data['id'], array('name', 'login', 'email'))) {
         $this->setError(implode("<br/>", $registration->_invalid));
         return false;
     }
     return parent::validate($form, $data, $group);
 }
示例#2
0
 /**
  * Update attachment record
  *
  * @return  void
  */
 public function saveItem($manifest, $blockId, $pub, $actor = 0, $elementId = 0, $aid = 0)
 {
     $aid = $aid ? $aid : Request::getInt('aid', 0);
     // Load classes
     $row = new \Components\Publications\Tables\Author($this->_parent->_db);
     $objO = new \Components\Projects\Tables\Owner($this->_parent->_db);
     // We need attachment record
     if (!$aid || !$row->load($aid) || $row->publication_version_id != $pub->version_id) {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_CONTENT_ERROR_LOAD_AUTHOR'));
         return false;
     }
     // Instantiate a new registration object
     include_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'models' . DS . 'registration.php';
     $xregistration = new \Components\Members\Models\Registration();
     // Get current owners
     $owners = $objO->getIds($pub->_project->get('id'), 'all', 1);
     $email = Request::getVar('email', '', 'post');
     $firstName = Request::getVar('firstName', '', 'post');
     $lastName = Request::getVar('lastName', '', 'post');
     $org = Request::getVar('organization', '', 'post');
     $credit = Request::getVar('credit', '', 'post');
     $sendInvite = 0;
     $code = \Components\Projects\Helpers\Html::generateCode();
     $uid = Request::getInt('uid', 0, 'post');
     $regex = '/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+/';
     $email = preg_match($regex, $email) ? $email : '';
     if (!$firstName || !$lastName) {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_MISSING_REQUIRED'));
         return false;
     }
     $row->organization = $org;
     $row->firstName = $firstName;
     $row->lastName = $lastName;
     $row->name = $row->firstName . ' ' . $row->lastName;
     $row->credit = $credit;
     $row->modified_by = $actor;
     $row->modified = Date::toSql();
     // Check that profile exists
     if ($uid) {
         $profile = User::getInstance($uid);
         $uid = $profile->get('id') ? $uid : 0;
     }
     // Tying author to a user account?
     if ($uid && !$row->user_id) {
         // Do we have an owner with this user id?
         $owner = $objO->getOwnerId($pub->_project->get('id'), $uid);
         if ($owner) {
             // Update owner assoc
             $row->project_owner_id = $owner;
         } else {
             // Update associated project owner account
             if ($objO->load($row->project_owner_id) && !$objO->userid) {
                 $objO->userid = $uid;
                 $objO->status = 1;
                 $objO->store();
             }
         }
     }
     $row->user_id = $uid;
     if ($row->store()) {
         $this->set('_message', Lang::txt('Author record saved'));
         // Reflect the update in curation record
         $this->_parent->set('_update', 1);
     } else {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_AUTHORS_ERROR_SAVING_AUTHOR_INFO'));
         return false;
     }
     // Update project owner (invited)
     if ($email && !$row->user_id && $objO->load($row->project_owner_id)) {
         $invitee = $objO->checkInvited($pub->_project->get('id'), $email);
         // Do we have a registered user with this email?
         $user = $xregistration->getEmailId($email);
         if ($invitee && $invitee != $row->project_owner_id) {
             // Stop, must have owner record
         } elseif (in_array($user, $owners)) {
             // Stop, already in team
         } elseif ($email != $objO->invited_email) {
             $objO->invited_email = $email;
             $objO->invited_name = $row->name;
             $objO->userid = $row->user_id;
             $objO->invited_code = $code;
             $objO->store();
             $sendInvite = 1;
         }
     }
     // (Re)send email invitation
     if ($sendInvite && $email) {
         // Get project model
         $project = new \Components\Projects\Models\Project($pub->_project->get('id'));
         // Plugin params
         $plugin_params = array(0, $email, $code, 2, $project, 'com_projects');
         // Send invite
         $output = Event::trigger('projects.sendInviteEmail', $plugin_params);
         $result = json_decode($output[0]);
     }
     return true;
 }
示例#3
0
 /**
  * Check if a username is available
  *
  * @return  string
  */
 public function checkusernameTask()
 {
     // Incoming
     $username = Request::getVar('userlogin', '', 'get');
     // Instantiate a new registration object
     $xregistration = new \Components\Members\Models\Registration();
     // Check the username
     $usernamechecked = $xregistration->checkusername($username);
     echo json_encode($usernamechecked);
     die;
 }
示例#4
0
 /**
  * Check Data integrity
  *
  * @return  $this  Current object
  */
 public function check()
 {
     // Run save check method
     if (!$this->record->entry->check()) {
         array_push($this->record->errors, $this->record->entry->getError());
         return $this;
     }
     $xregistration = new \Components\Members\Models\Registration();
     $xregistration->loadProfile($this->_profile);
     // Check that required fields were filled in properly
     if (!$xregistration->check('edit', $this->_profile->get('uidNumber'), array())) {
         if (!empty($xregistration->_missing)) {
             foreach ($xregistration->_missing as $missing) {
                 array_push($this->record->errors, $missing);
             }
         }
         if (!empty($xregistration->_invalid)) {
             foreach ($xregistration->_invalid as $invalid) {
                 array_push($this->record->errors, $invalid);
             }
         }
     }
     return $this;
 }
示例#5
0
 /**
  * Save member
  *
  * @return     void, redirect
  */
 protected function _save()
 {
     // Incoming
     $members = urldecode(trim(Request::getVar('newmember', '', 'post')));
     $groups = urldecode(trim(Request::getVar('newgroup', '')));
     $role = Request::getInt('role', 0);
     // Result collectors
     $m_added = 0;
     // count of individual members added
     $m_invited = 0;
     // count of individuals invited
     $g_added = 0;
     // count of members from new group
     $uids = array();
     // ids/emails of added people
     $names = array();
     // names/emails of added people
     $invalid = array();
     // collector for invalid names
     // Setup stage?
     $setup = $this->model->inSetup();
     // Get owner class
     $objO = $this->model->table('Owner');
     // Instantiate a new registration object
     include_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'models' . DS . 'registration.php';
     $xregistration = new \Components\Members\Models\Registration();
     // Owner names not supplied
     if (!$members && !$groups) {
         if (!$setup) {
             $this->setError(Lang::txt('PLG_PROJECTS_TEAM_NO_NAMES_SUPPLIED'));
         } else {
             return;
         }
     } else {
         if ($members) {
             $newm = explode(',', $members);
             // Do we have new authors?
             if ($newm) {
                 for ($i = 0, $n = count($newm); $i < $n; $i++) {
                     $cid = strtolower(trim($newm[$i]));
                     $uid = 0;
                     if ($cid == '') {
                         continue;
                     }
                     $parts = preg_split("/[(]/", $cid);
                     if (count($parts) == 2) {
                         $name = $parts[0];
                         $uid = preg_replace('/[)]/', '', $parts[1]);
                     } elseif (intval($cid) && ($validUser = User::getInstance($cid))) {
                         $uid = $cid;
                     } else {
                         $regex = '/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+/';
                         if (preg_match($regex, $cid)) {
                             // This is an email - check if user with the email exists
                             $uid = $xregistration->getEmailId($cid);
                             if (!$uid) {
                                 // Make sure we aren't inviting twice
                                 $invitee = $objO->checkInvited($this->model->get('id'), $cid);
                                 if (!$invitee) {
                                     // Generate invitation code
                                     $code = \Components\Projects\Helpers\Html::generateCode();
                                     // Add invitee record
                                     if ($objO->saveInvite($this->model->get('id'), $cid, $code, '', $role)) {
                                         $uids[] = $cid;
                                         $m_invited++;
                                         if (!$setup && $this->_config->get('messaging') == 1) {
                                             $this->sendInviteEmail(0, $cid, $code, $role);
                                         }
                                     }
                                 } elseif ($objO->load($invitee)) {
                                     // Previously deleted invite
                                     if ($objO->status == 2) {
                                         $objO->status = 0;
                                         $objO->role = $role;
                                         $uids[] = $cid;
                                         $objO->store();
                                         $m_invited++;
                                         if (!$setup && $this->_config->get('messaging') == 1) {
                                             $this->sendInviteEmail(0, $cid, $objO->invited_code, $objO->role);
                                         }
                                     }
                                 }
                             }
                         } else {
                             $invalid[] = $cid;
                         }
                     }
                     if (!$uid or !is_numeric($uid)) {
                         continue;
                     } else {
                         if (!User::getInstance($uid)) {
                             $invalid[] = $uid;
                             continue;
                         }
                     }
                     // Save new author
                     $native = $this->model->access('owner') ? 1 : 0;
                     if ($objO->saveOwners($this->model->get('id'), $this->_uid, $uid, 0, $role, $status = 1, $native)) {
                         $uids[] = $uid;
                     }
                 }
             }
         }
         if ($groups) {
             // Save new authors from group
             $g_added = $objO->saveOwners($this->model->get('id'), $this->_uid, 0, $groups, $role, $status = 1, $native = 0);
             if ($objO->getError()) {
                 $this->setError($objO->getError());
             }
             if ($g_added) {
                 $uids = array_merge($uids, $g_added);
             }
         }
     }
     // Did we add anyone new?
     $uids = array_unique($uids);
     if (count($uids) > 0) {
         $this->_msg = Lang::txt('PLG_PROJECTS_TEAM_SUCCESS_ADDED_OR_INVITED') . ' ' . count($uids) . ' ' . Lang::txt('PLG_PROJECTS_TEAM_NEW') . ' ' . Lang::txt('PLG_PROJECTS_TEAM_MEMBERS');
         if (count($invalid) > 0) {
             $this->_msg .= '<br />' . Lang::txt('PLG_PROJECTS_TEAM_MEMBERS_INVALID_NAMES');
         }
         if (!$setup) {
             $note = strtolower(Lang::txt('PLG_PROJECTS_TEAM_SUCCESS_ADDED_OR_INVITED')) . ' ';
             for ($i = 0; $i < count($uids); $i++) {
                 $uu = $uids[$i];
                 if ($uu && is_numeric($uu)) {
                     $xuser = User::getInstance($uids[$i]);
                     $note .= is_numeric($uids[$i]) && is_object($xuser) ? $xuser->get('name') : $uids[$i];
                 } else {
                     $note .= $uids[$i];
                 }
                 if ($i > 1) {
                     $left = count($uids) - 3;
                     if ($left) {
                         $note .= ' ' . Lang::txt('PLG_PROJECTS_TEAM_AND') . ' ' . $left . ' ' . Lang::txt('PLG_PROJECTS_TEAM_MORE') . ' ';
                         $note .= $left == 1 ? Lang::txt('PLG_PROJECTS_TEAM_ACTIVITY_PERSON') : Lang::txt('PLG_PROJECTS_TEAM_ACTIVITY_PERSONS');
                     }
                     break;
                 }
                 $note .= $i == count($uids) - 1 ? '' : ', ';
             }
             $note .= ' ' . Lang::txt('PLG_PROJECTS_TEAM_TO_PROJECT_TEAM');
             // Send out emails
             if ($this->_config->get('messaging') == 1) {
                 foreach ($uids as $user) {
                     $this->sendInviteEmail($user, '', '', $role);
                 }
             }
         }
         // Sync with system group
         $objO->sysGroup($this->model->get('alias'), $this->_config->get('group_prefix', 'pr-'));
     } elseif (count($invalid) > 0) {
         $this->setError(Lang::txt('PLG_PROJECTS_TEAM_MEMBERS_INVALID_NAMES') . '<br />' . Lang::txt('PLG_PROJECTS_TEAM_MEMBERS_INVALID_NAMES_EXPLAIN'));
     }
     // Pass error or success message
     if ($this->getError()) {
         \Notify::message($this->getError(), 'error', 'projects');
     } elseif (!empty($this->_msg)) {
         \Notify::message($this->_msg, 'success', 'projects');
     }
     $url = $setup ? Route::url($this->model->link('setup') . '&section=team') : Route::url($this->model->link('edit') . '&section=team');
     App::redirect($url);
     return;
 }
示例#6
0
 /**
  * View the profile page
  *
  * @return  string
  */
 private function display()
 {
     //get member params
     $rparams = new \Hubzero\Config\Registry($this->member->get('params'));
     //get profile plugin's params
     $params = $this->params;
     $params->merge($rparams);
     $xreg = null;
     $fields = Components\Members\Models\Profile\Field::all()->including(['options', function ($option) {
         $option->select('*')->ordered();
     }])->where('action_edit', '!=', Components\Members\Models\Profile\Field::STATE_HIDDEN)->ordered()->rows();
     if (App::get('session')->get('registration.incomplete')) {
         $xreg = new \Components\Members\Models\Registration();
         $xreg->loadProfile($this->member);
         $check = $xreg->check('update');
         // Validate profile data
         // @TODO  Move this to central validation model (e.g., registraiton)?
         // Compile profile data
         $profile = array();
         foreach ($fields as $field) {
             $profile[$field->get('name')] = $this->member->get($field->get('name'));
         }
         // Validate profile fields
         $form = new Hubzero\Form\Form('profile', array('control' => 'profile'));
         $form->load(Components\Members\Models\Profile\Field::toXml($fields, 'edit', $profile));
         $form->bind(new Hubzero\Config\Registry($profile));
         if (!$form->validate($profile)) {
             $check = false;
             foreach ($form->getErrors() as $key => $error) {
                 if ($error instanceof Hubzero\Form\Exception\MissingData) {
                     $xreg->_missing[$key] = (string) $error;
                 }
                 $xreg->_invalid[$key] = (string) $error;
             }
         }
         // If no errors, redirect to where they were going
         if ($check) {
             App::get('session')->set('registration.incomplete', 0);
             App::redirect($_SERVER['REQUEST_URI']);
         }
     }
     $view = $this->view('default', 'index')->set('params', $params)->set('option', 'com_members')->set('profile', $this->member)->set('fields', $fields)->set('completeness', $this->getProfileCompleteness($fields, $this->member))->set('registration_update', $xreg);
     return $view->setErrors($this->getErrors())->loadTemplate();
 }
示例#7
0
 /**
  * Event call to determine if this plugin should return data
  *
  * @param      array  $fields  Fields filled in
  * @param      object $profile MembersProfile
  * @return     integer
  */
 public function getProfileCompleteness($fields, $profile)
 {
     //default vars
     $num_fields = 0;
     $num_filled_fields = 0;
     $_property_map = array('Fullname' => 'name', 'Email' => 'email', 'URL' => 'web', 'Phone' => 'phone', 'Employment' => 'orgtype', 'Organization' => 'org', 'Citizenship' => 'countryorigin', 'Residency' => 'countryresident', 'Sex' => 'sex', 'Disability' => 'disability', 'Hispanic' => 'hispanic', 'Race' => 'race', 'Bio' => 'bio', 'Interests' => 'tags', 'OptIn' => 'mailPreferenceOption', 'ORCID' => 'orcid');
     //unset errors from the fields object
     $fields->setErrors(array());
     //load the user profile
     $registration = new \Components\Members\Models\Registration();
     $registration->loadProfile($profile);
     //add tags to the registration object
     $database = App::get('db');
     $mt = new \Components\Members\Models\Tags($profile->get('uidNumber'));
     $registration->_registration['tags'] = $mt->render('string');
     //add bio to the registration object
     $fields->Bio = REG_OPTIONAL;
     $registration->_registration['bio'] = $profile->get("bio");
     //loop through each field to see if we want to count it
     foreach ($fields as $k => $v) {
         //if the field is anything button hidden we want to count it
         if (in_array($v, array(REG_REQUIRED, REG_OPTIONAL, REG_READONLY))) {
             //check if we have a mapping (excludes certain unused vars)
             if (isset($_property_map[$k])) {
                 //add to the number of fields count
                 $num_fields++;
                 //check to see if we have it filled in
                 $value = $registration->get($_property_map[$k]);
                 $type = gettype($registration->get($_property_map[$k]));
                 if ($type == 'array' && !empty($value) || $type == 'string' && $value != '') {
                     $num_filled_fields++;
                 }
             }
         }
     }
     //return percentage
     return number_format($num_filled_fields / $num_fields * 100, 0);
 }
示例#8
0
 /**
  * Check Data integrity
  *
  * @return  $this  Current object
  */
 public function check()
 {
     // Run save check method
     /*if (!$this->record->entry->check())
     		{
     			array_push($this->record->errors, $this->record->entry->getError());
     			return $this;
     		}*/
     $xregistration = new \Components\Members\Models\Registration();
     $xregistration->loadProfile($this->record->entry);
     // Check that required fields were filled in properly
     if (!$xregistration->check('edit', $this->record->entry->get('id'), array())) {
         $skip = array();
         if (!empty($xregistration->_missing)) {
             foreach ($xregistration->_missing as $key => $missing) {
                 if ($this->_mode == 'PATCH') {
                     $skip[] = $key;
                     continue;
                 }
                 array_push($this->record->errors, $missing);
             }
         }
         if (!empty($xregistration->_invalid)) {
             foreach ($xregistration->_invalid as $key => $invalid) {
                 if (in_array($key, $skip)) {
                     continue;
                 }
                 array_push($this->record->errors, $invalid);
             }
         }
     }
     // Validate profile data
     $fields = \Components\Members\Models\Profile\Field::all()->including(['options', function ($option) {
         $option->select('*');
     }])->where('action_edit', '!=', \Components\Members\Models\Profile\Field::STATE_HIDDEN)->ordered()->rows();
     $form = new \Hubzero\Form\Form('profile', array('control' => 'profile'));
     $form->load(\Components\Members\Models\Profile\Field::toXml($fields, 'edit'));
     $form->bind(new \Hubzero\Config\Registry($this->_profile));
     if (!$form->validate($this->_profile)) {
         foreach ($form->getErrors() as $key => $error) {
             array_push($this->record->errors, (string) $error);
         }
     }
     return $this;
 }
示例#9
0
 /**
  * Save changes to a profile
  * Outputs JSON when called via AJAX, redirects to profile otherwise
  *
  * @return     string JSON
  */
 public function saveTask()
 {
     // Check if they are logged in
     if (User::isGuest()) {
         return false;
     }
     Request::checkToken(array('get', 'post'));
     $no_html = Request::getVar("no_html", 0);
     // Incoming user ID
     $id = Request::getInt('id', 0, 'post');
     // Do we have an ID?
     if (!$id) {
         App::abort(404, Lang::txt('MEMBERS_NO_ID'));
         return;
     }
     // Incoming profile edits
     $p = Request::getVar('profile', array(), 'post', 'none', 2);
     $n = Request::getVar('name', array(), 'post');
     $a = Request::getVar('access', array(), 'post');
     // Load the profile
     $profile = \Hubzero\User\Profile::getInstance($id);
     $oldemail = $profile->get('email');
     if ($n) {
         $profile->set('givenName', trim($n['first']));
         $profile->set('middleName', trim($n['middle']));
         $profile->set('surname', trim($n['last']));
         $name = trim($n['first']) . ' ';
         $name .= trim($n['middle']) != '' ? trim($n['middle']) . ' ' : '';
         $name .= trim($n['last']);
         $profile->set('name', $name);
     }
     if (isset($p['bio'])) {
         $profile->set('bio', trim($p['bio']));
     }
     if (is_array($a) && count($a) > 0) {
         foreach ($a as $k => $v) {
             $v = intval($v);
             if (!in_array($v, array(0, 1, 2, 3, 4))) {
                 $v = 0;
             }
             $profile->setParam('access_' . $k, $v);
         }
     }
     if (isset($p['public'])) {
         $profile->set('public', $p['public']);
     }
     // Set some post data for the xregistration class
     $tags = trim(Request::getVar('tags', ''));
     if (isset($tags)) {
         Request::setVar('interests', $tags, 'post');
     }
     // Instantiate a new \Components\Members\Models\Registration
     $xregistration = new \Components\Members\Models\Registration();
     $xregistration->loadPOST();
     // Push the posted data to the profile
     // Note: this is done before the required fields check so, if we need to display the edit form, it'll show all the new changes
     if (!is_null($xregistration->_registration['email'])) {
         $profile->set('email', $xregistration->_registration['email']);
         // Unconfirm if the email address changed
         if ($oldemail != $xregistration->_registration['email']) {
             // Get a new confirmation code
             $confirm = \Components\Members\Helpers\Utility::genemailconfirm();
             $profile->set('emailConfirmed', $confirm);
         }
     }
     if (!is_null($xregistration->_registration['countryresident'])) {
         $profile->set('countryresident', $xregistration->_registration['countryresident']);
     }
     if (!is_null($xregistration->_registration['countryorigin'])) {
         $profile->set('countryorigin', $xregistration->_registration['countryorigin']);
     }
     if (!is_null($xregistration->_registration['nativetribe'])) {
         $profile->set('nativeTribe', $xregistration->_registration['nativetribe']);
     }
     if ($xregistration->_registration['org'] != '') {
         $profile->set('organization', $xregistration->_registration['org']);
     } elseif ($xregistration->_registration['orgtext'] != '') {
         $profile->set('organization', $xregistration->_registration['orgtext']);
     }
     if (!is_null($xregistration->_registration['web'])) {
         $profile->set('url', $xregistration->_registration['web']);
     }
     if (!is_null($xregistration->_registration['phone'])) {
         $profile->set('phone', $xregistration->_registration['phone']);
     }
     if (!is_null($xregistration->_registration['orgtype'])) {
         $profile->set('orgtype', $xregistration->_registration['orgtype']);
     }
     if (!is_null($xregistration->_registration['sex'])) {
         $profile->set('gender', $xregistration->_registration['sex']);
     }
     if (!is_null($xregistration->_registration['disability'])) {
         $profile->set('disability', $xregistration->_registration['disability']);
     }
     if (!is_null($xregistration->_registration['hispanic'])) {
         $profile->set('hispanic', $xregistration->_registration['hispanic']);
     }
     if (!is_null($xregistration->_registration['race'])) {
         $profile->set('race', $xregistration->_registration['race']);
     }
     if (!is_null($xregistration->_registration['mailPreferenceOption'])) {
         $profile->set('mailPreferenceOption', $xregistration->_registration['mailPreferenceOption']);
     }
     if (!is_null($xregistration->_registration['usageAgreement'])) {
         $profile->set('usageAgreement', $xregistration->_registration['usageAgreement']);
     }
     if (!is_null($xregistration->_registration['orcid'])) {
         $profile->set('orcid', $xregistration->_registration['orcid']);
     }
     $field_to_check = Request::getVar("field_to_check", array());
     // Check that required fields were filled in properly
     if (!$xregistration->check('edit', $profile->get('uidNumber'), $field_to_check)) {
         if (!$no_html) {
             $this->_task = 'edit';
             $this->editTask($xregistration, $profile);
             return;
         } else {
             echo json_encode($xregistration);
             exit;
         }
     }
     //are we declining the terms of use
     //if yes we want to set the usage agreement to 0 and profile to private
     $declineTOU = Request::getVar('declinetou', 0);
     if ($declineTOU) {
         $profile->set('public', 0);
         $profile->set('usageAgreement', 0);
     }
     // Set the last modified datetime
     $profile->set('modifiedDate', Date::toSql());
     // Save the changes
     if (!$profile->update()) {
         App::abort(500, $profile->getError());
         return false;
     }
     // Process tags
     if (isset($tags) && in_array('interests', $field_to_check)) {
         $mt = new \Components\Members\Models\Tags($id);
         $mt->setTags($tags, $id);
     }
     $email = $profile->get('email');
     $name = $profile->get('name');
     // Make sure certain changes make it back to the user table
     if ($id > 0) {
         $user = User::getInstance($id);
         $jname = $user->get('name');
         $jemail = $user->get('email');
         if ($name != trim($jname)) {
             $user->set('name', $name);
         }
         if ($email != trim($jemail)) {
             $user->set('email', $email);
         }
         if ($name != trim($jname) || $email != trim($jemail)) {
             if (!$user->save()) {
                 App::abort(500, Lang::txt($user->getError()));
                 return false;
             }
         }
         // Update session if name is changing
         if ($n && $user->get('name') != App::get('session')->get('user')->get('name')) {
             $suser = App::get('session')->get('user');
             $user->set('name', $suser->get('name'));
         }
         // Update session if email is changing
         if ($user->get('email') != App::get('session')->get('user')->get('email')) {
             $suser = App::get('session')->get('user');
             $user->set('email', $suser->get('email'));
             // add item to session to mark that the user changed emails
             // this way we can serve profile images for these users but not all
             // unconfirmed users
             $session = App::get('session');
             $session->set('userchangedemail', 1);
         }
     }
     // Send a new confirmation code AFTER we've successfully saved the changes to the e-mail address
     if ($email != $oldemail) {
         $this->_message = $this->_sendConfirmationCode($profile->get('username'), $email, $confirm);
     }
     //if were declinging the terms we want to logout user and tell the javascript
     if ($declineTOU) {
         App::get('auth')->logout();
         echo json_encode(array('loggedout' => true));
         return;
     }
     if (!$no_html) {
         // Redirect
         App::redirect(Route::url('index.php?option=' . $this->_option . ($id ? '&id=' . $id . '&active=profile' : '')), $this->_message);
     } else {
         // Output JSON
         echo json_encode(array('success' => true));
     }
 }