Beispiel #1
0
 protected function processImpl(PostArrayAdapter $adapter, $button)
 {
     $pass = $adapter->str(FORM_PARAM_REG_PASS);
     $passConfirm = $adapter->str(FORM_PARAM_REG_PASS_CONF);
     $error = UserInputValidator::validatePass($pass, $passConfirm);
     if ($error) {
         return array(FORM_PARAM_REG_PASS => $error);
     }
     $error = UserInputValidator::validatePassConfirm($pass, $passConfirm);
     if ($error) {
         return array(FORM_PARAM_REG_PASS_CONF => $error);
     }
     /*
      * Код
      */
     $code = $adapter->str(REMIND_CODE_PARAM);
     if (!$code) {
         return 'Не передан код восстановления';
     }
     $user = PassRecoverManager::changePassWithCode($code, $pass);
     if ($user instanceof PsUser) {
         $authed = AuthManager::loginUser($user->getEmail(), $pass);
         if ($authed) {
             return new AjaxSuccess();
         } else {
             return 'Не удалось авторизоваться после смены пароля';
         }
     } else {
         //Описание - почему код не может быть использован
         return $user;
     }
 }
 protected function processImpl(PostArrayAdapter $adapter, $button)
 {
     $entity = Handlers::getInstance()->getFoldedEntityByUnique($adapter->str('fentity'));
     $tpl = $entity->getFolding()->getInfoTpl($entity->getIdent(), $adapter->str('ftpl'));
     $content = $adapter->str('tpl');
     $tpl->getDirItem()->writeLineToFile($content, true);
     return new AjaxSuccess();
 }
Beispiel #3
0
 protected function processImpl(PostArrayAdapter $adapter, $button)
 {
     $text = $adapter->str('text');
     if (!$text) {
         return array('text', 'required');
     }
     return new AjaxSuccess();
 }
Beispiel #4
0
 protected function processImpl(PostArrayAdapter $adapter, $button)
 {
     $FEEDBACK = FeedbackManager::inst();
     /*
      * Тема
      */
     $theme = $adapter->str(FORM_PARAM_THEME);
     $error = UserInputValidator::validateShortText($theme);
     if ($error) {
         return array(FORM_PARAM_THEME => $error);
     }
     $theme = UserInputTools::safeShortText($theme);
     /*
      * Комментарий
      */
     $text = $adapter->str(FORM_PARAM_COMMENT);
     $error = UserInputValidator::validateLongText($text);
     if ($error) {
         return array(FORM_PARAM_COMMENT => $error);
     }
     $text = UserInputTools::safeLongText($text);
     /*
      * АВТОРИЗОВАН - пользуемся стандартным механизмом добавления сообщения в тред.
      * Кодом треда, при этом, является сам пользователь.
      */
     if (AuthManager::isAuthorized()) {
         $msg = $FEEDBACK->saveMessage(PsUser::inst()->getId(), null, $text, $theme, PsUser::inst());
         return new AjaxSuccess($FEEDBACK->buildLeaf($msg));
     }
     /*
      * НЕ АВТОРИЗОВАН - сохраняем сообщение в таблицу анонимных пользователей.
      */
     if (!AuthManager::isAuthorized()) {
         /*
          * Имя пользователя
          */
         $name = $adapter->str(FORM_PARAM_NAME);
         $error = UserInputValidator::validateShortText($name);
         if ($error) {
             return array(FORM_PARAM_NAME => $error);
         }
         $name = UserInputTools::safeShortText($name);
         /*
          * Контакты
          */
         $contacts = $adapter->str(FORM_PARAM_REG_CONTACTS);
         if ($contacts) {
             $error = UserInputValidator::validateShortText($contacts, false);
             if ($error) {
                 return array(FORM_PARAM_REG_CONTACTS => $error);
             }
             $contacts = UserInputTools::safeShortText($contacts);
         }
         $FEEDBACK->saveAnonimousFeedback($name, $contacts, $theme, $text);
         return new AjaxSuccess();
     }
 }
