summaryrefslogtreecommitdiff
path: root/app/Controller
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-05-15 21:50:46 -0400
committerFrederic Guillot <fred@kanboard.net>2016-05-15 21:50:46 -0400
commit9ec654186a8374b0d260cf641114bcbde1f6bb4f (patch)
tree38d8fccab165a4aae26cfb9e7c56c185bbdd9b06 /app/Controller
parent20052c7dd295464c7782350628701675b1f07db7 (diff)
User creation forms are now displayed with inline popup
Diffstat (limited to 'app/Controller')
-rw-r--r--app/Controller/User.php58
-rw-r--r--app/Controller/UserCreationController.php83
2 files changed, 83 insertions, 58 deletions
diff --git a/app/Controller/User.php b/app/Controller/User.php
index 11a7a01e..190acb61 100644
--- a/app/Controller/User.php
+++ b/app/Controller/User.php
@@ -3,9 +3,7 @@
namespace Kanboard\Controller;
use Kanboard\Core\Controller\PageNotFoundException;
-use Kanboard\Notification\Mail as MailNotification;
use Kanboard\Model\Project as ProjectModel;
-use Kanboard\Core\Security\Role;
/**
* User controller
@@ -56,62 +54,6 @@ class User extends BaseController
}
/**
- * Display a form to create a new user
- *
- * @access public
- * @param array $values
- * @param array $errors
- */
- public function create(array $values = array(), array $errors = array())
- {
- $is_remote = $this->request->getIntegerParam('remote') == 1 || (isset($values['is_ldap_user']) && $values['is_ldap_user'] == 1);
-
- $this->response->html($this->helper->layout->app($is_remote ? 'user/create_remote' : 'user/create_local', array(
- 'timezones' => $this->timezone->getTimezones(true),
- 'languages' => $this->language->getLanguages(true),
- 'roles' => $this->role->getApplicationRoles(),
- 'projects' => $this->project->getList(),
- 'errors' => $errors,
- 'values' => $values + array('role' => Role::APP_USER),
- 'title' => t('New user')
- )));
- }
-
- /**
- * Validate and save a new user
- *
- * @access public
- */
- public function save()
- {
- $values = $this->request->getValues();
- list($valid, $errors) = $this->userValidator->validateCreation($values);
-
- if ($valid) {
- $project_id = empty($values['project_id']) ? 0 : $values['project_id'];
- unset($values['project_id']);
-
- $user_id = $this->user->create($values);
-
- if ($user_id !== false) {
- $this->projectUserRole->addUser($project_id, $user_id, Role::PROJECT_MEMBER);
-
- if (! empty($values['notifications_enabled'])) {
- $this->userNotificationType->saveSelectedTypes($user_id, array(MailNotification::TYPE));
- }
-
- $this->flash->success(t('User created successfully.'));
- return $this->response->redirect($this->helper->url->to('user', 'show', array('user_id' => $user_id)));
- } else {
- $this->flash->failure(t('Unable to create your user.'));
- $values['project_id'] = $project_id;
- }
- }
-
- return $this->create($values, $errors);
- }
-
- /**
* Display user information
*
* @access public
diff --git a/app/Controller/UserCreationController.php b/app/Controller/UserCreationController.php
new file mode 100644
index 00000000..d1c554ae
--- /dev/null
+++ b/app/Controller/UserCreationController.php
@@ -0,0 +1,83 @@
+<?php
+
+namespace Kanboard\Controller;
+
+use Kanboard\Core\Security\Role;
+use Kanboard\Notification\Mail as MailNotification;
+
+/**
+ * Class UserCreationController
+ *
+ * @package Kanboard\Controller
+ * @author Frederic Guillot
+ */
+class UserCreationController extends BaseController
+{
+ /**
+ * Display a form to create a new user
+ *
+ * @access public
+ * @param array $values
+ * @param array $errors
+ */
+ public function show(array $values = array(), array $errors = array())
+ {
+ $isRemote = $this->request->getIntegerParam('remote') == 1 || (isset($values['is_ldap_user']) && $values['is_ldap_user'] == 1);
+ $template = $isRemote ? 'user_creation/remote' : 'user_creation/local';
+
+ $this->response->html($this->template->render($template, array(
+ 'timezones' => $this->timezone->getTimezones(true),
+ 'languages' => $this->language->getLanguages(true),
+ 'roles' => $this->role->getApplicationRoles(),
+ 'projects' => $this->project->getList(),
+ 'errors' => $errors,
+ 'values' => $values + array('role' => Role::APP_USER),
+ )));
+ }
+
+ /**
+ * Validate and save a new user
+ *
+ * @access public
+ */
+ public function save()
+ {
+ $values = $this->request->getValues();
+ list($valid, $errors) = $this->userValidator->validateCreation($values);
+
+ if ($valid) {
+ $this->createUser($values);
+ } else {
+ $this->show($values, $errors);
+ }
+ }
+
+ /**
+ * Create user
+ *
+ * @param array $values
+ */
+ private function createUser(array $values)
+ {
+ $project_id = empty($values['project_id']) ? 0 : $values['project_id'];
+ unset($values['project_id']);
+
+ $user_id = $this->user->create($values);
+
+ if ($user_id !== false) {
+ if ($project_id !== 0) {
+ $this->projectUserRole->addUser($project_id, $user_id, Role::PROJECT_MEMBER);
+ }
+
+ if (! empty($values['notifications_enabled'])) {
+ $this->userNotificationType->saveSelectedTypes($user_id, array(MailNotification::TYPE));
+ }
+
+ $this->flash->success(t('User created successfully.'));
+ $this->response->redirect($this->helper->url->to('user', 'show', array('user_id' => $user_id)));
+ } else {
+ $this->flash->failure(t('Unable to create your user.'));
+ $this->response->redirect($this->helper->url->to('user', 'index'));
+ }
+ }
+}