/** * 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_create_admin() { // if an admin account exists, lock down this step and redirect to the next step instead /** @var Users $users */ $users = $this->getContext()->getService('users'); $check_users = $users->getAll(); if ($check_users['count'] > 0) { return new RedirectResponse($this->uri->create('install/modules')); } if ($this->getPost()) { $validator = new Validator(); $validator->add('username', _i('Username'), [new Trim(), new Assert\NotBlank(), new Assert\Length(['min' => 4, 'max' => 32])])->add('email', _i('Email'), [new Trim(), new Assert\NotBlank(), new Assert\Email()])->add('password', _i('Password'), [new Trim(), new Assert\NotBlank(), new Assert\Length(['min' => 4, 'max' => 64])])->add('confirm_password', _i('Confirm Password'), [new EqualsField(['field' => _i('Password'), 'value' => $this->getPost('password')])]); $validator->validate($this->getPost()); if (!$validator->getViolations()->count()) { $input = $validator->getFinalValues(); $auth = new Auth($this->getContext()); list($id, $activation_key) = $auth->createUser($input['username'], $input['password'], $input['email']); $auth->activateUser($id, $activation_key); $auth->authenticateWithId($id); $user = $auth->getUser(); $user->save(['group_id' => 100]); // leave the module installation later in case we must do something with users $this->install->install_modules(); return new RedirectResponse($this->uri->create('install/complete')); } else { $this->notices->set('warning', $validator->getViolations()->getText()); } } $this->process('create_admin'); $this->param_manager->setParam('method_title', _i('Admin Account')); $this->builder->createPartial('body', 'install/create_admin'); return new Response($this->builder->build()); }