Beispiel #5
0
 protected function processImpl(PostArrayAdapter $aa, $button)
 {
     $action = $this->getFormAction();
     $table = TableExporter::inst()->getTable($aa->str('table'));
     $rec = $table->fetchRowFromForm($aa->getData(), $action);
     if (!is_array($rec)) {
         return $rec;
     }
     return new RecEditFormData($table, $action, $this->isSubmittedByButton(array(self::BUTTON_CREATEF, self::BUTTON_EDITF, self::BUTTON_DELETEF)), $rec);
 }
Beispiel #6
0
 protected function processImpl(PostArrayAdapter $adapter, $button)
 {
     PsDefines::assertProductionOff(__CLASS__);
     $text = $adapter->str('text');
     if (!$text) {
         return array('text', 'required');
     }
     $mtime = $adapter->int('mtime');
     ToDoFile::inst()->save($text, $mtime);
     return new AjaxSuccess();
 }
Beispiel #7
0
 protected function processImpl(PostArrayAdapter $adapter, $button)
 {
     $tzName = $adapter->str(FORM_PARAM_TIMEZONE);
     if (!$tzName) {
         return array(FORM_PARAM_TIMEZONE => 'required');
     }
     if (!PsTimeZone::inst()->isTimeZoneExists($tzName)) {
         return array(FORM_PARAM_TIMEZONE => "Временная зона [{$tzName}] не существует");
     }
     PsUser::inst()->updateTimezone($tzName);
     return new AjaxSuccess();
 }
Beispiel #8
0
 protected function processStock(BaseStock $stock, PostArrayAdapter $adapter, $button)
 {
     //ОБРАБОТАЕМ КОММЕНТАРИЙ
     $comment = $adapter->str(FORM_PARAM_COMMENT);
     $error = UserInputValidator::validateShortText($comment, true, MOSAIC_ANS_MAX_LEN);
     if ($error) {
         return array(FORM_PARAM_COMMENT => $error);
     }
     $comment = UserInputTools::safeShortText($comment);
     //ВЫЗОВЕМ ДЕЙСТВИЕ ДЛЯ АКЦИИ
     return $stock->formSaveAnswer($comment);
 }
 protected function processImpl(PostArrayAdapter $adapter, $button)
 {
     $clear = $adapter->bool(FORM_PARAM_YES_NO);
     $folding = Handlers::getInstance()->getFoldingByUnique($adapter->str('folding'));
     $uploadedZip = SimpleUploader::inst()->saveUploadedFile();
     try {
         $fentity = $folding->imporFromZip($uploadedZip, $clear);
     } catch (Exception $ex) {
         $uploadedZip->remove();
         throw $ex;
     }
     return new AjaxSuccess(array('url' => AP_APFoldingEdit::url($fentity)));
 }
Beispiel #10
0
 protected function processImpl(PostArrayAdapter $adapter, $button)
 {
     /*
      * e-mail
      */
     $mail = $adapter->str(FORM_PARAM_REG_MAIL);
     $error = UserInputValidator::validateEmail($mail, true);
     if ($error) {
         return array(FORM_PARAM_REG_MAIL => $error);
     }
     PassRecoverManager::sendRecoverCode($mail);
     return new AjaxSuccess();
 }
Beispiel #11
0
 public function processImpl(PostArrayAdapter $paa, $button)
 {
     $login = $paa->str(FORM_PARAM_LOGIN);
     if (!$login) {
         return 'Укажите e-mail';
     }
     if (!PsCheck::isEmail($login)) {
         return 'E-mail должен быть корректным';
     }
     $password = $paa->str(FORM_PARAM_PASS);
     if (!$password) {
         return 'Нужно указать пароль';
     }
     return new AdminLoginFormData($login, $password);
 }
