Пример #1
0
 /**
  * Add or edit a project group.
  * @param null $groupId
  * @return void|b8\Http\Response\RedirectResponse
  */
 public function edit($groupId = null)
 {
     $this->requireAdmin();
     if (!is_null($groupId)) {
         $group = $this->groupStore->getById($groupId);
     } else {
         $group = new ProjectGroup();
     }
     if ($this->request->getMethod() == 'POST') {
         $group->setTitle($this->getParam('title'));
         $this->groupStore->save($group);
         $response = new b8\Http\Response\RedirectResponse();
         $response->setHeader('Location', PHPCI_URL . 'group');
         return $response;
     }
     $form = new Form();
     $form->setMethod('POST');
     $form->setAction(PHPCI_URL . 'group/edit' . (!is_null($groupId) ? '/' . $groupId : ''));
     $title = new Form\Element\Text('title');
     $title->setContainerClass('form-group');
     $title->setClass('form-control');
     $title->setLabel('Group Title');
     $title->setValue($group->getTitle());
     $submit = new Form\Element\Submit();
     $submit->setValue('Save Group');
     $form->addField($title);
     $form->addField($submit);
     $this->view->form = $form;
 }
Пример #2
0
 /**
  * Handles user login (form and processing)
  */
 public function login()
 {
     $isLoginFailure = false;
     if ($this->request->getMethod() == 'POST') {
         $token = $this->getParam('token');
         if (!isset($token, $_SESSION['login_token']) || $token !== $_SESSION['login_token']) {
             $isLoginFailure = true;
         } else {
             unset($_SESSION['login_token']);
             $user = $this->userStore->getByEmail($this->getParam('email'));
             if ($user && password_verify($this->getParam('password', ''), $user->getHash())) {
                 session_regenerate_id(true);
                 $_SESSION['phpci_user_id'] = $user->getId();
                 $response = new b8\Http\Response\RedirectResponse();
                 $response->setHeader('Location', $this->getLoginRedirect());
                 return $response;
             } else {
                 $isLoginFailure = true;
             }
         }
     }
     $form = new b8\Form();
     $form->setMethod('POST');
     $form->setAction(PHPCI_URL . 'session/login');
     $email = new b8\Form\Element\Email('email');
     $email->setLabel(Lang::get('email_address'));
     $email->setRequired(true);
     $email->setContainerClass('form-group');
     $email->setClass('form-control');
     $form->addField($email);
     $pwd = new b8\Form\Element\Password('password');
     $pwd->setLabel(Lang::get('password'));
     $pwd->setRequired(true);
     $pwd->setContainerClass('form-group');
     $pwd->setClass('form-control');
     $form->addField($pwd);
     $pwd = new b8\Form\Element\Submit();
     $pwd->setValue(Lang::get('log_in'));
     $pwd->setClass('btn-success');
     $form->addField($pwd);
     $tokenValue = $this->generateToken();
     $_SESSION['login_token'] = $tokenValue;
     $token = new b8\Form\Element\Hidden('token');
     $token->setValue($tokenValue);
     $form->addField($token);
     $this->view->form = $form->render();
     $this->view->failed = $isLoginFailure;
     return $this->view->render();
 }
Пример #3
0
 public function getLoginForm($returnUrl = null)
 {
     $form = new Form();
     $form->setMethod('POST');
     $form->setAction('/member/login');
     $form->disableValidation();
     if (!is_null($returnUrl)) {
         $rtn = new Hidden();
         $rtn->setName('rtn');
         $rtn->setValue($returnUrl);
         $form->addField($rtn);
     }
     $form->addField(Email::create('email', 'Email Address', true));
     $form->addField(Password::create('password', 'Password', true));
     $submit = new Submit();
     $submit->setClass('button pull-right');
     $submit->setValue('Login');
     $form->addField($submit);
     return $form;
 }
Пример #4
0
 /**
  * Handles user login (form and processing)
  */
 public function login()
 {
     $isLoginFailure = false;
     if ($this->request->getMethod() == 'POST') {
         $user = $this->userStore->getByEmail($this->getParam('email'));
         if ($user && password_verify($this->getParam('password', ''), $user->getHash())) {
             $_SESSION['user_id'] = $user->getId();
             header('Location: ' . $this->getLoginRedirect());
             die;
         } else {
             $isLoginFailure = true;
         }
     }
     $form = new b8\Form();
     $form->setMethod('POST');
     $form->setAction(PHPCI_URL . 'session/login');
     $email = new b8\Form\Element\Email('email');
     $email->setLabel('Email Address');
     $email->setRequired(true);
     $email->setContainerClass('form-group');
     $email->setClass('form-control');
     $form->addField($email);
     $pwd = new b8\Form\Element\Password('password');
     $pwd->setLabel('Password');
     $pwd->setRequired(true);
     $pwd->setContainerClass('form-group');
     $pwd->setClass('form-control');
     $form->addField($pwd);
     $pwd = new b8\Form\Element\Submit();
     $pwd->setValue('Log in »');
     $pwd->setClass('btn-success');
     $form->addField($pwd);
     $this->view->form = $form->render();
     $this->view->failed = $isLoginFailure;
     return $this->view->render();
 }
