diff --git a/app/Controller/Config.php b/app/Controller/Config.php
index ebb541d21..deafd05bf 100644
--- a/app/Controller/Config.php
+++ b/app/Controller/Config.php
@@ -176,7 +176,7 @@ class Config extends BaseController
public function downloadDb()
{
$this->checkCSRFParam();
- $this->response->withDownload('db.sqlite.gz');
+ $this->response->withFileDownload('db.sqlite.gz');
$this->response->binary($this->config->downloadDatabase());
}
diff --git a/app/Controller/Export.php b/app/Controller/Export.php
index f5783b72b..7e1d2fdc8 100644
--- a/app/Controller/Export.php
+++ b/app/Controller/Export.php
@@ -29,7 +29,7 @@ class Export extends BaseController
if ($from && $to) {
$data = $this->$model->$method($project['id'], $from, $to);
- $this->response->withDownload($filename.'.csv');
+ $this->response->withFileDownload($filename.'.csv');
$this->response->csv($data);
}
diff --git a/app/Controller/FileViewer.php b/app/Controller/FileViewer.php
index a990e12a4..52ff0d0ef 100644
--- a/app/Controller/FileViewer.php
+++ b/app/Controller/FileViewer.php
@@ -123,7 +123,7 @@ class FileViewer extends BaseController
{
try {
$file = $this->getFile();
- $this->response->withDownload($file['name']);
+ $this->response->withFileDownload($file['name']);
$this->objectStorage->output($file['path']);
} catch (ObjectStorageException $e) {
$this->logger->error($e->getMessage());
diff --git a/app/Controller/TaskImport.php b/app/Controller/TaskImport.php
index 5dbf86788..5e37fb2f3 100644
--- a/app/Controller/TaskImport.php
+++ b/app/Controller/TaskImport.php
@@ -69,7 +69,7 @@ class TaskImport extends BaseController
*/
public function template()
{
- $this->response->withDownload('tasks.csv');
+ $this->response->withFileDownload('tasks.csv');
$this->response->csv(array($this->taskImport->getColumnMapping()));
}
}
diff --git a/app/Controller/UserImport.php b/app/Controller/UserImportController.php
similarity index 62%
rename from app/Controller/UserImport.php
rename to app/Controller/UserImportController.php
index b99e56a0a..b3cb52d1e 100644
--- a/app/Controller/UserImport.php
+++ b/app/Controller/UserImportController.php
@@ -7,40 +7,63 @@ use Kanboard\Core\Csv;
/**
* User Import controller
*
- * @package controller
+ * @package Kanboard\Controller
* @author Frederic Guillot
*/
-class UserImport extends BaseController
+class UserImportController extends BaseController
{
/**
* Upload the file and ask settings
*
+ * @param array $values
+ * @param array $errors
*/
- public function step1(array $values = array(), array $errors = array())
+ public function show(array $values = array(), array $errors = array())
{
- $this->response->html($this->helper->layout->app('user_import/step1', array(
+ $this->response->html($this->template->render('user_import/show', array(
'values' => $values,
'errors' => $errors,
'max_size' => ini_get('upload_max_filesize'),
'delimiters' => Csv::getDelimiters(),
'enclosures' => Csv::getEnclosures(),
- 'title' => t('Import users from CSV file'),
)));
}
/**
- * Process CSV file
- *
+ * Submit form
*/
- public function step2()
+ public function save()
{
$values = $this->request->getValues();
$filename = $this->request->getFilePath('file');
if (! file_exists($filename)) {
- $this->step1($values, array('file' => array(t('Unable to read your file'))));
+ $this->flash->failure(t('Unable to read your file'));
+ } else {
+ $this->importFile($values, $filename);
}
+ $this->response->redirect($this->helper->url->to('user', 'index'));
+ }
+
+ /**
+ * Generate template
+ *
+ */
+ public function template()
+ {
+ $this->response->withFileDownload('users.csv');
+ $this->response->csv(array($this->userImport->getColumnMapping()));
+ }
+
+ /**
+ * Process file
+ *
+ * @param array $values
+ * @param $filename
+ */
+ private function importFile(array $values, $filename)
+ {
$csv = new Csv($values['delimiter'], $values['enclosure']);
$csv->setColumnMapping($this->userImport->getColumnMapping());
$csv->read($filename, array($this->userImport, 'import'));
@@ -50,17 +73,5 @@ class UserImport extends BaseController
} else {
$this->flash->failure(t('Nothing have been imported!'));
}
-
- $this->response->redirect($this->helper->url->to('userImport', 'step1'));
- }
-
- /**
- * Generate template
- *
- */
- public function template()
- {
- $this->response->withDownload('users.csv');
- $this->response->csv(array($this->userImport->getColumnMapping()));
}
}
diff --git a/app/Core/Http/Response.php b/app/Core/Http/Response.php
index fd67ec95e..1c5310d04 100644
--- a/app/Core/Http/Response.php
+++ b/app/Core/Http/Response.php
@@ -172,7 +172,7 @@ class Response extends Base
* @param string $filename
* @return $this
*/
- public function withDownload($filename)
+ public function withFileDownload($filename)
{
$this->withHeader('Content-Disposition', 'attachment; filename="'.$filename.'"');
$this->withHeader('Content-Transfer-Encoding', 'binary');
diff --git a/app/ServiceProvider/AuthenticationProvider.php b/app/ServiceProvider/AuthenticationProvider.php
index b9082c26c..8baa02ea6 100644
--- a/app/ServiceProvider/AuthenticationProvider.php
+++ b/app/ServiceProvider/AuthenticationProvider.php
@@ -137,7 +137,7 @@ class AuthenticationProvider implements ServiceProviderInterface
$acl->add('ProjectCreation', 'create', Role::APP_MANAGER);
$acl->add('Projectuser', '*', Role::APP_MANAGER);
$acl->add('Twofactor', 'disable', Role::APP_ADMIN);
- $acl->add('UserImport', '*', Role::APP_ADMIN);
+ $acl->add('UserImportController', '*', Role::APP_ADMIN);
$acl->add('User', array('index', 'create', 'save', 'authentication'), Role::APP_ADMIN);
$acl->add('UserStatus', '*', Role::APP_ADMIN);
diff --git a/app/Template/user/index.php b/app/Template/user/index.php
index 0b5da17c0..00cd0c82c 100644
--- a/app/Template/user/index.php
+++ b/app/Template/user/index.php
@@ -4,7 +4,7 @@
- = $this->url->link(t('New local user'), 'user', 'create') ?>
- = $this->url->link(t('New remote user'), 'user', 'create', array('remote' => 1)) ?>
- - = $this->url->link(t('Import'), 'userImport', 'step1') ?>
+ - = $this->url->link(t('Import'), 'UserImportController', 'show', array(), false, 'popover') ?>
- = $this->url->link(t('View all groups'), 'group', 'index') ?>
diff --git a/app/Template/user_import/show.php b/app/Template/user_import/show.php
new file mode 100644
index 000000000..54a66237c
--- /dev/null
+++ b/app/Template/user_import/show.php
@@ -0,0 +1,41 @@
+
+
+
+
+ - = t('Your file must use the predefined CSV format') ?>
+ - = t('Your file must be encoded in UTF-8') ?>
+ - = t('The first row must be the header') ?>
+ - = t('Duplicates are not imported') ?>
+ - = t('Usernames must be lowercase and unique') ?>
+ - = t('Passwords will be encrypted if present') ?>
+
+
+
+
diff --git a/app/Template/user_import/step1.php b/app/Template/user_import/step1.php
deleted file mode 100644
index 592587a3e..000000000
--- a/app/Template/user_import/step1.php
+++ /dev/null
@@ -1,46 +0,0 @@
-
-
-
-
-
-
-
- - = t('Your file must use the predefined CSV format') ?>
- - = t('Your file must be encoded in UTF-8') ?>
- - = t('The first row must be the header') ?>
- - = t('Duplicates are not imported') ?>
- - = t('Usernames must be lowercase and unique') ?>
- - = t('Passwords will be encrypted if present') ?>
-
-
- = $this->url->link(t('Download CSV template'), 'userImport', 'template') ?>
-
\ No newline at end of file