Beispiel #12
0
 protected function processImpl(PostArrayAdapter $adapter, $button)
 {
     $login = $adapter->str(FORM_PARAM_LOGIN);
     if (!$login) {
         return array(FORM_PARAM_LOGIN, 'required');
     }
     if (!PsCheck::isEmail($login)) {
         return array(FORM_PARAM_LOGIN, 'email');
     }
     $password = $adapter->str(FORM_PARAM_PASS);
     if (!$password) {
         return array(FORM_PARAM_PASS, 'required');
     }
     $loggedIn = AuthManager::loginUser($login, $password);
     return $loggedIn ? new AjaxSuccess() : 'В доступе отказано';
 }
Beispiel #13
0
 protected function processImpl(PostArrayAdapter $adapter, $button)
 {
     $oldPass = $adapter->str(FORM_PARAM_REG_OLD_PASS);
     $newPass = $adapter->str(FORM_PARAM_REG_PASS);
     $newPassConfirm = $adapter->str(FORM_PARAM_REG_PASS_CONF);
     $error = UserInputValidator::validateOldPass($oldPass);
     if ($error) {
         return array(FORM_PARAM_REG_OLD_PASS => $error);
     }
     $error = UserInputValidator::validatePass($newPass, $newPassConfirm);
     if ($error) {
         return array(FORM_PARAM_REG_PASS => $error);
     }
     $error = UserInputValidator::validatePassConfirm($newPass, $newPassConfirm);
     if ($error) {
         return array(FORM_PARAM_REG_PASS_CONF => $error);
     }
     PsUser::inst()->changePassword($oldPass, $newPass);
     return new AjaxSuccess();
 }
 protected function processImpl(PostArrayAdapter $adapter, $button)
 {
     if (!$adapter->hasAllNoEmpty('folding', self::PARAM_NEW_FOLDING_IDENT)) {
         return 'Не переданы все необходимые параметры.';
     }
     $funique = $adapter->str('folding');
     $fident = check_condition($adapter->str(self::PARAM_NEW_FOLDING_IDENT), 'Пустой идентификатор фолдинга');
     $folding = FoldedStorageInsts::byUnique($funique);
     $folding->assertNotExistsEntity($fident);
     switch ($button) {
         case self::BUTTON_SAVE_DB:
             $action = PS_ACTION_CREATE;
             $table = TableExporter::inst()->getTable($folding);
             //Проставим руками идентификатор фолдинга для колонки из базы
             $adapter->set($folding->getTableColumnIdent(), $fident);
             //TODO - выкинуто
             /*
              $rec = $table->fetchRowFromForm($adapter->getData(), $action);
              if (!is_array($rec)) {
              //Данные для создания записи в БД не прошли валидацию
              return $rec;
              }
              //$table->saveRec($rec, $action);
             */
             //createFoldingDbRec($folding, $ident);
         //TODO - выкинуто
         /*
          $rec = $table->fetchRowFromForm($adapter->getData(), $action);
          if (!is_array($rec)) {
          //Данные для создания записи в БД не прошли валидацию
          return $rec;
          }
          //$table->saveRec($rec, $action);
         */
         //createFoldingDbRec($folding, $ident);
         case self::BUTTON_SAVE:
             $folding->createEntity($fident);
             break;
     }
     return new AjaxSuccess(array('url' => AP_APFoldingEdit::urlFoldingEdit($folding->getFoldedEntity($fident))));
 }
