summaryrefslogtreecommitdiff
path: root/app/Controller
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2017-03-11 15:24:34 -0500
committerFrederic Guillot <fred@kanboard.net>2017-03-11 15:24:34 -0500
commita22b8f3dc73555800caf55768f04a7a2ce4af7f2 (patch)
tree60257cb9b508da83be5a9477c434fb53cc3c6f6d /app/Controller
parent469112918d0cfa6a43a7fdb829cd19bdf85cfcbe (diff)
Make user actions available from contextual menu
Diffstat (limited to 'app/Controller')
-rw-r--r--app/Controller/AvatarFileController.php13
-rw-r--r--app/Controller/TwoFactorController.php13
-rw-r--r--app/Controller/UserApiAccessController.php13
-rw-r--r--app/Controller/UserCredentialController.php14
-rw-r--r--app/Controller/UserModificationController.php8
-rw-r--r--app/Controller/UserViewController.php24
6 files changed, 60 insertions, 25 deletions
diff --git a/app/Controller/AvatarFileController.php b/app/Controller/AvatarFileController.php
index 2a63c5ae..327080d2 100644
--- a/app/Controller/AvatarFileController.php
+++ b/app/Controller/AvatarFileController.php
@@ -36,7 +36,7 @@ class AvatarFileController extends BaseController
$this->flash->failure(t('Unable to upload files, check the permissions of your data folder.'));
}
- $this->response->redirect($this->helper->url->to('AvatarFileController', 'show', array('user_id' => $user['id'])));
+ $this->renderResponse($user['id']);
}
/**
@@ -48,7 +48,7 @@ class AvatarFileController extends BaseController
$user = $this->getUser();
$this->avatarFileModel->remove($user['id']);
$this->userSession->refresh($user['id']);
- $this->response->redirect($this->helper->url->to('AvatarFileController', 'show', array('user_id' => $user['id'])));
+ $this->renderResponse($user['id']);
}
/**
@@ -91,4 +91,13 @@ class AvatarFileController extends BaseController
$this->logger->error($e->getMessage());
}
}
+
+ protected function renderResponse($userId)
+ {
+ if ($this->request->isAjax()) {
+ $this->show();
+ } else {
+ $this->response->redirect($this->helper->url->to('AvatarFileController', 'show', array('user_id' => $userId)));
+ }
+ }
}
diff --git a/app/Controller/TwoFactorController.php b/app/Controller/TwoFactorController.php
index 73060c44..80f89fbd 100644
--- a/app/Controller/TwoFactorController.php
+++ b/app/Controller/TwoFactorController.php
@@ -100,10 +100,15 @@ class TwoFactorController extends UserViewController
unset($this->sessionStorage->twoFactorSecret);
$this->userSession->disablePostAuthentication();
- $this->response->redirect($this->helper->url->to('TwoFactorController', 'index', array('user_id' => $user['id'])));
+ $this->response->redirect($this->helper->url->to('TwoFactorController', 'index', array('user_id' => $user['id'])), true);
} else {
$this->flash->failure(t('The two factor authentication code is not valid.'));
- $this->response->redirect($this->helper->url->to('TwoFactorController', 'show', array('user_id' => $user['id'])));
+
+ if ($this->request->isAjax()) {
+ $this->show();
+ } else {
+ $this->response->redirect($this->helper->url->to('TwoFactorController', 'show', array('user_id' => $user['id'])));
+ }
}
}
@@ -127,7 +132,7 @@ class TwoFactorController extends UserViewController
$this->userSession->disablePostAuthentication();
$this->flash->success(t('User updated successfully.'));
- $this->response->redirect($this->helper->url->to('TwoFactorController', 'index', array('user_id' => $user['id'])));
+ $this->response->redirect($this->helper->url->to('TwoFactorController', 'index', array('user_id' => $user['id'])), true);
}
/**
@@ -192,7 +197,7 @@ class TwoFactorController extends UserViewController
'twofactor_secret' => '',
));
- $this->response->redirect($this->helper->url->to('UserViewController', 'show', array('user_id' => $user['id'])));
+ $this->response->redirect($this->helper->url->to('UserViewController', 'show', array('user_id' => $user['id'])), true);
} else {
$this->response->html($this->helper->layout->user('twofactor/disable', array(
'user' => $user,
diff --git a/app/Controller/UserApiAccessController.php b/app/Controller/UserApiAccessController.php
index e03514d5..0f1c891e 100644
--- a/app/Controller/UserApiAccessController.php
+++ b/app/Controller/UserApiAccessController.php
@@ -32,7 +32,7 @@ class UserApiAccessController extends BaseController
'api_access_token' => Token::getToken(),
));
- $this->response->redirect($this->helper->url->to('UserApiAccessController', 'show', array('user_id' => $user['id'])));
+ $this->renderResponse();
}
public function remove()
@@ -45,6 +45,15 @@ class UserApiAccessController extends BaseController
'api_access_token' => null,
));
- $this->response->redirect($this->helper->url->to('UserApiAccessController', 'show', array('user_id' => $user['id'])));
+ $this->renderResponse();
+ }
+
+ protected function renderResponse()
+ {
+ if ($this->request->isAjax()) {
+ $this->show();
+ } else {
+ $this->response->redirect($this->helper->url->to('UserApiAccessController', 'show', array('user_id' => $user['id'])));
+ }
}
} \ No newline at end of file
diff --git a/app/Controller/UserCredentialController.php b/app/Controller/UserCredentialController.php
index 98fe967d..23e7edba 100644
--- a/app/Controller/UserCredentialController.php
+++ b/app/Controller/UserCredentialController.php
@@ -47,14 +47,14 @@ class UserCredentialController extends BaseController
if ($this->userModel->update($values)) {
$this->flash->success(t('Password modified successfully.'));
$this->userLockingModel->resetFailedLogin($user['username']);
+ $this->response->redirect($this->helper->url->to('UserViewController', 'show', array('user_id' => $user['id'])), true);
+ return;
} else {
$this->flash->failure(t('Unable to change the password.'));
}
-
- return $this->response->redirect($this->helper->url->to('UserViewController', 'show', array('user_id' => $user['id'])));
}
- return $this->changePassword($values, $errors);
+ $this->changePassword($values, $errors);
}
/**
@@ -97,14 +97,14 @@ class UserCredentialController extends BaseController
if ($valid) {
if ($this->userModel->update($values)) {
$this->flash->success(t('User updated successfully.'));
+ $this->response->redirect($this->helper->url->to('UserCredentialController', 'changeAuthentication', array('user_id' => $user['id'])), true);
+ return;
} else {
- $this->flash->failure(t('Unable to update your user.'));
+ $this->flash->failure(t('Unable to update this user.'));
}
-
- return $this->response->redirect($this->helper->url->to('UserCredentialController', 'changeAuthentication', array('user_id' => $user['id'])));
}
- return $this->changeAuthentication($values, $errors);
+ $this->changeAuthentication($values, $errors);
}
/**
diff --git a/app/Controller/UserModificationController.php b/app/Controller/UserModificationController.php
index d339fd9a..ed145921 100644
--- a/app/Controller/UserModificationController.php
+++ b/app/Controller/UserModificationController.php
@@ -57,13 +57,13 @@ class UserModificationController extends BaseController
if ($valid) {
if ($this->userModel->update($values)) {
$this->flash->success(t('User updated successfully.'));
+ $this->response->redirect($this->helper->url->to('UserViewController', 'show', array('user_id' => $user['id'])), true);
+ return;
} else {
- $this->flash->failure(t('Unable to update your user.'));
+ $this->flash->failure(t('Unable to update this user.'));
}
-
- return $this->response->redirect($this->helper->url->to('UserViewController', 'show', array('user_id' => $user['id'])));
}
- return $this->show($values, $errors);
+ $this->show($values, $errors);
}
}
diff --git a/app/Controller/UserViewController.php b/app/Controller/UserViewController.php
index a73c5c51..eb987379 100644
--- a/app/Controller/UserViewController.php
+++ b/app/Controller/UserViewController.php
@@ -123,7 +123,12 @@ class UserViewController extends BaseController
$this->checkCSRFParam();
$user = $this->getUser();
$this->rememberMeSessionModel->remove($this->request->getIntegerParam('id'));
- $this->response->redirect($this->helper->url->to('UserViewController', 'sessions', array('user_id' => $user['id'])));
+
+ if ($this->request->isAjax()) {
+ $this->sessions();
+ } else {
+ $this->response->redirect($this->helper->url->to('UserViewController', 'sessions', array('user_id' => $user['id'])), true);
+ }
}
/**
@@ -139,10 +144,11 @@ class UserViewController extends BaseController
$values = $this->request->getValues();
$this->userNotificationModel->saveSettings($user['id'], $values);
$this->flash->success(t('User updated successfully.'));
- return $this->response->redirect($this->helper->url->to('UserViewController', 'notifications', array('user_id' => $user['id'])));
+ $this->response->redirect($this->helper->url->to('UserViewController', 'notifications', array('user_id' => $user['id'])), true);
+ return;
}
- return $this->response->html($this->helper->layout->user('user_view/notifications', array(
+ $this->response->html($this->helper->layout->user('user_view/notifications', array(
'projects' => $this->projectUserRoleModel->getProjectsByUser($user['id'], array(ProjectModel::ACTIVE)),
'notifications' => $this->userNotificationModel->readSettings($user['id']),
'types' => $this->userNotificationTypeModel->getTypes(),
@@ -164,7 +170,8 @@ class UserViewController extends BaseController
$values = $this->request->getValues();
$this->userMetadataModel->save($user['id'], $values);
$this->flash->success(t('User updated successfully.'));
- $this->response->redirect($this->helper->url->to('UserViewController', 'integrations', array('user_id' => $user['id'])));
+ $this->response->redirect($this->helper->url->to('UserViewController', 'integrations', array('user_id' => $user['id'])), true);
+ return;
}
$this->response->html($this->helper->layout->user('user_view/integrations', array(
@@ -206,10 +213,15 @@ class UserViewController extends BaseController
$this->flash->failure(t('Unable to update this user.'));
}
- return $this->response->redirect($this->helper->url->to('UserViewController', 'share', array('user_id' => $user['id'])));
+ if (! $this->request->isAjax()) {
+ $this->response->redirect($this->helper->url->to('UserViewController', 'share', array('user_id' => $user['id'])), true);
+ return;
+ }
+
+ $user = $this->getUser();
}
- return $this->response->html($this->helper->layout->user('user_view/share', array(
+ $this->response->html($this->helper->layout->user('user_view/share', array(
'user' => $user,
'title' => t('Public access'),
)));