public function add()
    {
        $this->requireAdmin();

        $this->layout->title = Lang::get('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();
        }


        $name = $this->getParam('name', null);
        $email = $this->getParam('email', null);
        $password = $this->getParam('password', null);
        $isAdmin = (int)$this->getParam('is_admin', 0);

        $this->userService->createUser($name, $email, $password, $isAdmin);

        $response = new b8\Http\Response\RedirectResponse();
        $response->setHeader('Location', PHPCI_URL . 'user');
        return $response;
    }
public function add()
    {
        $this->requireAdmin();

        $this->layout->title = Lang::get('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();
        }


        $name = $this->getParam('name', null);
        $email = $this->getParam('email', null);
        $password = $this->getParam('password', null);
        $isAdmin = (int)$this->getParam('is_admin', 0);

        $this->userService->createUser($name, $email, $password, $isAdmin);

        $response = new b8\Http\Response\RedirectResponse();
        $response->setHeader('Location', PHPCI_URL . 'user');
        return $response;
    }
public function add ( ) { $ this -> requireAdmin ( ) ; $ this -> layout -> title = Lang :: get ( '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 ( ) ; } $ name = $ this -> getParam ( 'name' , null ) ; $ email = $ this -> getParam ( 'email' , null ) ; $ password = $ this -> getParam ( 'password' , null ) ; $ isAdmin = ( int ) $ this -> getParam ( 'is_admin' , 0 ) ; $ this -> userService -> createUser ( $ name , $ email , $ password , $ isAdmin ) ; $ response = new b8 \ Http \ Response \ RedirectResponse ( ) ; $ response -> setHeader ( 'Location' , PHPCI_URL . 'user' ) ; return $ response ; }
Add a user - handles both form and processing.
Add a user - handles both form and processing .