Beispiel #15
0
 protected function doSearch(PostArrayAdapter $params)
 {
     /*
      * Параметры
      */
     $process = $params->int('process');
     $action = $params->int('action');
     $actionParent = $params->int('parent_action');
     $dateFrom = $params->int('date_from');
     $dateTo = $params->int('date_to');
     /*
      * Запрос
      */
     $what[] = 'id_rec';
     $what[] = 'concat(ifnull(id_user, ""), concat("/", id_user_authed)) as user_authed';
     $what[] = 'dt_event';
     $what[] = 'n_action';
     $what[] = 'v_data';
     $what[] = 'b_encoded';
     $where['id_process'] = $process;
     if ($actionParent) {
         $where['id_rec_parent'] = $actionParent;
     }
     if ($action) {
         $where['n_action'] = $action;
     }
     if ($dateFrom) {
         $where[] = Query::assocParam('dt_event', $dateFrom, true, '>=');
     }
     if ($dateTo) {
         $where[] = Query::assocParam('dt_event', $dateTo, true, '<=');
     }
     $order = 'dt_event asc, id_rec asc';
     $limit = 500;
     /*
      * Работа с данными
      */
     $query = Query::select($what, 'ps_audit', $where, null, $order, $limit);
     $result = PSDB::getArray($query);
     foreach ($result as &$row) {
         //Декодируем действие
         $row['n_action'] = BaseAudit::getByCode($process)->decodeAction($row['n_action'], false);
         //Декодируем данные
         $encoded = 1 * $row['b_encoded'];
         if ($encoded) {
             $row['v_data'] = print_r(BaseAudit::decodeData($row['v_data']), true);
         }
         unset($row['b_encoded']);
     }
     $results = new SearchResults($result, $query);
     $results->addSetting('v_data', SearchResults::COL_PRE);
     $results->addSetting('n_action', SearchResults::COL_NOWRAP);
     return $results;
 }
 protected function processImpl(PostArrayAdapter $adapter, $button)
 {
     //return print_r($adapter->data, true);
     if (!$adapter->hasAllNoEmpty(array('ftype', 'fident'))) {
         return 'Не переданы все необходимые параметры.';
     }
     $ftype = $adapter->str('ftype');
     $fsubtype = $adapter->str('fsubtype');
     $ident = $adapter->str('fident');
     $folding = FoldedStorageInsts::byTypeStype($ftype, $fsubtype);
     $fEntity = $folding->getFoldedEntity($ident, true);
     $result = 'OK';
     switch ($button) {
         case self::BUTTON_SAVE:
             /*
              * На всякий случай убедимся, что нам передали все данные с формы
              */
             check_condition($adapter->hasAll($folding->getAllowedResourceTypes()), 'Переданы не все типы данных для фолдинга');
             //Основим обложку, если фолдинг с ней работает
             if ($folding->isImagesFactoryEnabled()) {
                 $cover = SimpleUploader::inst()->saveUploadedFile(false);
                 if ($cover) {
                     $folding->updateEntityCover($ident, $cover);
                     $cover->remove();
                 }
             }
             //Обновим остальные параемтры
             $folding->editEntity($ident, $adapter);
             break;
         case self::BUTTON_DELETE_ALL:
             //Удаляем строку из базы
             //TODO - выкинуто
             //TableExporter::inst()->getTable($folding->getTableName())->deleteFoldingDbRec($folding, $ident);
         //Удаляем строку из базы
         //TODO - выкинуто
         //TableExporter::inst()->getTable($folding->getTableName())->deleteFoldingDbRec($folding, $ident);
         case self::BUTTON_DELETE:
             $folding->deleteEntity($ident);
             $result = AP_APFoldingEdit::urlFoldingEntitys($folding);
             break;
     }
     return new AjaxSuccess($result);
 }
