mailing sytem admin

This commit is contained in:
Etienne Roudeix
2013-10-28 12:24:59 +01:00
parent 223b39b6c1
commit 2eb5fc821c
12 changed files with 653 additions and 65 deletions

View File

@@ -23,20 +23,91 @@
namespace Thelia\Controller\Admin;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Core\Event\MailingSystem\MailingSystemEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Security\AccessManager;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Form\MailingSystemModificationForm;
use Thelia\Model\ConfigQuery;
/**
* Class MailingSystemController
* @package Thelia\Controller\Admin
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class MailingSystemController extends BaseAdminController
{
const RESOURCE_CODE = "admin.mailing-system";
public function defaultAction()
{
if (null !== $response = $this->checkAuth(AdminResources::MAILING_SYSTEM, AccessManager::VIEW)) return $response;
return $this->render("mailing-system");
if (null !== $response = $this->checkAuth(self::RESOURCE_CODE, AccessManager::VIEW)) return $response;
// Hydrate the form abd pass it to the parser
$data = array(
'enabled' => ConfigQuery::isSmtpEnable() ? 1 : 0,
'host' => ConfigQuery::getSmtpHost(),
'port' => ConfigQuery::getSmtpPort(),
'encryption' => ConfigQuery::getSmtpEncryption(),
'username' => ConfigQuery::getSmtpUsername(),
'password' => ConfigQuery::getSmtpPassword(),
'authmode' => ConfigQuery::getSmtpAuthMode(),
'timeout' => ConfigQuery::getSmtpTimeout(),
'sourceip' => ConfigQuery::getSmtpSourceIp(),
);
// Setup the object form
$form = new MailingSystemModificationForm($this->getRequest(), "form", $data);
// Pass it to the parser
$this->getParserContext()->addForm($form);
// Render the edition template.
return $this->render('mailing-system');
}
public function updateAction()
{
// Check current user authorization
if (null !== $response = $this->checkAuth(self::RESOURCE_CODE, AccessManager::UPDATE)) return $response;
$error_msg = false;
// Create the form from the request
$form = new MailingSystemModificationForm($this->getRequest());
try {
// Check the form against constraints violations
$formData = $this->validateForm($form, "POST");
// Get the form field values
$event = new MailingSystemEvent();
$event->setEnabled($formData->get('enabled')->getData());
$event->setHost($formData->get('host')->getData());
$event->setPort($formData->get('port')->getData());
$event->setEncryption($formData->get('encryption')->getData());
$event->setUsername($formData->get('username')->getData());
$event->setPassword($formData->get('password')->getData());
$event->setAuthMode($formData->get('authmode')->getData());
$event->setTimeout($formData->get('timeout')->getData());
$event->setSourceIp($formData->get('sourceip')->getData());
$this->dispatch(TheliaEvents::MAILING_SYSTEM_UPDATE, $event);
// Redirect to the success URL
$this->redirectToRoute("admin.configuration.mailing-system.view");
} catch (FormValidationException $ex) {
// Form cannot be validated
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
} catch (\Exception $ex) {
// Any other error
$error_msg = $ex->getMessage();
}
$this->setupFormErrorContext(
$this->getTranslator()->trans("mailing system modification", array()),
$error_msg,
$form,
$ex
);
// At this point, the form has errors, and should be redisplayed.
return $this->render('mailing-system');
}
}