Пример #5
0
 protected function contactForm()
 {
     $form = new \Octo\Admin\Form();
     $form->addField(Form\Element\Text::create('first_name', 'First Name', true));
     $form->addField(Form\Element\Text::create('last_name', 'Last Name', true));
     $form->addField(Form\Element\Email::create('email', 'Email Address', true));
     $form->addField(Form\Element\Text::create('phone', 'Phone Number'));
     $form->addField(Form\Element\Text::create('company', 'Company'));
     $form->addField(Form\Element\Submit::create('submit', 'Save')->setValue('Save Contact'));
     return $form;
 }
Пример #6
0
 public function testElements()
 {
     $e = new Form\Element\Button();
     $this->assertTrue($e->validate());
     $this->assertTrue(strpos($e->render(), 'button') !== false);
     $e = new Form\Element\Checkbox();
     $e->setCheckedValue('ten');
     $this->assertTrue($e->getCheckedValue() == 'ten');
     $this->assertTrue(strpos($e->render(), 'checkbox') !== false);
     $this->assertTrue(strpos($e->render(), 'checked') === false);
     $e->setValue(true);
     $this->assertTrue(strpos($e->render(), 'checked') !== false);
     $e->setValue('ten');
     $this->assertTrue(strpos($e->render(), 'checked') !== false);
     $e->setValue('fail');
     $this->assertTrue(strpos($e->render(), 'checked') === false);
     $e = new Form\Element\CheckboxGroup();
     $this->assertTrue(strpos($e->render(), 'group') !== false);
     $e = new Form\ControlGroup();
     $this->assertTrue(strpos($e->render(), 'group') !== false);
     $e = new Form\Element\Email();
     $this->assertTrue(strpos($e->render(), 'email') !== false);
     $e = new Form\Element\Select();
     $e->setOptions(array('key' => 'Val'));
     $html = $e->render();
     $this->assertTrue(strpos($html, 'select') !== false);
     $this->assertTrue(strpos($html, 'option') !== false);
     $this->assertTrue(strpos($html, 'key') !== false);
     $this->assertTrue(strpos($html, 'Val') !== false);
     $e = new Form\Element\Submit();
     $this->assertTrue($e->validate());
     $this->assertTrue(strpos($e->render(), 'submit') !== false);
     $e = new Form\Element\Text();
     $e->setValue('test');
     $this->assertTrue(strpos($e->render(), 'test') !== false);
     $e = new Form\Element\TextArea();
     $e->setRows(10);
     $this->assertTrue(strpos($e->render(), '10') !== false);
     $e = new Form\Element\Url();
     $this->assertTrue(strpos($e->render(), 'url') !== false);
 }
Пример #7
0
 protected function resetPasswordForm($memberId, $key)
 {
     $form = new Form();
     $form->setMethod('POST');
     $form->setAction('/member/reset-password/' . $memberId);
     $form->enableValidation();
     $form->addField(Hidden::create('k', 'Key', true));
     $form->addField(Password::create('password', 'Your New Password', true));
     $submit = new Submit();
     $submit->setClass('button pull-right');
     $submit->setValue('Reset and Login');
     $form->setValues(['k' => $key]);
     $form->addField($submit);
     return $form;
 }