Beispiel #17
0
 protected function processImpl(PostArrayAdapter $adapter, $button)
 {
     $data = new RegFormData();
     /*
      * Имя пользователя
      */
     $name = $adapter->str(FORM_PARAM_REG_NAME);
     $error = UserInputValidator::validateShortText($name);
     if ($error) {
         return array(FORM_PARAM_REG_NAME => $error);
     }
     $name = UserInputTools::safeShortText($name);
     $data->setUserName($name);
     /*
      * e-mail
      */
     $mail = $adapter->str(FORM_PARAM_REG_MAIL);
     $error = UserInputValidator::validateEmail($mail);
     if ($error) {
         return array(FORM_PARAM_REG_MAIL => $error);
     }
     $data->setUserMail($mail);
     /*
      * Пол
      */
     $sex = $adapter->int(FORM_PARAM_REG_SEX);
     $error = UserInputValidator::validateSex($sex);
     if ($error) {
         return array(FORM_PARAM_REG_SEX => $error);
     }
     $data->setSex($sex);
     /*
      * Пароль
      */
     $pass = $adapter->str(FORM_PARAM_REG_PASS);
     $passConfirm = $adapter->str(FORM_PARAM_REG_PASS_CONF);
     $error = UserInputValidator::validatePass($pass, $passConfirm);
     if ($error) {
         return array(FORM_PARAM_REG_PASS => $error);
     }
     $error = UserInputValidator::validatePassConfirm($pass, $passConfirm);
     if ($error) {
         return array(FORM_PARAM_REG_PASS_CONF => $error);
     }
     $data->setPassword($pass);
     AuthManager::createUser($data);
     return new AjaxSuccess();
 }
Beispiel #18
0
 protected function processImpl(PostArrayAdapter $adapter, $button)
 {
     $data = new RegFormData();
     /*
      * Имя пользователя
      */
     $name = $adapter->str(FORM_PARAM_REG_NAME);
     $error = UserInputValidator::validateShortText($name);
     if ($error) {
         return array(FORM_PARAM_REG_NAME => $error);
     }
     $name = UserInputTools::safeShortText($name);
     $data->setUserName($name);
     /*
      * Пол
      */
     $sex = $adapter->int(FORM_PARAM_REG_SEX);
     $error = UserInputValidator::validateSex($sex);
     if ($error) {
         return array(FORM_PARAM_REG_SEX => $error);
     }
     $data->setSex($sex);
     /*
      * Обо мне
      */
     $about = $adapter->str(FORM_PARAM_REG_ABOUT);
     if ($about) {
         $error = UserInputValidator::validateLongText($about, false);
         if ($error) {
             return array(FORM_PARAM_REG_ABOUT => $error);
         }
         $data->setAboutSrc($about);
         $data->setAbout(UserInputTools::safeLongText($about));
     }
     /*
      * Контакты
      */
     $contacts = $adapter->str(FORM_PARAM_REG_CONTACTS);
     if ($contacts) {
         $error = UserInputValidator::validateLongText($contacts, false);
         if ($error) {
             return array(FORM_PARAM_REG_CONTACTS => $error);
         }
         $data->setContactsSrc($contacts);
         $data->setContacts(UserInputTools::safeLongText($contacts));
     }
     /*
      * Цитата
      */
     $msg = $adapter->str(FORM_PARAM_REG_MSG);
     if ($msg) {
         $error = UserInputValidator::validateLongText($msg, false);
         if ($error) {
             return array(FORM_PARAM_REG_MSG => $error);
         }
         $data->setMsgSrc($msg);
         $data->setMsg(UserInputTools::safeLongText($msg));
     }
     PsUser::inst()->updateInfo($data);
     return new AjaxSuccess();
 }
Beispiel #19
0
 /**
  * ===================
  * = ПАРАМЕТРЫ ФОРМЫ =
  * ===================
  */
 public function getFormAction()
 {
     return PostArrayAdapter::inst()->str(FORM_PARAM_ACTION);
 }
