2010-04-22 16:26:41 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Michael Tänzer
|
|
|
|
*/
|
|
|
|
|
2010-06-28 15:30:31 +00:00
|
|
|
class ManageAccountController extends Zend_Controller_Action
|
2010-04-22 16:26:41 +00:00
|
|
|
{
|
2010-04-29 13:27:33 +00:00
|
|
|
const MAX_POINTS_PER_ASSURANCE = 35;
|
2010-06-29 18:00:03 +00:00
|
|
|
const MAX_POINTS_TOTAL = 150;
|
|
|
|
const ADMIN_INCREASE_FRAGMENT_SIZE = 2;
|
|
|
|
|
|
|
|
// Value used in the database to identify a admin increase
|
|
|
|
const ADMIN_INCREASE_METHOD = 'Administrative Increase';
|
2010-04-29 13:27:33 +00:00
|
|
|
|
|
|
|
protected $db;
|
|
|
|
|
2010-04-22 16:26:41 +00:00
|
|
|
public function init()
|
|
|
|
{
|
2010-04-29 13:27:33 +00:00
|
|
|
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini',
|
|
|
|
APPLICATION_ENV);
|
|
|
|
|
|
|
|
$this->db = Zend_Db::factory($config->ca_mgr->db->auth->pdo,
|
2010-07-01 17:58:45 +00:00
|
|
|
$config->ca_mgr->db->auth);
|
|
|
|
|
|
|
|
// Build the left navigation
|
|
|
|
$actions = array();
|
|
|
|
$actions['assurance'] = I18n::_('Automated Assurance');
|
|
|
|
$actions['admin-increase'] = I18n::_('Administrative Increase');
|
|
|
|
$actions['assurer-challenge'] = I18n::_('Assurer Challenge');
|
2010-07-06 16:16:10 +00:00
|
|
|
$actions['flags'] = I18n::_('Set Flags');
|
2010-07-01 17:58:45 +00:00
|
|
|
$url = array('controller' => 'manage-account');
|
|
|
|
foreach ($actions as $action => $label) {
|
|
|
|
$url['action'] = $action;
|
|
|
|
$link = '<a href="'.$this->view->url($url, 'default', true).'">'.
|
|
|
|
$label . '</a>';
|
|
|
|
$this->view->leftNav($link);
|
|
|
|
}
|
|
|
|
|
2010-04-22 16:26:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function indexAction()
|
|
|
|
{
|
2010-06-28 14:13:14 +00:00
|
|
|
// Just render the view
|
|
|
|
return;
|
2010-04-26 18:57:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function assuranceAction()
|
|
|
|
{
|
2010-04-29 13:27:33 +00:00
|
|
|
// Validate form
|
2010-04-26 18:57:27 +00:00
|
|
|
$form = $this->getAssuranceForm();
|
2010-06-28 14:13:14 +00:00
|
|
|
if (!$this->getRequest()->isPost() || !$form->isValid($_POST)) {
|
2010-04-26 18:57:27 +00:00
|
|
|
$this->view->assurance_form = $form;
|
2010-06-28 14:13:14 +00:00
|
|
|
return $this->render('assuranceform');
|
2010-04-26 18:57:27 +00:00
|
|
|
}
|
|
|
|
|
2010-04-29 13:27:33 +00:00
|
|
|
// Form is valid -> get values for processing
|
2010-04-26 18:57:27 +00:00
|
|
|
$values = $form->getValues();
|
2010-04-29 13:27:33 +00:00
|
|
|
|
2011-06-20 11:41:52 +00:00
|
|
|
// Get the current user
|
2011-06-20 21:08:08 +00:00
|
|
|
$user = Default_Model_User::findCurrentUser();
|
2010-04-29 13:27:33 +00:00
|
|
|
|
|
|
|
$this->view->assurancesDone = array();
|
2010-04-29 19:18:14 +00:00
|
|
|
$quantity = $values['quantity'];
|
2010-04-29 13:27:33 +00:00
|
|
|
do {
|
|
|
|
// split up into multiple assurances
|
2010-04-29 19:18:14 +00:00
|
|
|
if ($quantity > self::MAX_POINTS_PER_ASSURANCE) {
|
2011-06-20 11:41:52 +00:00
|
|
|
$points = self::MAX_POINTS_PER_ASSURANCE;
|
2010-04-29 19:18:14 +00:00
|
|
|
$quantity -= self::MAX_POINTS_PER_ASSURANCE;
|
2010-04-29 13:27:33 +00:00
|
|
|
} else {
|
2011-06-20 11:41:52 +00:00
|
|
|
$points = $quantity;
|
2010-04-29 19:18:14 +00:00
|
|
|
$quantity = 0;
|
2010-04-29 13:27:33 +00:00
|
|
|
}
|
|
|
|
|
2010-04-29 19:21:47 +00:00
|
|
|
// Get the assurer for this assurance
|
2011-06-20 11:41:52 +00:00
|
|
|
$issued = $user->findNewAssurer()
|
|
|
|
->assure($user, $points, $values['location'], $values['date']);
|
2010-08-03 19:19:05 +00:00
|
|
|
|
2011-06-20 11:41:52 +00:00
|
|
|
$this->view->assurancesDone[] = $issued;
|
2010-04-29 19:18:14 +00:00
|
|
|
} while ($quantity > 0);
|
2010-04-29 13:27:33 +00:00
|
|
|
|
|
|
|
return;
|
2010-04-26 18:57:27 +00:00
|
|
|
}
|
|
|
|
|
2010-06-29 18:00:03 +00:00
|
|
|
public function adminIncreaseAction()
|
|
|
|
{
|
|
|
|
// Validate form
|
|
|
|
$form = $this->getAdminIncreaseForm();
|
|
|
|
if (!$this->getRequest()->isPost() || !$form->isValid($_POST)) {
|
|
|
|
$this->view->admin_increase_form = $form;
|
|
|
|
return $this->render('admin-increase-form');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Form is valid -> get values for processing
|
|
|
|
$values = $form->getValues();
|
|
|
|
|
2011-06-28 18:11:03 +00:00
|
|
|
// Get current user
|
2011-06-27 23:20:56 +00:00
|
|
|
$user = Default_Model_User::findCurrentUser();
|
2010-06-29 18:00:03 +00:00
|
|
|
|
|
|
|
$this->view->adminIncreasesDone = array();
|
2011-06-28 10:36:55 +00:00
|
|
|
$points = $values['points'];
|
|
|
|
|
|
|
|
// Only assign points within the limit if unlimited flag is not set
|
|
|
|
if ($values['unlimited'] != '1') {
|
|
|
|
if ($user->getPoints() >= self::MAX_POINTS_TOTAL) {
|
|
|
|
// No more administrative increases should be done
|
|
|
|
return;
|
|
|
|
} elseif ($user->getPoints() + $points > self::MAX_POINTS_TOTAL) {
|
|
|
|
$points = self::MAX_POINTS_TOTAL - $user->getPoints();
|
2010-06-29 18:00:03 +00:00
|
|
|
}
|
2011-06-28 10:36:55 +00:00
|
|
|
}
|
2010-06-29 18:00:03 +00:00
|
|
|
|
2011-06-28 10:36:55 +00:00
|
|
|
$user->adminIncrease($points, $values['location'], $values['date']);
|
|
|
|
$this->view->adminIncreasesDone[] = $points;
|
|
|
|
|
2010-06-29 18:00:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-01 16:52:43 +00:00
|
|
|
|
|
|
|
public function assurerChallengeAction()
|
|
|
|
{
|
|
|
|
// Validate form
|
|
|
|
$form = $this->getAssurerChallengeForm();
|
|
|
|
if (!$this->getRequest()->isPost() || !$form->isValid($_POST)) {
|
|
|
|
$this->view->assurer_challenge_form = $form;
|
|
|
|
return $this->render('assurer-challenge-form');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Form is valid -> get values for processing
|
|
|
|
$values = $form->getValues();
|
|
|
|
|
|
|
|
// Get user data
|
2011-06-28 18:11:03 +00:00
|
|
|
$user = Default_Model_User::findCurrentUser();
|
2010-07-01 16:52:43 +00:00
|
|
|
|
2011-06-28 18:11:03 +00:00
|
|
|
$user->assignChallenge(1, $values['variant']);
|
2010-07-01 16:52:43 +00:00
|
|
|
}
|
|
|
|
|
2010-07-06 16:16:10 +00:00
|
|
|
public function flagsAction()
|
|
|
|
{
|
2011-06-30 19:48:35 +00:00
|
|
|
$user = Default_Model_User::findCurrentUser();
|
2010-07-06 16:16:10 +00:00
|
|
|
|
|
|
|
// Validate form
|
2011-06-30 19:48:35 +00:00
|
|
|
$form = $this->getFlagsForm($user);
|
2010-07-06 16:16:10 +00:00
|
|
|
$this->view->flags_form = $form;
|
|
|
|
if (!$this->getRequest()->isPost() || !$form->isValid($_POST)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-30 19:48:35 +00:00
|
|
|
$flags = $user->getFlags();
|
|
|
|
foreach ($flags as $flag => $value) {
|
|
|
|
$element = $form->getElement($flag);
|
|
|
|
if ($element !== null) {
|
|
|
|
$flags[$flag] = $element->isChecked();
|
2010-07-06 16:16:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-30 19:48:35 +00:00
|
|
|
$user->setFlags($flags);
|
2010-07-06 16:16:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-26 18:57:27 +00:00
|
|
|
protected function getAssuranceForm()
|
|
|
|
{
|
|
|
|
$form = new Zend_Form();
|
2010-06-28 16:25:07 +00:00
|
|
|
$form->setAction('/manage-account/assurance')->setMethod('post');
|
2010-04-26 18:57:27 +00:00
|
|
|
|
|
|
|
$quantity = new Zend_Form_Element_Text('quantity');
|
|
|
|
$quantity->setRequired(true)
|
|
|
|
->setLabel(I18n::_('Number of Points'))
|
|
|
|
->addFilter(new Zend_Filter_Int())
|
|
|
|
->addValidator(new Zend_Validate_Between(0, 100));
|
|
|
|
$form->addElement($quantity);
|
|
|
|
|
2010-04-29 13:27:33 +00:00
|
|
|
$location = new Zend_Form_Element_Text('location');
|
|
|
|
$location->setRequired(true)
|
|
|
|
->setLabel(I18n::_('Location'))
|
2010-05-14 09:42:57 +00:00
|
|
|
->setValue(I18n::_('CAcert Test Manager'))
|
2010-04-29 13:27:33 +00:00
|
|
|
->addValidator(new Zend_Validate_StringLength(1,255));
|
|
|
|
$form->addElement($location);
|
|
|
|
|
|
|
|
$date = new Zend_Form_Element_Text('date');
|
|
|
|
$date->setRequired(true)
|
|
|
|
->setLabel(I18n::_('Date of Assurance'))
|
|
|
|
->setValue(date('Y-m-d H:i:s'))
|
|
|
|
->addValidator(new Zend_Validate_StringLength(1,255));
|
|
|
|
$form->addElement($date);
|
|
|
|
|
2010-04-26 18:57:27 +00:00
|
|
|
$submit = new Zend_Form_Element_Submit('submit');
|
|
|
|
$submit->setLabel(I18n::_('Assure Me'));
|
|
|
|
$form->addElement($submit);
|
|
|
|
|
|
|
|
return $form;
|
2010-04-22 16:26:41 +00:00
|
|
|
}
|
2010-06-28 18:06:01 +00:00
|
|
|
|
|
|
|
protected function getAdminIncreaseForm()
|
|
|
|
{
|
|
|
|
$form = new Zend_Form();
|
|
|
|
$form->setAction('/manage-account/admin-increase')->setMethod('post');
|
|
|
|
|
2011-06-28 10:36:55 +00:00
|
|
|
$points = new Zend_Form_Element_Text('points');
|
|
|
|
$points->setRequired(true)
|
2010-06-28 18:06:01 +00:00
|
|
|
->setLabel(I18n::_('Number of Points'))
|
|
|
|
->addFilter(new Zend_Filter_Int())
|
|
|
|
->addValidator(new Zend_Validate_GreaterThan(0));
|
2011-06-28 10:36:55 +00:00
|
|
|
$form->addElement($points);
|
2010-06-28 18:06:01 +00:00
|
|
|
|
|
|
|
$unlimited = new Zend_Form_Element_Checkbox('unlimited');
|
|
|
|
$unlimited->setLabel(I18n::_('Assign Points even if the Limit of 150 '.
|
|
|
|
'is exceeded'))
|
|
|
|
->setChecked(false);
|
|
|
|
$form->addElement($unlimited);
|
|
|
|
|
|
|
|
$location = new Zend_Form_Element_Text('location');
|
|
|
|
$location->setRequired(true)
|
|
|
|
->setLabel(I18n::_('Location'))
|
|
|
|
->setValue(I18n::_('CAcert Test Manager'))
|
|
|
|
->addValidator(new Zend_Validate_StringLength(1,255));
|
|
|
|
$form->addElement($location);
|
|
|
|
|
|
|
|
$date = new Zend_Form_Element_Text('date');
|
|
|
|
$date->setRequired(true)
|
|
|
|
->setLabel(I18n::_('Date of Increase'))
|
|
|
|
->setValue(date('Y-m-d H:i:s'))
|
|
|
|
->addValidator(new Zend_Validate_StringLength(1,255));
|
|
|
|
$form->addElement($date);
|
|
|
|
|
|
|
|
$submit = new Zend_Form_Element_Submit('submit');
|
|
|
|
$submit->setLabel(I18n::_('Give Me Points'));
|
|
|
|
$form->addElement($submit);
|
2010-07-01 14:42:37 +00:00
|
|
|
|
|
|
|
return $form;
|
2010-06-28 18:06:01 +00:00
|
|
|
}
|
2010-07-01 16:52:43 +00:00
|
|
|
|
|
|
|
protected function getAssurerChallengeForm()
|
|
|
|
{
|
|
|
|
$form = new Zend_Form();
|
|
|
|
$form->setAction('/manage-account/assurer-challenge')
|
|
|
|
->setMethod('post');
|
|
|
|
|
|
|
|
$variant = new Zend_Form_Element_Select('variant');
|
|
|
|
$variant->setLabel(I18n::_('Variant'));
|
2011-06-28 18:11:03 +00:00
|
|
|
$options =
|
|
|
|
Default_Model_User::getAvailableChallengeVariants($this->db, 1);
|
2010-07-04 22:31:17 +00:00
|
|
|
$variant->setMultiOptions($options)
|
2010-07-01 16:52:43 +00:00
|
|
|
->setRequired(true);
|
|
|
|
$form->addElement($variant);
|
|
|
|
|
|
|
|
$submit = new Zend_Form_Element_Submit('submit');
|
|
|
|
$submit->setLabel(I18n::_('Challenge Me'));
|
|
|
|
$form->addElement($submit);
|
|
|
|
|
|
|
|
return $form;
|
|
|
|
}
|
2010-07-06 16:16:10 +00:00
|
|
|
|
2011-06-30 19:48:35 +00:00
|
|
|
protected function getFlagsForm(Default_Model_User $user)
|
2010-07-06 16:16:10 +00:00
|
|
|
{
|
|
|
|
$form = new Zend_Form();
|
|
|
|
$form->setAction('/manage-account/flags')
|
|
|
|
->setMethod('post');
|
|
|
|
|
2011-06-30 19:48:35 +00:00
|
|
|
$flags = $user->getFlags();
|
2010-07-06 16:16:10 +00:00
|
|
|
|
|
|
|
// Add a checkbox for each flag
|
|
|
|
$labels = array();
|
|
|
|
$labels['admin'] = I18n::_('Support Engineer');
|
|
|
|
$labels['codesign'] = I18n::_('Code Signing');
|
|
|
|
$labels['orgadmin'] = I18n::_('Organisation Admin');
|
|
|
|
$labels['ttpadmin'] = I18n::_('TTP Admin');
|
|
|
|
$labels['board'] = I18n::_('Board Member');
|
|
|
|
$labels['locadmin'] = I18n::_('Location Admin');
|
2011-06-30 19:48:35 +00:00
|
|
|
$labels['tverify'] = I18n::_('TVerify');
|
2010-07-06 16:16:10 +00:00
|
|
|
$labels['locked'] = I18n::_('Lock Account');
|
|
|
|
$labels['assurer_blocked'] = I18n::_('Block Assurer');
|
|
|
|
|
|
|
|
foreach ($labels as $flag => $label) {
|
|
|
|
$checkbox = new Zend_Form_Element_Checkbox($flag);
|
|
|
|
$checkbox->setLabel($label)
|
2011-06-30 19:48:35 +00:00
|
|
|
->setChecked($flags[$flag]);
|
2010-07-06 16:16:10 +00:00
|
|
|
$form->addElement($checkbox);
|
|
|
|
}
|
|
|
|
|
|
|
|
$submit = new Zend_Form_Element_Submit('submit');
|
|
|
|
$submit->setLabel(I18n::_('Save Flags'));
|
|
|
|
$form->addElement($submit);
|
|
|
|
|
|
|
|
return $form;
|
|
|
|
}
|
2010-04-22 16:26:41 +00:00
|
|
|
}
|