/** * Add a user - handles both form and processing. */ public function add() { if (!$_SESSION['user']->getIsAdmin()) { 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') { $values = $this->getParams(); } else { $values = array(); } $form = $this->userForm($values); if ($method != 'POST' || $method == 'POST' && !$form->validate()) { $view = new b8\View('UserForm'); $view->type = 'add'; $view->user = null; $view->form = $form; return $view->render(); } $values = $form->getValues(); $values['hash'] = password_hash($values['password'], PASSWORD_DEFAULT); $user = new User(); $user->setValues($values); $user = $this->userStore->save($user); header('Location: ' . PHPCI_URL . 'user'); die; }