Beispiel #20
0
function smarty_function_html_input($params, Smarty_Internal_Template &$smarty)
{
    $adapter = ArrayAdapter::inst($params);
    $fieldId = $adapter->get('id');
    $label = $adapter->get('label');
    $value = $adapter->get('val');
    $inputType = $adapter->str('type');
    $help = $adapter->str('help');
    $RQ = PostArrayAdapter::inst();
    $attrs = array();
    switch ($inputType) {
        case 'hidden':
            echo PsHtml::hidden($fieldId, $value);
            break;
        case 'text':
            echo PsHtmlForm::text($label, $fieldId, $RQ->str($fieldId, $value), $attrs, $help);
            break;
        case 'datetime':
            $attrs['class'][] = 'ps-datetime-picker';
            echo PsHtmlForm::text($label, $fieldId, $RQ->str($fieldId, $value), $attrs, $help);
            break;
        case 'pass':
            echo PsHtmlForm::password($label, $fieldId, $RQ->str($fieldId));
            break;
        case 'file':
            $label = $adapter->get('label', 'Файл');
            $fieldId = $fieldId ? $fieldId : FORM_PARAM_FILE;
            echo PsHtmlForm::file($label, $fieldId, $help);
            break;
        case 'user':
            $label = $adapter->get('label', 'Ваше имя');
            if (AuthManager::isAuthorized()) {
                echo PsHtmlForm::textInfo($label, PsUser::inst()->getName());
            } else {
                $fieldId = $fieldId ? $fieldId : FORM_PARAM_NAME;
                echo PsHtmlForm::text($label, $fieldId, $RQ->str($fieldId), $attrs, $help);
            }
            break;
        case 'textarea':
            $label = $adapter->get('label', 'Текст сообщения');
            $fieldId = $fieldId ? $fieldId : FORM_PARAM_COMMENT;
            $value = $value ? $value : $RQ->str($fieldId, $value);
            $maxlen = $adapter->str(array('maxlen', 'maxlength'));
            $manual = $adapter->bool('manual');
            $codemirror = $adapter->str('codemirror');
            echo PsHtmlForm::textarea($label, $fieldId, $value, $maxlen, $manual, $codemirror, $attrs, $help);
            break;
        case 'submit':
            $buttons[] = $label ? $label : 'Отправить';
            for ($idx = 0; $idx <= 10; $idx++) {
                $button = $adapter->get("label{$idx}");
                if ($button) {
                    $buttons[] = $button;
                }
            }
            $canReset = $adapter->bool('reset');
            echo PsHtmlForm::submit($buttons, $canReset);
            break;
        case 'yesno':
            $fieldId = $fieldId ? $fieldId : 'yesno';
            $options[] = PsHtml::comboOption(0, 'Нет');
            $options[] = PsHtml::comboOption(1, 'Да');
            echo PsHtmlForm::select($label, $fieldId, $attrs, $options, 0);
            break;
        case 'sex':
            $value = $value ? $value : $RQ->int($fieldId);
            $options[] = PsHtml::comboOption(SEX_GIRL, 'Женский');
            $options[] = PsHtml::comboOption(SEX_BOY, 'Мужской');
            echo PsHtmlForm::select($label, $fieldId, $attrs, $options, $value);
            break;
        case 'posttype':
            $label = $label ? $label : 'Тип поста';
            $fieldId = $fieldId ? $fieldId : FORM_PARAM_POST_TYPE;
            $options = array();
            /* @var $pr PostsProcessor */
            foreach (Handlers::getInstance()->getPostsProcessors() as $type => $pr) {
                $title = $pr->postTitle();
                $options[] = PsHtml::comboOption($type, "{$title} ({$type})");
            }
            echo PsHtmlForm::select($label, $fieldId, $attrs, $options);
            break;
        case 'select':
            echo PsHtmlForm::select($label, $fieldId, $attrs, $adapter->arr('options'), $adapter->str('curVal'), $adapter->bool('hasEmpty'), $help);
            break;
        case 'timezone':
            $label = $label ? $label : 'Выберите временную зону';
            $tzSelect = PsTimeZone::inst()->zonesSelectHtml();
            echo PsHtmlForm::field($label, $tzSelect, $help);
            break;
        default:
            raise_error("Unsupported html input type: [{$inputType}]");
    }
}
Beispiel #21
0
 /** @return AbstractForm */
 public function getSubmittedForm()
 {
     return $this->getForm(PostArrayAdapter::inst()->str(FORM_PARAM_ID));
 }