/** * Edit a person's data and synchronize with the person with the user entity * * @param KCommandContext $context Context parameter * * @return AnDomainEntityAbstract */ protected function _actionEdit(KCommandContext $context) { //add the validations here $this->getRepository()->getValidator()->addValidation('username', 'uniqueness')->addValidation('email', 'uniqueness'); $data = $context->data; $person = parent::_actionEdit($context); //manually set the password to make sure there's a password if (!empty($data->password)) { $person->setPassword($data->password); } if ($person->validate() === false) { throw new AnErrorException($person->getErrors(), KHttpResponse::BAD_REQUEST); } $user = JFactory::getUser($person->userId); if ($person->getModifiedData()->name) { $user->set('name', $person->name); } if ($person->getModifiedData()->username) { $user->set('username', $person->username); } if ($person->getModifiedData()->email) { $user->set('email', $person->email); } if (!empty($data->password)) { $user->set('password', $person->getPassword(true)); } //save language if (@$data->params->language) { $user->_params->set('language', $data->params->language); } if (!$user->save()) { throw new RuntimeException('Unexpected error when saving user'); return false; } if (!$person->save()) { throw new RuntimeException('Unexpected error when saving user'); } $this->getResponse()->status = KHttpResponse::RESET_CONTENT; return $person; }
/** * Edit a person's data and synchronize with the person with the user entity. * * @param KCommandContext $context Context parameter * * @return AnDomainEntityAbstract */ protected function _actionEdit(KCommandContext $context) { $data = $context->data; //dont' set the usertype yet, until we find the conditions are met $userType = null; if ($data->userType) { $userType = $data->userType; unset($context->data->userType); } $person = parent::_actionEdit($context); if ($data->password) { $person->setPassword($data->password); $_SESSION['reset_password_prompt'] = 0; } //add the validations here $this->getRepository()->getValidator()->addValidation('username', 'uniqueness')->addValidation('email', 'uniqueness'); if ($person->validate() === false) { throw new AnErrorException($person->getErrors(), KHttpResponse::BAD_REQUEST); } //now check to see if usertype can be set, otherwise the value is unchanged if (in_array($userType, $this->_allowed_user_types) && $person->authorize('changeUserType')) { $person->userType = $userType; } $person->timestamp(); $this->setMessage('LIB-AN-PROMPT-UPDATE-SUCCESS', 'success'); return $person; }