Example #1
0
 /**
  * Contains the logic to render a report and its children to the command line
  *
  * @param common_report_Report $report A report to be rendered.
  * @param boolean $useColor
  * @param integer $intend the intend of the message.
  * @return string The shell output of $report.
  */
 public static function renderToCommandLine(common_report_Report $report, $useColor = self::AUTOSENSE, $intend = 0)
 {
     switch ($report->getType()) {
         case common_report_Report::TYPE_SUCCESS:
             $color = '0;32';
             // green
             break;
         case common_report_Report::TYPE_WARNING:
             $color = '1;33';
             // yellow
             break;
         case common_report_Report::TYPE_ERROR:
             $color = '1;31';
             // red
             break;
         default:
             $color = '0;37';
             // light grey
     }
     if ($useColor == self::AUTOSENSE) {
         $useColor = getenv('TAO_CONSOLE') !== 'nocolor' && !helpers_PlatformInstance::isWindows();
     }
     $output = ($useColor ? "[" . $color . 'm' : '') . ($intend > 0 ? str_repeat(' ', $intend) : '') . $report->getMessage() . ($useColor ? "" : '') . PHP_EOL;
     foreach ($report as $child) {
         $output .= self::renderToCommandline($child, $useColor, $intend + 2);
     }
     return $output;
 }
Example #2
0
 /**
  * Action dedicated to change the password of the user currently connected.
  */
 public function password()
 {
     $this->setData('formTitle', __("Change password"));
     if (helpers_PlatformInstance::isDemo()) {
         $this->setData('myForm', __('Unable to change passwords in demo mode'));
     } else {
         $myFormContainer = new tao_actions_form_UserPassword();
         $myForm = $myFormContainer->getForm();
         if ($myForm->isSubmited()) {
             if ($myForm->isValid()) {
                 $user = $this->userService->getCurrentUser();
                 tao_models_classes_UserService::singleton()->setPassword($user, $myForm->getValue('newpassword'));
                 $this->setData('message', __('Password changed'));
             }
         }
         $this->setData('myForm', $myForm->render());
     }
     $this->setView('form/settings_user.tpl');
 }
Example #3
0
 /**
  * Remove a user
  * The request must contains the user's login to remove
  * @return void
  */
 public function delete()
 {
     $deleted = false;
     $message = __('An error occured during user deletion');
     if (helpers_PlatformInstance::isDemo()) {
         $message = __('User deletion not permited on a demo instance');
     } elseif ($this->hasRequestParameter('uri')) {
         $user = new core_kernel_classes_Resource(tao_helpers_Uri::decode($this->getRequestParameter('uri')));
         $this->checkUser($user->getUri());
         if ($this->userService->removeUser($user)) {
             $deleted = true;
             $message = __('User deleted successfully');
         }
     }
     $this->returnJson(array('deleted' => $deleted, 'message' => $message));
 }
 /**
  * Short description of method initElements
  *
  * @access protected
  * @author Joel Bout, <*****@*****.**>
  * @return mixed
  */
 protected function initElements()
 {
     if (!isset($this->options['mode'])) {
         throw new Exception("Please set a mode into container options ");
     }
     parent::initElements();
     //login field
     $loginElement = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_USER_LOGIN));
     $loginElement->setDescription($loginElement->getDescription() . ' *');
     if ($this->options['mode'] == 'add') {
         $loginElement->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty'), tao_helpers_form_FormFactory::getValidator('Callback', array('object' => tao_models_classes_UserService::singleton(), 'method' => 'loginAvailable', 'message' => __('This Login is already in use')))));
     } else {
         $loginElement->setAttributes(array('readonly' => 'readonly', 'disabled' => 'disabled'));
     }
     //set default lang to the languages fields
     $langService = tao_models_classes_LanguageService::singleton();
     $dataLangElt = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_USER_DEFLG));
     $dataLangElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $dataLangElt->setDescription($dataLangElt->getDescription() . ' *');
     $dataUsage = new core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_DATA);
     $dataOptions = array();
     foreach ($langService->getAvailableLanguagesByUsage($dataUsage) as $lang) {
         $dataOptions[tao_helpers_Uri::encode($lang->getUri())] = $lang->getLabel();
     }
     $dataLangElt->setOptions($dataOptions);
     $uiLangElt = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_USER_UILG));
     $uiLangElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $uiLangElt->setDescription($uiLangElt->getDescription() . ' *');
     $guiUsage = new core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_GUI);
     $guiOptions = array();
     foreach ($langService->getAvailableLanguagesByUsage($guiUsage) as $lang) {
         $guiOptions[tao_helpers_Uri::encode($lang->getUri())] = $lang->getLabel();
     }
     $uiLangElt->setOptions($guiOptions);
     // roles field
     $property = new core_kernel_classes_Property(PROPERTY_USER_ROLES);
     $roles = $property->getRange()->getInstances(true);
     $rolesOptions = array();
     foreach ($roles as $r) {
         $rolesOptions[tao_helpers_Uri::encode($r->getUri())] = $r->getLabel();
     }
     asort($rolesOptions);
     $rolesElt = $this->form->getElement(tao_helpers_Uri::encode($property->getUri()));
     $rolesElt->setDescription($rolesElt->getDescription() . ' *');
     $rolesElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $rolesElt->setOptions($rolesOptions);
     // password field
     $this->form->removeElement(tao_helpers_Uri::encode(PROPERTY_USER_PASSWORD));
     if ($this->options['mode'] == 'add') {
         $pass1Element = tao_helpers_form_FormFactory::getElement('password1', 'Hiddenbox');
         $pass1Element->setDescription(__('Password *'));
         $pass1Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty'), tao_helpers_form_FormFactory::getValidator('Length', array('min' => 3))));
         $this->form->addElement($pass1Element);
         $pass2Element = tao_helpers_form_FormFactory::getElement('password2', 'Hiddenbox');
         $pass2Element->setDescription(__('Repeat password *'));
         $pass2Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty'), tao_helpers_form_FormFactory::getValidator('Password', array('password2_ref' => $pass1Element))));
         $this->form->addElement($pass2Element);
     } else {
         if (helpers_PlatformInstance::isDemo()) {
             $warning = tao_helpers_form_FormFactory::getElement('warningpass', 'Label');
             $warning->setValue(__('Unable to change passwords in demo mode'));
             $this->form->addElement($warning);
             $this->form->createGroup("pass_group", __("Change the password"), array('warningpass'));
         } else {
             $pass2Element = tao_helpers_form_FormFactory::getElement('password2', 'Hiddenbox');
             $pass2Element->setDescription(__('New password'));
             $pass2Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('Length', array('min' => 3))));
             $this->form->addElement($pass2Element);
             $pass3Element = tao_helpers_form_FormFactory::getElement('password3', 'Hiddenbox');
             $pass3Element->setDescription(__('Repeat new password'));
             $pass3Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('Password', array('password2_ref' => $pass2Element))));
             $this->form->addElement($pass3Element);
             $this->form->createGroup("pass_group", __("Change the password"), array('password1', 'password2', 'password3'));
             if (empty($_POST[$pass2Element->getName()]) && empty($_POST[$pass3Element->getName()])) {
                 $pass2Element->setForcedValid();
                 $pass3Element->setForcedValid();
             }
         }
     }
     /**/
 }