예제 #1
0
 /**
  * @return \EasyMinerCenter\Model\EasyMiner\Entities\User|null
  */
 private function getCurrentUser()
 {
     try {
         return $this->usersFacade->findUser($this->user->id);
     } catch (\Exception $e) {
         /*ignore error (uživatel nemusí být přihlášen)*/
     }
     return null;
 }
 /**
  * Akce pro vytvoření nového rulesetu (se zadaným jménem)
  * @param string $name
  * @param string $description=""
  * @throws InvalidArgumentException
  */
 public function actionNew($name, $description = "")
 {
     $this->ruleSetsFacade->checkUniqueRuleSetNameByUser($name, $this->user->id);
     //vytvoření rulesetu
     $ruleSet = new RuleSet();
     $ruleSet->name = $name;
     $ruleSet->description = $description;
     $ruleSet->user = $this->usersFacade->findUser($this->user->id);
     $this->ruleSetsFacade->saveRuleSet($ruleSet);
     //odeslání výsledku
     $this->sendJsonResponse($ruleSet->getDataArr());
 }
 /**
  * Formulář pro obnovu zapomenutého hesla
  * @return Form
  */
 protected function createComponentForgottenPasswordForm()
 {
     $form = new Form();
     $form->setTranslator($this->translator);
     $form->addProtection('Please submit the form again');
     $form->addText('email', 'E-mail:')->setRequired('You have to input your e-mail!')->addRule(Form::EMAIL, 'You have to input valid e-mail!');
     $form->addSubmit('submit', 'Submit...')->onClick[] = function (SubmitButton $button) {
         $values = $button->getForm(true)->getValues(true);
         try {
             $user = $this->usersFacade->findUserByEmail($values['email']);
             $userForgottenPassword = $this->usersFacade->generateUserForgottenPassword($user);
             /** @var MailerControl $mailerControl */
             $mailerControl = $this->getComponent('mailerControl', true);
             $result = $mailerControl->sendMailForgottenPassword($userForgottenPassword);
             if ($result) {
                 $this->flashMessage('Information to reset your password has been sent to your e-mail.');
             } else {
                 $this->flashMessage('It was not possible to sent you information for password reset. Please try it later, or contact the administrator.');
             }
         } catch (\Exception $e) {
             //nebyl nalezen příslušný přihlašovací účet...
             $this->flashMessage('Selected user account does not exist. Please register a new one...');
             $this->redirect('register');
             return;
         }
         $this->redirect('login');
     };
     $form->addSubmit('storno', 'storno')->setValidationScope([])->onClick[] = function () {
         $this->redirect('login');
     };
     return $form;
 }
 /**
  * Formulář pro import CSV souboru
  * @return Form
  */
 public function createComponentImportCsvForm()
 {
     $form = new Form();
     $form->setTranslator($this->translator);
     $tableName = $form->addText('table', 'Table name:')->setAttribute('class', 'normalWidth')->setRequired('Input table name!');
     $presenter = $this;
     $tableName->addRule(Form::MAX_LENGTH, 'Max length of the table name is %s characters!', 30)->addRule(Form::MIN_LENGTH, 'Min length of the table name is %s characters!', 3)->addRule(Form::PATTERN, 'Table name can contain only letters, numbers and underscore and start with a letter!', '[a-zA-Z0-9_]+')->addRule(function (TextInput $control) use($presenter) {
         $formValues = $control->form->getValues(true);
         $csvColumnsCount = $presenter->fileImportsFacade->getColsCountInCSV($formValues['file'], $formValues['separator'], $formValues['enclosure'], $formValues['escape']);
         $databaseType = $presenter->databasesFacade->prefferedDatabaseType($csvColumnsCount);
         $newDatasource = $presenter->datasourcesFacade->prepareNewDatasourceForUser($this->usersFacade->findUser($presenter->user->id), $databaseType);
         $presenter->databasesFacade->openDatabase($newDatasource->getDbConnection());
         return !$presenter->databasesFacade->checkTableExists($control->value);
     }, 'Table with this name already exists!');
     $form->addSelect('separator', 'Separator:', array(',' => 'Comma (,)', ';' => 'Semicolon (;)', '|' => 'Vertical line (|)', '\\t' => 'Tab (\\t)'))->setRequired()->setAttribute('class', 'normalWidth');
     $form->addSelect('encoding', 'Encoding:', array('utf8' => 'UTF-8', 'cp1250' => 'WIN 1250', 'iso-8859-1' => 'ISO 8859-1'))->setRequired()->setAttribute('class', 'normalWidth');
     $file = $form->addHidden('file');
     $file->setAttribute('id', 'frm-importCsvForm-file');
     $form->addHidden('type');
     $form->addText('enclosure', 'Enclosure:', 1, 1)->setDefaultValue('"');
     $form->addText('escape', 'Escape:', 1, 1)->setDefaultValue('\\');
     $nullValuesArr = CsvImport::getDefaultNullValuesArr();
     $defaultNullValue = 'none';
     foreach ($nullValuesArr as $value => $text) {
         $defaultNullValue = $value;
         break;
     }
     $form->addSelect('nullValue', 'Null values:', array_merge(['none' => '--none--'], $nullValuesArr))->setAttribute('title', 'This value will be imported as missing (null).')->setDefaultValue($defaultNullValue)->setAttribute('class', 'normalWidth');
     $form->addSubmit('submit', 'Import data into database...')->onClick[] = function (SubmitButton $submitButton) {
         /** @var Form $form */
         $form = $submitButton->form;
         $values = $form->getValues();
         $nullValue = $values->nullValue == 'none' ? null : $values->nullValue;
         $user = $this->usersFacade->findUser($this->user->id);
         $colsCount = $this->fileImportsFacade->getColsCountInCSV($values->file, $values->separator, $values->enclosure, $values->escape);
         $dbType = $this->databasesFacade->prefferedDatabaseType($colsCount);
         //připravení připojení k DB
         $datasource = $this->datasourcesFacade->prepareNewDatasourceForUser($user, $dbType);
         $this->fileImportsFacade->importCsvFile($values->file, $datasource->getDbConnection(), $values->table, $values->encoding, $values->separator, $values->enclosure, $values->escape, $nullValue);
         $datasource->name = $values->table;
         //uložíme datasource
         $this->datasourcesFacade->saveDatasource($datasource);
         //smažeme dočasné soubory...
         $this->fileImportsFacade->deleteFile($values->file);
         $this->redirect('Data:newMinerFromDatasource', array('datasource' => $datasource->datasourceId));
     };
     $form->addSubmit('storno', 'storno')->setValidationScope([])->onClick[] = function (SubmitButton $button) use($file) {
         /** @var DataPresenter $presenter */
         $presenter = $button->form->getParent();
         $this->fileImportsFacade->deleteFile($file->value);
         $presenter->redirect('Data:newMiner');
     };
     return $form;
 }
 /**
  * @throws AuthenticationException
  * @throws \Drahak\Restful\Application\BadRequestException
  * @throws \Exception
  */
 public function startup()
 {
     //kontrola přihlášeného uživatele
     $apiKey = @$this->getInput()->getData()['apiKey'];
     if (empty($apiKey)) {
         $authorizationHeader = $this->getHttpRequest()->getHeader('Authorization');
         $apiKey = substr($authorizationHeader, 0, 7) == "ApiKey " ? substr($authorizationHeader, 7) : null;
     }
     if (empty($apiKey)) {
         throw new AuthenticationException("You have to use API KEY!", IAuthenticator::FAILURE);
     } else {
         $this->identity = $this->usersFacade->authenticateUserByApiKey($apiKey, $this->currentUser);
     }
     //spuštění výchozí startup() akce
     parent::startup();
 }