Пример #8
0
 /**
  * Create add / edit project form.
  */
 protected function projectForm($values, $type = 'add')
 {
     $form = new Form();
     $form->setMethod('POST');
     $form->setAction(PHPCI_URL . 'project/' . $type);
     $form->addField(new Form\Element\Csrf('csrf'));
     $form->addField(new Form\Element\Hidden('pubkey'));
     $options = array('choose' => Lang::get('select_repository_type'), 'github' => Lang::get('github'), 'bitbucket' => Lang::get('bitbucket'), 'gitlab' => Lang::get('gitlab'), 'remote' => Lang::get('remote'), 'local' => Lang::get('local'), 'hg' => Lang::get('hg'), 'svn' => Lang::get('svn'));
     $field = Form\Element\Select::create('type', Lang::get('where_hosted'), true);
     $field->setPattern('^(github|bitbucket|gitlab|remote|local|hg|svn)');
     $field->setOptions($options);
     $field->setClass('form-control')->setContainerClass('form-group');
     $form->addField($field);
     $container = new Form\ControlGroup('github-container');
     $container->setClass('github-container');
     $field = Form\Element\Select::create('github', Lang::get('choose_github'), false);
     $field->setClass('form-control')->setContainerClass('form-group');
     $container->addField($field);
     $form->addField($container);
     $field = Form\Element\Text::create('reference', Lang::get('repo_name'), true);
     $field->setValidator($this->getReferenceValidator($values));
     $field->setClass('form-control')->setContainerClass('form-group');
     $form->addField($field);
     $field = Form\Element\Text::create('title', Lang::get('project_title'), true);
     $field->setClass('form-control')->setContainerClass('form-group');
     $form->addField($field);
     $field = Form\Element\TextArea::create('key', Lang::get('project_private_key'), false);
     $field->setClass('form-control')->setContainerClass('form-group');
     $field->setRows(6);
     $form->addField($field);
     $field = Form\Element\TextArea::create('build_config', Lang::get('build_config'), false);
     $field->setClass('form-control')->setContainerClass('form-group');
     $field->setRows(6);
     $form->addField($field);
     $field = Form\Element\Text::create('branch', Lang::get('default_branch'), true);
     $field->setClass('form-control')->setContainerClass('form-group')->setValue('master');
     $form->addField($field);
     $field = Form\Element\Select::create('group_id', 'Project Group', true);
     $field->setClass('form-control')->setContainerClass('form-group')->setValue(1);
     $groups = array();
     $groupStore = b8\Store\Factory::getStore('ProjectGroup');
     $groupList = $groupStore->getWhere(array(), 100, 0, array(), array('title' => 'ASC'));
     foreach ($groupList['items'] as $group) {
         $groups[$group->getId()] = $group->getTitle();
     }
     $field->setOptions($groups);
     $form->addField($field);
     $field = Form\Element\Checkbox::create('allow_public_status', Lang::get('allow_public_status'), false);
     $field->setContainerClass('form-group');
     $field->setCheckedValue(1);
     $field->setValue(0);
     $form->addField($field);
     $field = Form\Element\Checkbox::create('archived', Lang::get('archived'), false);
     $field->setContainerClass('form-group');
     $field->setCheckedValue(1);
     $field->setValue(0);
     $form->addField($field);
     $field = new Form\Element\Submit();
     $field->setValue(Lang::get('save_project'));
     $field->setContainerClass('form-group');
     $field->setClass('btn-success');
     $form->addField($field);
     $form->setValues($values);
     return $form;
 }
 protected function settingsForm($values)
 {
     $form = new FormElement();
     $form->setMethod('POST');
     $fieldset = new FieldSet();
     $fieldset->setId('oauth');
     $fieldset->setLabel('OAuth Details');
     $form->addField($fieldset);
     $fieldset->addField(Text::create('client_id', 'Client ID'));
     $fieldset->addField(Text::create('client_secret', 'Client Secret'));
     if (!empty($values['client_id']) && !empty($values['client_secret'])) {
         $fieldset = new FieldSet();
         $fieldset->setId('login');
         $fieldset->setLabel('Google Login');
         $form->addField($fieldset);
         $fieldset->addField(OnOffSwitch::create('login_enabled', 'Enable Google Login?', false));
         $fieldset->addField(Text::create('login_auto_create', 'Auto-approved login domains:'));
     }
     $submit = new Submit();
     $submit->setValue('Save Settings');
     $form->addField($submit);
     return $form;
 }
Пример #10
0
 public function profile()
 {
     if ($this->getRequest()->getMethod() == 'POST') {
         $this->currentUser->setEmail($this->getParam('email'));
         $this->currentUser->setName($this->getParam('name'));
         $password = $this->getParam('password', '');
         if (!empty($password)) {
             $this->currentUser->setHash(password_hash($password, PASSWORD_DEFAULT));
         }
         $this->currentUser = $this->userStore->save($this->currentUser);
         $this->successMessage('Profile updated successfully!');
     }
     $this->setTitle($this->currentUser->getName(), 'Edit Profile');
     $form = new \Octo\Admin\Form();
     $form->setMethod('POST');
     $name = Form\Element\Text::create('name', 'Name', true);
     $name->setValue($this->currentUser->getName());
     $email = Form\Element\Email::create('email', 'Email Address', true);
     $email->setValue($this->currentUser->getEmail());
     $password = Form\Element\Password::create('password', 'Password (enter a new password to change)', false);
     $submit = new Form\Element\Submit();
     $submit->setValue('Update Profile');
     $submit->setClass('btn btn-success');
     $form->addField($name);
     $form->addField($email);
     $form->addField($password);
     $form->addField($submit);
     $this->view->form = $form;
 }
