Fixing merge conflict
This commit is contained in:
commit
1f7f318634
8 changed files with 120 additions and 44 deletions
|
|
@ -10,6 +10,8 @@
|
|||
namespace PHPCI\Controller;
|
||||
|
||||
use b8;
|
||||
use b8\Exception\HttpException\ForbiddenException;
|
||||
use b8\Exception\HttpException\NotFoundException;
|
||||
use b8\Form;
|
||||
use PHPCI\Controller;
|
||||
use PHPCI\Model\User;
|
||||
|
|
@ -106,12 +108,11 @@ class UserController extends Controller
|
|||
public function add()
|
||||
{
|
||||
if (!$_SESSION['user']->getIsAdmin()) {
|
||||
throw new \Exception('You do not have permission to do that.');
|
||||
throw new ForbiddenException('You do not have permission to do that.');
|
||||
}
|
||||
|
||||
$this->config->set('page_title', 'Add User');
|
||||
|
||||
|
||||
$method = $this->request->getMethod();
|
||||
|
||||
if ($method == 'POST') {
|
||||
|
|
@ -132,7 +133,6 @@ class UserController extends Controller
|
|||
}
|
||||
|
||||
$values = $form->getValues();
|
||||
$values['is_admin'] = $values['admin'] ? 1 : 0;
|
||||
$values['hash'] = password_hash($values['password'], PASSWORD_DEFAULT);
|
||||
|
||||
$user = new User();
|
||||
|
|
@ -150,13 +150,15 @@ class UserController extends Controller
|
|||
public function edit($userId)
|
||||
{
|
||||
if (!$_SESSION['user']->getIsAdmin()) {
|
||||
throw new \Exception('You do not have permission to do that.');
|
||||
throw new ForbiddenException('You do not have permission to do that.');
|
||||
}
|
||||
|
||||
$method = $this->request->getMethod();
|
||||
$user = $this->userStore->getById($userId);
|
||||
|
||||
$this->config->set('page_title', 'Edit: ' . $user->getName());
|
||||
if (empty($user)) {
|
||||
throw new NotFoundException('User with ID: ' . $userId . ' does not exist.');
|
||||
}
|
||||
|
||||
$values = array_merge($user->getDataArray(), $this->getParams());
|
||||
$form = $this->userForm($values, 'edit/' . $userId);
|
||||
|
|
@ -170,13 +172,17 @@ class UserController extends Controller
|
|||
return $view->render();
|
||||
}
|
||||
|
||||
$values['is_admin'] = $values['admin'] ? 1 : 0;
|
||||
|
||||
if (!empty($values['password'])) {
|
||||
$values['hash'] = password_hash($values['password'], PASSWORD_DEFAULT);
|
||||
}
|
||||
|
||||
$user->setValues($values);
|
||||
|
||||
$isAdmin = $this->getParam('is_admin');
|
||||
if (empty($isAdmin)) {
|
||||
$user->setIsAdmin(0);
|
||||
}
|
||||
|
||||
$this->userStore->save($user);
|
||||
|
||||
header('Location: '.PHPCI_URL.'user');
|
||||
|
|
@ -208,8 +214,15 @@ class UserController extends Controller
|
|||
$form->addField($field);
|
||||
|
||||
$field = new Form\Element\Password('password');
|
||||
$field->setRequired(true);
|
||||
$field->setLabel('Password' . ($type == 'edit' ? ' (leave blank to keep current password)' : ''));
|
||||
|
||||
if ($type == 'add') {
|
||||
$field->setRequired(true);
|
||||
$field->setLabel('Password');
|
||||
} else {
|
||||
$field->setRequired(false);
|
||||
$field->setLabel('Password (leave blank to keep current password)');
|
||||
}
|
||||
|
||||
$field->setClass('form-control');
|
||||
$field->setContainerClass('form-group');
|
||||
$form->addField($field);
|
||||
|
|
@ -236,10 +249,15 @@ class UserController extends Controller
|
|||
public function delete($userId)
|
||||
{
|
||||
if (!$_SESSION['user']->getIsAdmin()) {
|
||||
throw new \Exception('You do not have permission to do that.');
|
||||
throw new ForbiddenException('You do not have permission to do that.');
|
||||
}
|
||||
|
||||
$user = $this->userStore->getById($userId);
|
||||
|
||||
if (empty($user)) {
|
||||
throw new NotFoundException('User with ID: ' . $userId . ' does not exist.');
|
||||
}
|
||||
|
||||
$this->userStore->delete($user);
|
||||
|
||||
header('Location: '.PHPCI_URL.'user');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue