public function action_user($id = null) { if (intval($id) < 1) { throw new NotFoundHttpException(); } $data = []; $form = []; try { /** @var \Foolz\FoolFrame\Model\Users $users */ $users = $this->getContext()->getService('users'); $data['object'] = $users->getUserBy('id', $id); $data['object']->password = ''; } catch (\Foolz\FoolFrame\Model\UsersWrongIdException $e) { throw new NotFoundHttpException(); } $form['open'] = array('type' => 'open'); $form['paragraph'] = array('type' => 'paragraph', 'help' => _i('You can customize your account here.')); $form['paragraph-2'] = array('type' => 'paragraph', 'help' => '<img src="' . Gravatar::image($data['object']->email) . '" width="80" height="80" style="padding:2px; border: 1px solid #ccc;"/> ' . _i('The avatar is automatically fetched from %s, based on the user\'s registration email.', '<a href="http://gravatar.com" target="_blank">Gravatar</a>')); if ($this->getAuth()->hasAccess('users.change_credentials')) { $form['username'] = array('type' => 'input', 'database' => true, 'label' => _i('Username'), 'class' => 'span3', 'help' => _i('Change the username'), 'validation' => [new Trim(), new Assert\Length(['max' => 32])]); $form['email'] = array('type' => 'input', 'database' => true, 'label' => _i('Email'), 'class' => 'span3', 'help' => _i('Change the email'), 'validation' => [new Trim(), new Assert\Length(['max' => 32])]); $form['password'] = array('type' => 'password', 'database' => true, 'label' => _i('Password'), 'class' => 'span3', 'help' => _i('Change the password (leave empty to not change it)')); } $form['bio'] = array('type' => 'textarea', 'database' => true, 'label' => 'Bio', 'style' => 'height:150px;', 'class' => 'span5', 'help' => _i('Some details about you'), 'validation' => [new Trim(), new Assert\Length(['max' => 360])]); $form['twitter'] = array('type' => 'input', 'database' => true, 'label' => 'Twitter', 'class' => 'span3', 'help' => _i('Your twitter nickname'), 'validation' => [new Trim(), new Assert\Length(['max' => 32])]); $form['display_name'] = array('type' => 'input', 'database' => true, 'label' => 'Display name', 'class' => 'span3', 'help' => _i('Alternative name in place of login username'), 'validation' => [new Trim(), new Assert\Length(['max' => 32])]); if ($this->getAuth()->hasAccess('users.change_group')) { $groups = $this->config->get('foolz/foolframe', 'foolauth', 'groups'); $group_ids = []; foreach ($groups as $level => $group) { $group_ids[$level] = $group['name']; } $form['group_id'] = array('type' => 'radio', 'database' => true, 'label' => 'Display name', 'help' => _i('Change the group of the user'), 'radio_values' => $group_ids); } $form['submit'] = array('type' => 'submit', 'class' => 'btn btn-primary', 'value' => _i('Submit')); $form['close'] = array('type' => 'close'); $data['form'] = $form; if ($this->getPost() && !$this->checkCsrfToken()) { $this->notices->set('warning', _i('The security token wasn\'t found. Try resubmitting.')); } elseif ($this->getPost()) { $result = Validator::formValidate($form, $this->getPost()); if (isset($result['error'])) { $this->notices->set('warning', $result['error']); } else { if (isset($result['warning'])) { $this->notices->set('warning', $result['warning']); } $this->notices->set('success', _i('Preferences updated.')); $user = $users->getUserBy('id', $id); $user->save($result['success']); $data['object'] = $user; $data['object']->password = ''; } } // create a form $this->param_manager->setParam('method_title', [_i('Manage'), _i('Edit'), $data['object']->username]); $this->builder->createPartial('body', 'form_creator')->getParamManager()->setParams($data); return new Response($this->builder->build()); }
function action_add() { $data['form'] = $this->radix_coll->structure(); if ($this->getPost() && !$this->checkCsrfToken()) { $this->notices->set('warning', _i('The security token wasn\'t found. Try resubmitting.')); } elseif ($this->getPost()) { $result = Validator::formValidate($data['form'], $this->getPost()); if (isset($result['error'])) { $this->notices->set('warning', $result['error']); } else { // it's actually fully checked, we just have to throw it in DB $this->radix_coll->save($result['success']); $this->notices->setFlash('success', _i('New board created!')); return $this->redirect('admin/boards/board/' . $result['success']['shortname']); } } // the actual POST is in the board() function $data['form']['open']['action'] = $this->uri->create('admin/boards/add_new'); // panel for creating a new board $this->param_manager->setParam('method_title', [_i('Manage'), _i('Add')]); $this->builder->createPartial('body', 'form_creator')->getParamManager()->setParams($data); return new Response($this->builder->build()); }
public function action_profile() { if (!$this->getAuth()->hasAccess('maccess.user')) { return $this->redirectToLogin(); } $data = []; $form = []; $form['open'] = array('type' => 'open'); $form['paragraph'] = array('type' => 'paragraph', 'help' => _i('You can customize your account here.')); $form['paragraph-2'] = array('type' => 'paragraph', 'help' => '<img src="' . Gravatar::image($this->getAuth()->getUser()->getEmail()) . '" width="80" height="80" style="padding:2px; border: 1px solid #ccc;"/> ' . _i('Your avatar is automatically fetched from %s, based on your registration email.', '<a href="http://gravatar.com" target="_blank">Gravatar</a>')); $form['display_name'] = array('type' => 'input', 'database' => true, 'label' => _i('Display Name'), 'class' => 'span3', 'help' => _i('Alternative name in place of login username'), 'validation' => [new Trim(), new Assert\Length(['max' => 32])]); $form['bio'] = array('type' => 'textarea', 'database' => true, 'label' => 'Bio', 'style' => 'height:150px;', 'class' => 'span5', 'help' => _i('Some details about you'), 'validation' => [new Trim(), new Assert\Length(['max' => 360])]); $form['twitter'] = array('type' => 'input', 'database' => true, 'label' => 'Twitter', 'class' => 'span3', 'help' => _i('Your twitter nickname'), 'validation' => [new Trim(), new Assert\Length(['max' => 32])]); $form['submit'] = array('type' => 'submit', 'class' => 'btn btn-primary', 'value' => _i('Submit')); $form['close'] = array('type' => 'close'); $data['form'] = $form; if ($this->getPost() && !$this->security->checkCsrfToken($this->getRequest())) { $this->notices->set('warning', _i('The security token wasn\'t found. Try resubmitting.')); } elseif ($this->getPost()) { $result = Validator::formValidate($form, $this->getPost()); if (isset($result['error'])) { $this->notices->set('warning', $result['error']); } else { if (isset($result['warning'])) { $this->notices->set('warning', $result['warning']); } $this->notices->set('success', _i('Your profile has been updated.')); $user = $this->getAuth()->getUser(); $user->save($result['success']); } } $data['object'] = (object) $this->getAuth()->getUser(); // generate profile form $this->param_manager->setParam('method_title', _i('Profile')); $this->builder->createPartial('body', 'form_creator')->getParamManager()->setParams($data); return new Response($this->builder->build()); }
/** * A lazy way to submit the preference panel input, saves some code in controller * * This function runs the custom validation function that uses the $form array * to first run the original FuelPHP validation and then the anonymous * functions included in the $form array. It sets a proper notice for the * admin interface on conclusion. * * @param Request $request * @param array $form * @param bool|array $input If it evaluates to false, content won't be submitted */ public function submit_auto(Request $request, $form, $input = false) { if ($input) { $this->notices = $this->getContext()->getService('notices'); if (!$this->security->checkCsrfToken($request)) { $this->notices->set('warning', _i('The security token wasn\'t found. Try resubmitting.')); return; } $post = []; foreach ($input as $key => $item) { // PHP doesn't allow periods in POST array $post[str_replace(',', '.', $key)] = $item; } $result = Validator::formValidate($form, $post); if (isset($result['error'])) { $this->notices->set('warning', $result['error']); } else { if (isset($result['warning'])) { $this->notices->set('warning', $result['warning']); } $this->notices->set('success', _i('Preferences updated.')); $this->submit($result['success']); } } }
public function action_edit_release($id = 0) { if (!$id || !ctype_digit((string) $id)) { throw new NotFoundHttpException(); } try { $release_bulk = $this->release_factory->getById($id); } catch (SeriesNotFoundException $e) { throw new NotFoundHttpException(); } $data['object'] = $release_bulk->release; $data['form'] = $this->release_factory->getStructure(); if ($this->getPost() && !$this->checkCsrfToken()) { $this->notices->set('warning', _i('The security token was not found. Please try again.')); } elseif ($this->getPost()) { $result = Validator::formValidate($data['form'], $this->getPost()); if (isset($result['error'])) { $this->notices->set('warning', $result['error']); } else { // it's actually fully checked, we just have to throw it in DB $id = $this->release_factory->save($result['success']); return $this->redirect('admin/reader/edit_release/' . $id); } } $this->param_manager->setParam('method_title', _i('Edit series')); $this->builder->createPartial('body', 'form_creator')->getParamManager()->setParams($data); return new Response($this->builder->build()); }