Пример #11
0
 /**
  * Form for disabling user authentication while using a default user
  *
  * @param array $values
  * @return Form
  */
 protected function getAuthenticationForm($values = array())
 {
     $form = new Form();
     $form->setMethod('POST');
     $form->setAction(PHPCI_URL . 'settings/authentication');
     $form->addField(new Form\Element\Csrf('csrf'));
     $field = new Form\Element\Checkbox('disable_authentication');
     $field->setCheckedValue(1);
     $field->setRequired(false);
     $field->setLabel('Disable Authentication?');
     $field->setContainerClass('form-group');
     $field->setValue(0);
     if (isset($values['state'])) {
         $field->setValue((int) $values['state']);
     }
     $form->addField($field);
     $field = new Form\Element\Submit();
     $field->setValue('Save »');
     $field->setClass('btn btn-success pull-right');
     $form->addField($field);
     $form->setValues($values);
     return $form;
 }
Пример #12
0
 /**
  * Create user add / edit form.
  */
 protected function userForm($values, $type = 'add')
 {
     $form = new Form();
     $form->setMethod('POST');
     $form->setAction(PHPCI_URL . 'user/' . $type);
     $form->addField(new Form\Element\Csrf('csrf'));
     $field = new Form\Element\Email('email');
     $field->setRequired(true);
     $field->setLabel(Lang::get('email_address'));
     $field->setClass('form-control');
     $field->setContainerClass('form-group');
     $form->addField($field);
     $field = new Form\Element\Text('name');
     $field->setRequired(true);
     $field->setLabel(Lang::get('name'));
     $field->setClass('form-control');
     $field->setContainerClass('form-group');
     $form->addField($field);
     $field = new Form\Element\Password('password');
     if ($type == 'add') {
         $field->setRequired(true);
         $field->setLabel(Lang::get('password'));
     } else {
         $field->setRequired(false);
         $field->setLabel(Lang::get('password_change'));
     }
     $field->setClass('form-control');
     $field->setContainerClass('form-group');
     $form->addField($field);
     $field = new Form\Element\Checkbox('is_admin');
     $field->setRequired(false);
     $field->setCheckedValue(1);
     $field->setLabel(Lang::get('is_user_admin'));
     $field->setContainerClass('form-group');
     $form->addField($field);
     $field = new Form\Element\Submit();
     $field->setValue(Lang::get('save_user'));
     $field->setClass('btn-success');
     $form->addField($field);
     $form->setValues($values);
     return $form;
 }
