Users and Settings

This commit is contained in:
Dan Cryer 2014-12-04 14:30:43 +00:00
parent cea124cfaa
commit 5f3b1c0c53
6 changed files with 127 additions and 60 deletions

View file

@ -13,6 +13,7 @@ use b8;
use b8\Form;
use b8\HttpClient;
use PHPCI\Controller;
use PHPCI\Helper\Lang;
use PHPCI\Model\Build;
use Symfony\Component\Yaml\Dumper;
use Symfony\Component\Yaml\Parser;
@ -40,7 +41,7 @@ class SettingsController extends Controller
{
$this->requireAdmin();
$this->layout->title = 'Settings';
$this->layout->title = Lang::get('settings');
$this->view->settings = $this->settings;
$emailSettings = array();
@ -173,7 +174,7 @@ class SettingsController extends Controller
$field = new Form\Element\Text('githubid');
$field->setRequired(true);
$field->setPattern('[a-zA-Z0-9]+');
$field->setLabel('Application ID');
$field->setLabel(Lang::get('application_id'));
$field->setClass('form-control');
$field->setContainerClass('form-group');
$form->addField($field);
@ -185,7 +186,7 @@ class SettingsController extends Controller
$field = new Form\Element\Text('githubsecret');
$field->setRequired(true);
$field->setPattern('[a-zA-Z0-9]+');
$field->setLabel('Application Secret');
$field->setLabel(Lang::get('application_secret'));
$field->setClass('form-control');
$field->setContainerClass('form-group');
$form->addField($field);
@ -195,7 +196,7 @@ class SettingsController extends Controller
}
$field = new Form\Element\Submit();
$field->setValue('Save »');
$field->setValue(Lang::get('save'));
$field->setClass('btn btn-success pull-right');
$form->addField($field);
@ -211,7 +212,7 @@ class SettingsController extends Controller
$field = new Form\Element\Text('smtp_address');
$field->setRequired(false);
$field->setLabel('SMTP Server');
$field->setLabel(Lang::get('smtp_server'));
$field->setClass('form-control');
$field->setContainerClass('form-group');
$field->setValue('localhost');
@ -220,7 +221,7 @@ class SettingsController extends Controller
$field = new Form\Element\Text('smtp_port');
$field->setRequired(false);
$field->setPattern('[0-9]+');
$field->setLabel('SMTP Port');
$field->setLabel(Lang::get('smtp_port'));
$field->setClass('form-control');
$field->setContainerClass('form-group');
$field->setValue(25);
@ -228,42 +229,42 @@ class SettingsController extends Controller
$field = new Form\Element\Text('smtp_username');
$field->setRequired(false);
$field->setLabel('SMTP Username');
$field->setLabel(Lang::get('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->setLabel(Lang::get('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->setLabel(Lang::get('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->setLabel(Lang::get('default_notification_address'));
$field->setClass('form-control');
$field->setContainerClass('form-group');
$form->addField($field);
$field = new Form\Element\Select('smtp_encryption');
$field->setOptions(['' => 'None', 'tls' => 'TLS', 'ssl' => 'SSL']);
$field->setOptions(['' => Lang::get('none'), 'tls' => Lang::get('tls'), 'ssl' => Lang::get('ssl')]);
$field->setRequired(false);
$field->setLabel('Use SMTP encryption?');
$field->setLabel(Lang::get('use_smtp_encryption'));
$field->setContainerClass('form-group');
$field->setValue(1);
$form->addField($field);
$field = new Form\Element\Submit();
$field->setValue('Save »');
$field->setValue(Lang::get('save'));
$field->setClass('btn btn-success pull-right');
$form->addField($field);
@ -293,22 +294,22 @@ class SettingsController extends Controller
$field = new Form\Element\Select('failed_after');
$field->setRequired(false);
$field->setLabel('Consider a build failed after');
$field->setLabel(Lang::get('failed_after'));
$field->setClass('form-control');
$field->setContainerClass('form-group');
$field->setOptions([
300 => '5 Minutes',
900 => '15 Minutes',
1800 => '30 Minutes',
3600 => '1 Hour',
10800 => '3 Hours',
300 => Lang::get('5_mins'),
900 => Lang::get('15_mins'),
1800 => Lang::get('30_mins'),
3600 => Lang::get('1_hour'),
10800 => Lang::get('3_hours'),
]);
$field->setValue(1800);
$form->addField($field);
$field = new Form\Element\Submit();
$field->setValue('Save »');
$field->setValue(Lang::get('save'));
$field->setClass('btn btn-success pull-right');
$form->addField($field);

View file

@ -14,6 +14,7 @@ use b8\Exception\HttpException\ForbiddenException;
use b8\Exception\HttpException\NotFoundException;
use b8\Form;
use PHPCI\Controller;
use PHPCI\Helper\Lang;
use PHPCI\Model\User;
use PHPCI\Service\UserService;
@ -49,7 +50,7 @@ class UserController extends Controller
$users = $this->userStore->getWhere(array(), 1000, 0, array(), array('email' => 'ASC'));
$this->view->users = $users;
$this->layout->title = 'Users';
$this->layout->title = Lang::get('manage_users');
return $this->view->render();
}
@ -58,7 +59,8 @@ class UserController extends Controller
{
$user = $_SESSION['phpci_user'];
$this->layout->title = 'Edit Profile';
$this->layout->title = $user->getName();
$this->layout->subtitle = Lang::get('edit_profile');
if ($this->request->getMethod() == 'POST') {
$name = $this->getParam('name', null);
@ -80,27 +82,27 @@ class UserController extends Controller
$name = new Form\Element\Text('name');
$name->setClass('form-control');
$name->setContainerClass('form-group');
$name->setLabel('Name');
$name->setLabel(Lang::get('name'));
$name->setRequired(true);
$form->addField($name);
$email = new Form\Element\Email('email');
$email->setClass('form-control');
$email->setContainerClass('form-group');
$email->setLabel('Email Address');
$email->setLabel(Lang::get('email_address'));
$email->setRequired(true);
$form->addField($email);
$password = new Form\Element\Password('password');
$password->setClass('form-control');
$password->setContainerClass('form-group');
$password->setLabel('Password (leave blank if you don\'t want to change it)');
$password->setLabel(Lang::get('password_change'));
$password->setRequired(false);
$form->addField($password);
$submit = new Form\Element\Submit();
$submit->setClass('btn btn-success');
$submit->setValue('Save »');
$submit->setValue(Lang::get('save'));
$form->addField($submit);
$form->setValues($values);
@ -117,7 +119,7 @@ class UserController extends Controller
{
$this->requireAdmin();
$this->layout->title = 'Add User';
$this->layout->title = Lang::get('add_user');
$method = $this->request->getMethod();
@ -161,11 +163,11 @@ class UserController extends Controller
$user = $this->userStore->getById($userId);
if (empty($user)) {
throw new NotFoundException('User with ID: ' . $userId . ' does not exist.');
throw new NotFoundException(Lang::get('user_n_not_found', $userId));
}
$this->layout->title = $user->getName();
$this->layout->subtitle = 'Edit User';
$this->layout->subtitle = Lang::get('edit_user');
$values = array_merge($user->getDataArray(), $this->getParams());
$form = $this->userForm($values, 'edit/' . $userId);
@ -202,14 +204,14 @@ class UserController extends Controller
$field = new Form\Element\Email('email');
$field->setRequired(true);
$field->setLabel('Email Address');
$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('Name');
$field->setLabel(Lang::get('name'));
$field->setClass('form-control');
$field->setContainerClass('form-group');
$form->addField($field);
@ -218,10 +220,10 @@ class UserController extends Controller
if ($type == 'add') {
$field->setRequired(true);
$field->setLabel('Password');
$field->setLabel(Lang::get('password'));
} else {
$field->setRequired(false);
$field->setLabel('Password (leave blank to keep current password)');
$field->setLabel(Lang::get('password_change'));
}
$field->setClass('form-control');
@ -231,12 +233,12 @@ class UserController extends Controller
$field = new Form\Element\Checkbox('is_admin');
$field->setRequired(false);
$field->setCheckedValue(1);
$field->setLabel('Is this user an administrator?');
$field->setLabel(Lang::get('is_user_admin'));
$field->setContainerClass('form-group');
$form->addField($field);
$field = new Form\Element\Submit();
$field->setValue('Save User');
$field->setValue(Lang::get('save_user'));
$field->setClass('btn-success');
$form->addField($field);
@ -254,7 +256,7 @@ class UserController extends Controller
$user = $this->userStore->getById($userId);
if (empty($user)) {
throw new NotFoundException('User with ID: ' . $userId . ' does not exist.');
throw new NotFoundException(Lang::get('user_n_not_found', $userId));
}
$this->userService->deleteUser($user);

View file

@ -198,4 +198,62 @@ PHPCI',
'build_created' => 'Build Created',
'build_started' => 'Build Started',
'build_finished' => 'Build Finished',
// Users
'name' => 'Name',
'password_change' => 'Password (leave blank if you don\'t want to change)',
'save' => 'Save »',
'update_your_details' => 'Update your details',
'your_details_updated' => 'Your details have been updated.',
'add_user' => 'Add User',
'is_admin' => 'Is Admin?',
'yes' => 'Yes',
'no' => 'No',
'edit' => 'Edit',
'edit_user' => 'Edit User',
'delete_user' => 'Delete User',
'user_n_not_found' => 'User with ID %d does not exist.',
'is_user_admin' => 'Is this user an administrator?',
'save_user' => 'Save User',
// Settings:
'settings_saved' => 'Your settings have been saved.',
'settings_check_perms' => 'Your settings could not be saved, check the permissions of your config.yml file.',
'settings_cannot_write' => 'PHPCI cannot write to your config.yml file, settings may not be saved properly
until this is rectified.',
'settings_github_linked' => 'Your Github account has been linked.',
'settings_github_not_linked' => 'Your Github account could not be linked.',
'build_settings' => 'Build Settings',
'github_application' => 'Github Application',
'github_sign_in' => 'Before you can start using Github, you need to <a href="%s">sign in</a> and grant
PHPCI access to your account.',
'github_phpci_linked' => 'PHPCI is successfully linked to Github account.',
'github_where_to_find' => 'Where to find these...',
'github_where_help' => 'If you own the application you would like to use, you can find this information within your
<a href="https://github.com/settings/applications">applications</a> settings area.',
'email_settings' => 'Email Settings',
'email_settings_help' => 'Before PHPCI can send build status emails,
you need to configure your SMTP settings below.',
'application_id' => 'Application ID',
'application_secret' => 'Application Secret',
'smtp_server' => 'SMTP Server',
'smtp_port' => 'SMTP Port',
'smtp_username' => 'SMTP Username',
'smtp_password' => 'SMTP Password',
'from_email_address' => 'From Email Address',
'default_notification_address' => 'Default Notification Email Address',
'use_smtp_encryption' => 'Use SMTP Encryption?',
'none' => 'None',
'ssl' => 'SSL',
'tls' => 'TLS',
'failed_after' => 'Consider a build failed after',
'5_mins' => '5 Minutes',
'15_mins' => '15 Minutes',
'30_mins' => '30 Minutes',
'1_hour' => '1 Hour',
'3_hours' => '3 Hours',
);

View file

@ -1,42 +1,44 @@
<?php use PHPCI\Helper\Lang; ?>
<?php if (isset($_GET['saved']) && $_GET['saved'] == 1): ?>
<p class="alert alert-success" style="margin-bottom: 20px;">
Your settings have been saved.
<?php Lang::out('settings_saved'); ?>
</p>
<?php endif; ?>
<?php if (isset($_GET['saved']) && $_GET['saved'] == 2): ?>
<p class="alert alert-danger" style="margin-bottom: 20px;">
Your settings could not be saved, maybe check the permissions of config.yml?
<?php Lang::out('settings_check_perms'); ?>
</p>
<?php endif; ?>
<?php if (!$isWriteable): ?>
<p class="alert alert-danger" style="margin-bottom: 20px;">
PHPCI cannot write to your config.yml file, settings may not be saved properly until this is rectified.
<?php Lang::out('settings_cannot_write'); ?>
</p>
<?php endif; ?>
<?php if (isset($_GET['linked']) && $_GET['linked'] == 1): ?>
<p class="alert alert-success" style="margin-bottom: 20px;">
Your Github account has been linked.
<?php Lang::out('settings_github_linked'); ?>
</p>
<?php endif; ?>
<?php if (isset($_GET['linked']) && $_GET['linked'] == 2): ?>
<p class="alert alert-danger" style="margin-bottom: 20px;">
Your Github account could not be linked.
<?php Lang::out('settings_github_not_linked'); ?>
</p>
<?php endif; ?>
<div class="box box-primary">
<div class="box-header"><h3 class="box-title">Build Settings</h3></div>
<div class="box-header"><h3 class="box-title"><?php Lang::out('build_settings'); ?></h3></div>
<div class="box-body clearfix">
<?php print $buildSettings; ?>
</div>
</div>
<div class="box box-primary">
<div class="box-header"><h3 class="box-title">Github Application</h3></div>
<div class="box-header"><h3 class="box-title"><?php Lang::out('github_application'); ?></h3></div>
<div class="box-body clearfix">
<div class="row">
@ -53,13 +55,14 @@
?>
<?php if (!empty($id) && empty($settings['phpci']['github']['token'])): ?>
<p class="alert alert-warning clearfix">
Before you can start using Github, you need to <a href="<?php echo $githubUri; ?>">sign in</a> and grant PHPCI access to your account.
<?php Lang::out('github_sign_in', $githubUri); ?>
</p>
<?php endif; ?>
<?php if (!empty($id) && !empty($settings['phpci']['github']['token'])): ?>
<p class="alert alert-success">
PHPCI is successfully linked to Github account
<?php Lang::out('github_phpci_linked'); ?>
<strong>
<a href="<?php echo $githubUser['html_url']; ?>"><?php echo $githubUser['name']; ?></a>
</strong>
@ -74,12 +77,13 @@
<div class="col-lg-4">
<div class="box box-info">
<div class="box-header">
<h3 class="box-title">Where to find these...</h3>
<h3 class="box-title"><?php Lang::out('github_where_to_find'); ?></h3>
</div>
<div class="box-body">
<p>If you own the application you would like to use, you can find this information within your
<a href="https://github.com/settings/applications">applications</a> settings area.</p>
<p>
<?php Lang::out('github_where_help'); ?>
</p>
</div>
</div>
</div>
@ -91,13 +95,13 @@
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">Email Settings</h3>
<h3 class="box-title"><?php Lang::out('email_settings'); ?></h3>
</div>
<div class="box-body clearfix">
<?php if (!isset($settings['phpci']['email_settings'])): ?>
<p class="alert alert-warning clearfix">
Before PHPCI can send build status emails, you need to configure your SMTP settings below.
<?php Lang::out('email_settings_help'); ?>
</p>
<?php endif; ?>

View file

@ -1,6 +1,7 @@
<?php use PHPCI\Helper\Lang; ?>
<div class="clearfix" style="margin-bottom: 20px;">
<div class="pull-right btn-group">
<a class="btn btn-primary" href="<?php print PHPCI_URL; ?>user/add">Add User</a>
<a class="btn btn-primary" href="<?php print PHPCI_URL; ?>user/add"><?php Lang::out('add_user'); ?></a>
</div>
</div>
@ -11,9 +12,9 @@
<table class="table">
<thead>
<tr>
<th>Email Address</th>
<th>Name</th>
<th>Administrator</th>
<th><?php Lang::out('email_address'); ?></th>
<th><?php Lang::out('name'); ?></th>
<th><?php Lang::out('is_admin'); ?></th>
<th style="width: 100px"></th>
</tr>
</thead>
@ -24,12 +25,12 @@
{
case 0:
$cls = '';
$status = 'No';
$status = Lang::get('no');
break;
case 1:
$cls = 'warning';
$status = 'Yes';
$status = Lang::get('yes');
break;
}
?>
@ -40,12 +41,12 @@
<td>
<?php if($this->User()->getIsAdmin()): ?>
<div class="btn-group">
<a class="btn btn-default btn-small" href="<?php echo PHPCI_URL ?>user/edit/<?php print $user->getId(); ?>">Edit</a>
<a class="btn btn-default btn-small" href="<?php echo PHPCI_URL ?>user/edit/<?php print $user->getId(); ?>"><?php Lang::out('edit'); ?></a>
<button class="btn btn-default btn-small dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="<?php echo PHPCI_URL ?>user/delete/<?php print $user->getId(); ?>" class="phpci-app-delete-user">Delete User</a></li>
<li><a href="<?php echo PHPCI_URL ?>user/delete/<?php print $user->getId(); ?>" class="phpci-app-delete-user"><?php Lang::out('delete_user'); ?></a></li>
</ul>
</div>
<?php endif; ?>

View file

@ -1,10 +1,11 @@
<?php use PHPCI\Helper\Lang; ?>
<?php if (isset($updated)): ?>
<p class="alert alert-success">Your details have been updated.</p>
<p class="alert alert-success"><?php Lang::out('your_details_updated'); ?></p>
<?php endif; ?>
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">Update your details</h3>
<h3 class="box-title"><?php Lang::out('update_your_details'); ?></h3>
</div>
<div class="box-body">
<?php print $form; ?>