Пример #13
0
 /**
  * Create user add / edit form.
  */
 protected function userForm($values, $type = 'add')
 {
     $form = new Form();
     $form->setMethod('POST');
     $form->setAction(PHPCI_URL . 'user/' . $type);
     $form->addField(new Form\Element\Csrf('csrf'));
     $field = new Form\Element\Email('email');
     $field->setRequired(true);
     $field->setLabel('Email Address');
     $field->setClass('form-control');
     $field->setContainerClass('form-group');
     $form->addField($field);
     $field = new Form\Element\Text('name');
     $field->setRequired(true);
     $field->setLabel('Name');
     $field->setClass('form-control');
     $field->setContainerClass('form-group');
     $form->addField($field);
     $field = new Form\Element\Password('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);
     $field = new Form\Element\Checkbox('is_admin');
     $field->setRequired(false);
     $field->setCheckedValue(1);
     $field->setLabel('Is this user an administrator?');
     $field->setContainerClass('form-group');
     $form->addField($field);
     $field = new Form\Element\Submit();
     $field->setValue('Save User');
     $field->setClass('btn-success');
     $form->addField($field);
     $form->setValues($values);
     return $form;
 }
Пример #14
0
 /**
  * Create add / edit project form.
  */
 protected function projectForm($values, $type = 'add')
 {
     $form = new Form();
     $form->setMethod('POST');
     $form->setAction(PHPCI_URL . 'project/' . $type);
     $form->addField(new Form\Element\Csrf('csrf'));
     $form->addField(new Form\Element\Hidden('pubkey'));
     $options = array('choose' => 'Select repository type...', 'github' => 'Github', 'bitbucket' => 'Bitbucket', 'gitlab' => 'Gitlab', 'remote' => 'Remote URL', 'local' => 'Local Path', 'hg' => 'Mercurial');
     $field = Form\Element\Select::create('type', 'Where is your project hosted?', true);
     $field->setPattern('^(github|bitbucket|gitlab|remote|local|hg)');
     $field->setOptions($options);
     $field->setClass('form-control')->setContainerClass('form-group');
     $form->addField($field);
     $container = new Form\ControlGroup('github-container');
     $container->setClass('github-container');
     $field = Form\Element\Select::create('github', 'Choose a Github repository:', false);
     $field->setClass('form-control')->setContainerClass('form-group');
     $container->addField($field);
     $form->addField($container);
     $field = Form\Element\Text::create('reference', 'Repository Name / URL (Remote) or Path (Local)', true);
     $field->setValidator($this->getReferenceValidator($values));
     $field->setClass('form-control')->setContainerClass('form-group');
     $form->addField($field);
     $field = Form\Element\Text::create('title', 'Project Title', true);
     $field->setClass('form-control')->setContainerClass('form-group');
     $form->addField($field);
     $title = 'Private key to use to access repository (leave blank for local and/or anonymous remotes)';
     $field = Form\Element\TextArea::create('key', $title, false);
     $field->setClass('form-control')->setContainerClass('form-group');
     $field->setRows(6);
     $form->addField($field);
     $label = 'PHPCI build config for this project (if you cannot add a phpci.yml file in the project repository)';
     $field = Form\Element\TextArea::create('build_config', $label, false);
     $field->setClass('form-control')->setContainerClass('form-group');
     $field->setRows(6);
     $form->addField($field);
     $field = Form\Element\Text::create('branch', 'Default branch name', true);
     $field->setValidator($this->getReferenceValidator($values));
     $field->setClass('form-control')->setContainerClass('form-group')->setValue('master');
     $form->addField($field);
     $label = 'Enable public status page and image for this project?';
     $field = Form\Element\Checkbox::create('allow_public_status', $label, false);
     $field->setContainerClass('form-group');
     $field->setCheckedValue(1);
     $field->setValue(1);
     $form->addField($field);
     $field = new Form\Element\Submit();
     $field->setValue('Save Project');
     $field->setContainerClass('form-group');
     $field->setClass('btn-success');
     $form->addField($field);
     $form->setValues($values);
     return $form;
 }
Пример #15
0
 protected function getEmailForm($values = array())
 {
     $form = new Form();
     $form->setMethod('POST');
     $form->setAction(PHPCI_URL . 'settings/email');
     $form->addField(new Form\Element\Csrf('csrf'));
     $field = new Form\Element\Text('smtp_address');
     $field->setRequired(false);
     $field->setLabel('SMTP Server');
     $field->setClass('form-control');
     $field->setContainerClass('form-group');
     $field->setValue('localhost');
     $form->addField($field);
     $field = new Form\Element\Text('smtp_port');
     $field->setRequired(false);
     $field->setPattern('[0-9]+');
     $field->setLabel('SMTP Port');
     $field->setClass('form-control');
     $field->setContainerClass('form-group');
     $field->setValue(25);
     $form->addField($field);
     $field = new Form\Element\Text('smtp_username');
     $field->setRequired(false);
     $field->setLabel('SMTP Username');
     $field->setClass('form-control');
     $field->setContainerClass('form-group');
     $form->addField($field);
     $field = new Form\Element\Text('smtp_password');
     $field->setRequired(false);
     $field->setLabel('SMTP Password');
     $field->setClass('form-control');
     $field->setContainerClass('form-group');
     $form->addField($field);
     $field = new Form\Element\Email('from_address');
     $field->setRequired(false);
     $field->setLabel('From Email Address');
     $field->setClass('form-control');
     $field->setContainerClass('form-group');
     $form->addField($field);
     $field = new Form\Element\Email('default_mailto_address');
     $field->setRequired(false);
     $field->setLabel('Default Notification Address');
     $field->setClass('form-control');
     $field->setContainerClass('form-group');
     $form->addField($field);
     $field = new Form\Element\Checkbox('smtp_encryption');
     $field->setCheckedValue(1);
     $field->setRequired(false);
     $field->setLabel('Use SMTP encryption?');
     $field->setContainerClass('form-group');
     $field->setValue(1);
     $form->addField($field);
     $field = new Form\Element\Submit();
     $field->setValue('Save »');
     $field->setClass('btn btn-success pull-right');
     $form->addField($field);
     $form->setValues($values);
     return $form;
 }