Merge branch 'master' into template
Conflicts: core/lib/Thelia/Core/Event/TheliaEvents.php
This commit is contained in:
@@ -210,31 +210,34 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
/**
|
||||
* Put in this method post object creation processing if required.
|
||||
*
|
||||
* @param unknown $createdObject the created object
|
||||
* @param unknown $createEvent the create event
|
||||
* @return Response a response, or null to continue normal processing
|
||||
*/
|
||||
protected function performAdditionalCreateAction($createdObject)
|
||||
protected function performAdditionalCreateAction($createEvent)
|
||||
{
|
||||
// Nothing to do
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put in this method post object update processing if required.
|
||||
*
|
||||
* @param unknown $updatedObject the updated object
|
||||
* @param unknown $updateEvent the update event
|
||||
* @return Response a response, or null to continue normal processing
|
||||
*/
|
||||
protected function performAdditionalUpdateAction($updatedObject)
|
||||
protected function performAdditionalUpdateAction($updateeEvent)
|
||||
{
|
||||
// Nothing to do
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put in this method post object delete processing if required.
|
||||
*
|
||||
* @param unknown $deletedObject the deleted object
|
||||
* @param unknown $deleteEvent the delete event
|
||||
* @return Response a response, or null to continue normal processing
|
||||
*/
|
||||
protected function performAdditionalDeleteAction($deletedObject)
|
||||
protected function performAdditionalDeleteAction($deleteEvent)
|
||||
{
|
||||
// Nothing to do
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -306,7 +309,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
$this->adminLogAppend(sprintf("%s %s (ID %s) created", ucfirst($this->objectName), $this->getObjectLabel($createdObject), $this->getObjectId($createdObject)));
|
||||
}
|
||||
|
||||
$this->performAdditionalCreateAction($createdObject);
|
||||
$this->performAdditionalCreateAction($createEvent);
|
||||
|
||||
// Substitute _ID_ in the URL with the ID of the created object
|
||||
$successUrl = str_replace('_ID_', $this->getObjectId($createdObject), $creationForm->getSuccessUrl());
|
||||
@@ -393,7 +396,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
$this->adminLogAppend(sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
|
||||
}
|
||||
|
||||
$this->performAdditionalUpdateAction($changedObject);
|
||||
$this->performAdditionalUpdateAction($changeEvent);
|
||||
|
||||
// If we have to stay on the same page, do not redirect to the succesUrl,
|
||||
// just redirect to the edit page again.
|
||||
@@ -494,8 +497,12 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
$this->adminLogAppend(
|
||||
sprintf("%s %s (ID %s) deleted", ucfirst($this->objectName), $this->getObjectLabel($deletedObject), $this->getObjectId($deletedObject)));
|
||||
}
|
||||
$this->performAdditionalDeleteAction($deletedObject);
|
||||
|
||||
$this->redirectToListTemplate();
|
||||
$response = $this->performAdditionalDeleteAction($deleteEvent);
|
||||
|
||||
if ($response == null)
|
||||
$this->redirectToListTemplate();
|
||||
else
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Security\Authentication\AdminTokenAuthenticator;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Core\Security\Exception\TokenAuthenticationException;
|
||||
|
||||
class AdminController extends BaseAdminController
|
||||
{
|
||||
public function indexAction()
|
||||
|
||||
@@ -107,7 +107,7 @@ class AttributeController extends AbstractCrudController
|
||||
*
|
||||
* @see \Thelia\Controller\Admin\AbstractCrudController::performAdditionalUpdateAction()
|
||||
*/
|
||||
protected function performAdditionalUpdateAction($updatedObject)
|
||||
protected function performAdditionalUpdateAction($updateEvent)
|
||||
{
|
||||
$attr_values = $this->getRequest()->get('attribute_values', null);
|
||||
|
||||
@@ -123,6 +123,8 @@ class AttributeController extends AbstractCrudController
|
||||
$this->dispatch(TheliaEvents::ATTRIBUTE_AV_UPDATE, $event);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue)
|
||||
|
||||
@@ -40,6 +40,8 @@ use Thelia\Form\BaseForm;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Log\Tlog;
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Thelia\Model\Admin;
|
||||
use Thelia\Core\Security\Token\CookieTokenProvider;
|
||||
|
||||
class BaseAdminController extends BaseController
|
||||
{
|
||||
@@ -302,6 +304,46 @@ class BaseAdminController extends BaseController
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the remember me cookie for the given user.
|
||||
*/
|
||||
protected function createAdminRememberMeCookie(Admin $user)
|
||||
{
|
||||
$ctp = new CookieTokenProvider();
|
||||
|
||||
$cookieName = ConfigQuery::read('admin_remember_me_cookie_name', 'armcn');
|
||||
$cookieExpiration = ConfigQuery::read('admin_remember_me_cookie_expiration', 2592000 /* 1 month */);
|
||||
|
||||
$ctp->createCookie($user, $cookieName, $cookieExpiration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rememberme key from the cookie.
|
||||
*
|
||||
* @return string hte key found, or null if no key was found.
|
||||
*/
|
||||
protected function getRememberMeKeyFromCookie()
|
||||
{
|
||||
// Check if we can authenticate the user with a cookie-based token
|
||||
$cookieName = ConfigQuery::read('admin_remember_me_cookie_name', 'armcn');
|
||||
|
||||
$ctp = new CookieTokenProvider();
|
||||
|
||||
return $ctp->getKeyFromCookie($this->getRequest(), $cookieName);
|
||||
}
|
||||
|
||||
/** Clear the remember me cookie.
|
||||
*
|
||||
*/
|
||||
protected function clearRememberMeCookie() {
|
||||
|
||||
$ctp = new CookieTokenProvider();
|
||||
|
||||
$cookieName = ConfigQuery::read('admin_remember_me_cookie_name', 'armcn');
|
||||
|
||||
$ctp->clearCookie($cookieName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the given template, and returns the result as an Http Response.
|
||||
*
|
||||
|
||||
@@ -30,6 +30,7 @@ use Thelia\Constraint\ConstraintFactoryTest;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmount;
|
||||
use Thelia\Constraint\Rule\CouponRuleInterface;
|
||||
use Thelia\Constraint\Validator\PriceParam;
|
||||
use Thelia\Core\Event\Coupon\CouponConsumeEvent;
|
||||
use Thelia\Core\Event\Coupon\CouponCreateEvent;
|
||||
use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Coupon\CouponEvent;
|
||||
@@ -39,6 +40,7 @@ use Thelia\Core\Security\Exception\AuthenticationException;
|
||||
use Thelia\Core\Security\Exception\AuthorizationException;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Coupon\CouponFactory;
|
||||
use Thelia\Coupon\CouponManager;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
@@ -72,7 +74,54 @@ class CouponController extends BaseAdminController
|
||||
{
|
||||
$this->checkAuth('ADMIN', 'admin.coupon.view');
|
||||
|
||||
return $this->render('coupon-list');
|
||||
$args['urlReadCoupon'] = $this->getRoute(
|
||||
'admin.coupon.read',
|
||||
array('couponId' => 'couponId'),
|
||||
Router::ABSOLUTE_URL
|
||||
);
|
||||
|
||||
$args['urlEditCoupon'] = $this->getRoute(
|
||||
'admin.coupon.update',
|
||||
array('couponId' => 'couponId'),
|
||||
Router::ABSOLUTE_URL
|
||||
);
|
||||
|
||||
$args['urlCreateCoupon'] = $this->getRoute(
|
||||
'admin.coupon.create',
|
||||
array(),
|
||||
Router::ABSOLUTE_URL
|
||||
);
|
||||
|
||||
return $this->render('coupon-list', $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage Coupons read display
|
||||
*
|
||||
* @param int $couponId Coupon Id
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function readAction($couponId)
|
||||
{
|
||||
$this->checkAuth('ADMIN', 'admin.coupon.read');
|
||||
|
||||
// Database request repeated in the loop but cached
|
||||
$search = CouponQuery::create();
|
||||
$coupon = $search->findOneById($couponId);
|
||||
|
||||
if ($coupon === null) {
|
||||
return $this->pageNotFound();
|
||||
}
|
||||
|
||||
$args['couponId'] = $couponId;
|
||||
$args['urlEditCoupon'] = $this->getRoute(
|
||||
'admin.coupon.update',
|
||||
array('couponId' => $couponId),
|
||||
Router::ABSOLUTE_URL
|
||||
);
|
||||
|
||||
return $this->render('coupon-read', $args);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +142,7 @@ class CouponController extends BaseAdminController
|
||||
|
||||
$i18n = new I18n();
|
||||
/** @var Lang $lang */
|
||||
$lang = $this->getSession()->get('lang');
|
||||
$lang = $this->getSession()->getLang();
|
||||
$eventToDispatch = TheliaEvents::COUPON_CREATE;
|
||||
|
||||
if ($this->getRequest()->isMethod('POST')) {
|
||||
@@ -108,10 +157,12 @@ class CouponController extends BaseAdminController
|
||||
// If no input for expirationDate, now + 2 months
|
||||
$defaultDate = new \DateTime();
|
||||
$args['defaultDate'] = $defaultDate->modify('+2 month')
|
||||
->format($lang->getDateFormat());
|
||||
->format('Y-m-d');
|
||||
}
|
||||
|
||||
$args['formAction'] = 'admin/coupon/create';
|
||||
$args['dateFormat'] = $this->getSession()->getLang()->getDateFormat();
|
||||
$args['availableCoupons'] = $this->getAvailableCoupons();
|
||||
$args['formAction'] = 'admin/coupon/create/';
|
||||
|
||||
return $this->render(
|
||||
'coupon-create',
|
||||
@@ -135,7 +186,7 @@ class CouponController extends BaseAdminController
|
||||
}
|
||||
|
||||
/** @var Coupon $coupon */
|
||||
$coupon = CouponQuery::create()->findOneById($couponId);
|
||||
$coupon = CouponQuery::create()->findPk($couponId);
|
||||
if (!$coupon) {
|
||||
$this->pageNotFound();
|
||||
}
|
||||
@@ -148,6 +199,7 @@ class CouponController extends BaseAdminController
|
||||
$lang = $this->getSession()->getLang();
|
||||
$eventToDispatch = TheliaEvents::COUPON_UPDATE;
|
||||
|
||||
// Create
|
||||
if ($this->getRequest()->isMethod('POST')) {
|
||||
$this->validateCreateOrUpdateForm(
|
||||
$i18n,
|
||||
@@ -156,9 +208,9 @@ class CouponController extends BaseAdminController
|
||||
'updated',
|
||||
'update'
|
||||
);
|
||||
} else {
|
||||
// Prepare the data that will hydrate the form
|
||||
} else { // Update
|
||||
|
||||
// Prepare the data that will hydrate the form
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
$rules = $constraintFactory->unserializeCouponRuleCollection(
|
||||
@@ -173,7 +225,7 @@ class CouponController extends BaseAdminController
|
||||
'shortDescription' => $coupon->getShortDescription(),
|
||||
'description' => $coupon->getDescription(),
|
||||
'isEnabled' => ($coupon->getIsEnabled() == 1),
|
||||
'expirationDate' => $coupon->getExpirationDate($lang->getDateFormat()),
|
||||
'expirationDate' => $coupon->getExpirationDate('Y-m-d'),
|
||||
'isAvailableOnSpecialOffers' => ($coupon->getIsAvailableOnSpecialOffers() == 1),
|
||||
'isCumulative' => ($coupon->getIsCumulative() == 1),
|
||||
'isRemovingPostage' => ($coupon->getIsRemovingPostage() == 1),
|
||||
@@ -202,7 +254,7 @@ class CouponController extends BaseAdminController
|
||||
// Pass it to the parser
|
||||
$this->getParserContext()->addForm($changeForm);
|
||||
}
|
||||
|
||||
$args['couponCode'] = $coupon->getCode();
|
||||
$args['availableCoupons'] = $this->getAvailableCoupons();
|
||||
$args['availableRules'] = $this->getAvailableRules();
|
||||
$args['urlAjaxGetRuleInput'] = $this->getRoute(
|
||||
@@ -222,123 +274,6 @@ class CouponController extends BaseAdminController
|
||||
return $this->render('coupon-update', $args);
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * Manage Coupons Rule creation display
|
||||
// *
|
||||
// * @param int $couponId Coupon id
|
||||
// *
|
||||
// * @return \Symfony\Component\HttpFoundation\Response
|
||||
// */
|
||||
// public function createRuleAction($couponId)
|
||||
// {
|
||||
// // Check current user authorization
|
||||
// $response = $this->checkAuth('admin.coupon.update');
|
||||
// if ($response !== null) {
|
||||
// return $response;
|
||||
// }
|
||||
//
|
||||
// /** @var Coupon $coupon */
|
||||
// $coupon = CouponQuery::create()->findOneById($couponId);
|
||||
// if (!$coupon) {
|
||||
// $this->pageNotFound();
|
||||
// }
|
||||
//
|
||||
// // Parameters given to the template
|
||||
// $args = array();
|
||||
//
|
||||
// $i18n = new I18n();
|
||||
// /** @var Lang $lang */
|
||||
// $lang = $this->getSession()->get('lang');
|
||||
// $eventToDispatch = TheliaEvents::COUPON_RULE_CREATE;
|
||||
//
|
||||
// if ($this->getRequest()->isMethod('POST')) {
|
||||
// $this->validateCreateOrUpdateForm(
|
||||
// $i18n,
|
||||
// $lang,
|
||||
// $eventToDispatch,
|
||||
// 'updated',
|
||||
// 'update'
|
||||
// );
|
||||
// } else {
|
||||
// // Prepare the data that will hydrate the form
|
||||
//
|
||||
// /** @var ConstraintFactory $constraintFactory */
|
||||
// $constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
//
|
||||
// $data = array(
|
||||
// 'code' => $coupon->getCode(),
|
||||
// 'title' => $coupon->getTitle(),
|
||||
// 'amount' => $coupon->getAmount(),
|
||||
// 'effect' => $coupon->getType(),
|
||||
// 'shortDescription' => $coupon->getShortDescription(),
|
||||
// 'description' => $coupon->getDescription(),
|
||||
// 'isEnabled' => ($coupon->getIsEnabled() == 1),
|
||||
// 'expirationDate' => $coupon->getExpirationDate($lang->getDateFormat()),
|
||||
// 'isAvailableOnSpecialOffers' => ($coupon->getIsAvailableOnSpecialOffers() == 1),
|
||||
// 'isCumulative' => ($coupon->getIsCumulative() == 1),
|
||||
// 'isRemovingPostage' => ($coupon->getIsRemovingPostage() == 1),
|
||||
// 'maxUsage' => $coupon->getMaxUsage(),
|
||||
// 'rules' => $constraintFactory->unserializeCouponRuleCollection($coupon->getSerializedRules()),
|
||||
// 'locale' => $coupon->getLocale(),
|
||||
// );
|
||||
//
|
||||
// /** @var CouponAdapterInterface $adapter */
|
||||
// $adapter = $this->container->get('thelia.adapter');
|
||||
// /** @var Translator $translator */
|
||||
// $translator = $this->container->get('thelia.translator');
|
||||
//
|
||||
// $args['rulesObject'] = array();
|
||||
// /** @var CouponRuleInterface $rule */
|
||||
// foreach ($coupon->getRules()->getRules() as $rule) {
|
||||
// $args['rulesObject'][] = array(
|
||||
// 'name' => $rule->getName($translator),
|
||||
// 'tooltip' => $rule->getToolTip($translator),
|
||||
// 'validators' => $rule->getValidators()
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// $args['rules'] = $this->cleanRuleForTemplate($coupon->getRules()->getRules());
|
||||
//
|
||||
// // Setup the object form
|
||||
// $changeForm = new CouponCreationForm($this->getRequest(), 'form', $data);
|
||||
//
|
||||
// // Pass it to the parser
|
||||
// $this->getParserContext()->addForm($changeForm);
|
||||
// }
|
||||
//
|
||||
// $args['formAction'] = 'admin/coupon/update/' . $couponId;
|
||||
//
|
||||
// return $this->render(
|
||||
// 'coupon-update',
|
||||
// $args
|
||||
// );
|
||||
// }
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Manage Coupons read display
|
||||
*
|
||||
* @param int $couponId Coupon Id
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function readAction($couponId)
|
||||
{
|
||||
$this->checkAuth('ADMIN', 'admin.coupon.read');
|
||||
|
||||
// Database request repeated in the loop but cached
|
||||
$search = CouponQuery::create();
|
||||
$coupon = $search->findOneById($couponId);
|
||||
|
||||
if ($coupon === null) {
|
||||
return $this->pageNotFound();
|
||||
}
|
||||
|
||||
return $this->render('coupon-read', array('couponId' => $couponId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage Coupons read display
|
||||
*
|
||||
@@ -350,17 +285,7 @@ class CouponController extends BaseAdminController
|
||||
{
|
||||
$this->checkAuth('ADMIN', 'admin.coupon.read');
|
||||
|
||||
if ($this->isDebug()) {
|
||||
if (!$this->getRequest()->isXmlHttpRequest()) {
|
||||
$this->redirect(
|
||||
$this->getRoute(
|
||||
'admin',
|
||||
array(),
|
||||
Router::ABSOLUTE_URL
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->checkXmlHttpRequest();
|
||||
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
@@ -391,17 +316,7 @@ class CouponController extends BaseAdminController
|
||||
{
|
||||
$this->checkAuth('ADMIN', 'admin.coupon.read');
|
||||
|
||||
if ($this->isDebug()) {
|
||||
if (!$this->getRequest()->isXmlHttpRequest()) {
|
||||
$this->redirect(
|
||||
$this->getRoute(
|
||||
'admin',
|
||||
array(),
|
||||
Router::ABSOLUTE_URL
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->checkXmlHttpRequest();
|
||||
|
||||
$search = CouponQuery::create();
|
||||
/** @var Coupon $coupon */
|
||||
@@ -475,6 +390,29 @@ class CouponController extends BaseAdminController
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Coupon consuming
|
||||
*
|
||||
* @param string $couponCode Coupon code
|
||||
*
|
||||
*/
|
||||
public function consumeAction($couponCode)
|
||||
{
|
||||
// @todo remove (event dispatcher testing purpose)
|
||||
$couponConsumeEvent = new CouponConsumeEvent($couponCode);
|
||||
$eventToDispatch = TheliaEvents::COUPON_CONSUME;
|
||||
|
||||
// Dispatch Event to the Action
|
||||
$this->dispatch(
|
||||
$eventToDispatch,
|
||||
$couponConsumeEvent
|
||||
);
|
||||
|
||||
var_dump('test', $couponConsumeEvent->getCode(), $couponConsumeEvent->getDiscount(), $couponConsumeEvent->getIsValid());
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a Coupon from its form
|
||||
*
|
||||
@@ -535,7 +473,7 @@ class CouponController extends BaseAdminController
|
||||
/**
|
||||
* Validate the CreateOrUpdate form
|
||||
*
|
||||
* @param string $i18n Local code (fr_FR)
|
||||
* @param I18n $i18n Local code (fr_FR)
|
||||
* @param Lang $lang Local variables container
|
||||
* @param string $eventToDispatch Event which will activate actions
|
||||
* @param string $log created|edited
|
||||
@@ -543,7 +481,7 @@ class CouponController extends BaseAdminController
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function validateCreateOrUpdateForm($i18n, $lang, $eventToDispatch, $log, $action)
|
||||
protected function validateCreateOrUpdateForm(I18n $i18n, Lang $lang, $eventToDispatch, $log, $action)
|
||||
{
|
||||
// Create the form from the request
|
||||
$creationForm = new CouponCreationForm($this->getRequest());
|
||||
@@ -563,7 +501,7 @@ class CouponController extends BaseAdminController
|
||||
$data['shortDescription'],
|
||||
$data['description'],
|
||||
$data['isEnabled'],
|
||||
$i18n->getDateTimeFromForm($lang, $data['expirationDate']),
|
||||
\DateTime::createFromFormat('Y-m-d', $data['expirationDate']),
|
||||
$data['isAvailableOnSpecialOffers'],
|
||||
$data['isCumulative'],
|
||||
$data['isRemovingPostage'],
|
||||
@@ -651,17 +589,17 @@ class CouponController extends BaseAdminController
|
||||
/** @var CouponManager $couponManager */
|
||||
$couponManager = $this->container->get('thelia.coupon.manager');
|
||||
$availableCoupons = $couponManager->getAvailableCoupons();
|
||||
$cleanedRules = array();
|
||||
$cleanedCoupons = array();
|
||||
/** @var CouponInterface $availableCoupon */
|
||||
foreach ($availableCoupons as $availableCoupon) {
|
||||
$rule = array();
|
||||
$rule['serviceId'] = $availableCoupon->getServiceId();
|
||||
$rule['name'] = $availableCoupon->getName();
|
||||
$rule['toolTip'] = $availableCoupon->getToolTip();
|
||||
$cleanedRules[] = $rule;
|
||||
$cleanedCoupons[] = $rule;
|
||||
}
|
||||
|
||||
return $cleanedRules;
|
||||
return $cleanedCoupons;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,11 +30,44 @@ use Thelia\Core\Security\Exception\AuthenticationException;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\Tools\Redirect;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Security\Authentication\AdminTokenAuthenticator;
|
||||
use Thelia\Core\Security\UserProvider\TokenProvider;
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
use Thelia\Core\Security\UserProvider\CookieTokenProvider;
|
||||
use Thelia\Core\Security\Exception\TokenAuthenticationException;
|
||||
|
||||
class SessionController extends BaseAdminController
|
||||
{
|
||||
public function showLoginAction()
|
||||
{
|
||||
// Check if we can authenticate the user with a cookie-based token
|
||||
if (null !== $key = $this->getRememberMeKeyFromCookie()) {
|
||||
|
||||
// Create the authenticator
|
||||
$authenticator = new AdminTokenAuthenticator($key);
|
||||
|
||||
try {
|
||||
// If have found a user, store it in the security context
|
||||
$user = $authenticator->getAuthentifiedUser();
|
||||
|
||||
$this->getSecurityContext()->setAdminUser($user);
|
||||
|
||||
$this->adminLogAppend("Successful token authentication");
|
||||
|
||||
// Update the cookie
|
||||
$cookie = $this->createAdminRememberMeCookie($user);
|
||||
|
||||
// Render the home page
|
||||
return $this->render("home");
|
||||
}
|
||||
catch (TokenAuthenticationException $ex) {
|
||||
$this->adminLogAppend("Token based authentication failed.");
|
||||
|
||||
// Clear the cookie
|
||||
$this->clearRememberMeCookie();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render("login");
|
||||
}
|
||||
|
||||
@@ -44,6 +77,9 @@ class SessionController extends BaseAdminController
|
||||
|
||||
$this->getSecurityContext()->clearAdminUser();
|
||||
|
||||
// Clear the remember me cookie, if any
|
||||
$this->clearRememberMeCookie();
|
||||
|
||||
// Go back to login page.
|
||||
$this->redirectToRoute('admin.login');
|
||||
}
|
||||
@@ -68,10 +104,19 @@ class SessionController extends BaseAdminController
|
||||
// Log authentication success
|
||||
AdminLog::append("Authentication successful", $request, $user);
|
||||
|
||||
/**
|
||||
* FIXME: we have tou find a way to send cookie
|
||||
*/
|
||||
if (intval($adminLoginForm->getForm()->get('remember_me')->getData()) > 0) {
|
||||
// If a remember me field if present and set in the form, create
|
||||
// the cookie thant store "remember me" information
|
||||
$this->createAdminRememberMeCookie($user);
|
||||
}
|
||||
|
||||
$this->dispatch(TheliaEvents::ADMIN_LOGIN);
|
||||
|
||||
// Redirect to the success URL
|
||||
return Redirect::exec($adminLoginForm->getSuccessUrl());
|
||||
// Redirect to the success URL, passing the cookie if one exists.
|
||||
$this->redirect($adminLoginForm->getSuccessUrl());
|
||||
|
||||
} catch (FormValidationException $ex) {
|
||||
|
||||
|
||||
196
core/lib/Thelia/Controller/Admin/TemplateController.php
Normal file
196
core/lib/Thelia/Controller/Admin/TemplateController.php
Normal file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\TemplateDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\TemplateUpdateEvent;
|
||||
use Thelia\Core\Event\TemplateCreateEvent;
|
||||
use Thelia\Model\TemplateQuery;
|
||||
use Thelia\Form\TemplateModificationForm;
|
||||
use Thelia\Form\TemplateCreationForm;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Model\TemplateAv;
|
||||
use Thelia\Model\TemplateAvQuery;
|
||||
use Thelia\Core\Event\TemplateAvUpdateEvent;
|
||||
use Thelia\Core\Event\TemplateEvent;
|
||||
|
||||
/**
|
||||
* Manages templates sent by mail
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class TemplateController extends AbstractCrudController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'template',
|
||||
null,
|
||||
null,
|
||||
|
||||
'admin.configuration.templates.view',
|
||||
'admin.configuration.templates.create',
|
||||
'admin.configuration.templates.update',
|
||||
'admin.configuration.templates.delete',
|
||||
|
||||
TheliaEvents::TEMPLATE_CREATE,
|
||||
TheliaEvents::TEMPLATE_UPDATE,
|
||||
TheliaEvents::TEMPLATE_DELETE,
|
||||
null, // No visibility toggle
|
||||
null // No position update
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCreationForm()
|
||||
{
|
||||
return new TemplateCreationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getUpdateForm()
|
||||
{
|
||||
return new TemplateModificationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getCreationEvent($formData)
|
||||
{
|
||||
$createEvent = new TemplateCreateEvent();
|
||||
|
||||
$createEvent
|
||||
->setTemplateName($formData['name'])
|
||||
->setLocale($formData["locale"])
|
||||
;
|
||||
|
||||
return $createEvent;
|
||||
}
|
||||
|
||||
protected function getUpdateEvent($formData)
|
||||
{
|
||||
$changeEvent = new TemplateUpdateEvent($formData['id']);
|
||||
|
||||
// Create and dispatch the change event
|
||||
$changeEvent
|
||||
->setLocale($formData["locale"])
|
||||
->setTemplateName($formData['name'])
|
||||
;
|
||||
|
||||
// Add feature and attributes list
|
||||
|
||||
return $changeEvent;
|
||||
}
|
||||
|
||||
protected function getDeleteEvent()
|
||||
{
|
||||
return new TemplateDeleteEvent($this->getRequest()->get('template_id'));
|
||||
}
|
||||
|
||||
protected function eventContainsObject($event)
|
||||
{
|
||||
return $event->hasTemplate();
|
||||
}
|
||||
|
||||
protected function hydrateObjectForm($object)
|
||||
{
|
||||
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
'locale' => $object->getLocale(),
|
||||
'name' => $object->getName()
|
||||
);
|
||||
|
||||
// Setup the object form
|
||||
return new TemplateModificationForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
protected function getObjectFromEvent($event)
|
||||
{
|
||||
return $event->hasTemplate() ? $event->getTemplate() : null;
|
||||
}
|
||||
|
||||
protected function getExistingObject()
|
||||
{
|
||||
return TemplateQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->findOneById($this->getRequest()->get('template_id'));
|
||||
}
|
||||
|
||||
protected function getObjectLabel($object)
|
||||
{
|
||||
return $object->getName();
|
||||
}
|
||||
|
||||
protected function getObjectId($object)
|
||||
{
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
protected function renderListTemplate($currentOrder)
|
||||
{
|
||||
return $this->render('templates', array('order' => $currentOrder));
|
||||
}
|
||||
|
||||
protected function renderEditionTemplate()
|
||||
{
|
||||
return $this->render(
|
||||
'template-edit',
|
||||
array(
|
||||
'template_id' => $this->getRequest()->get('template_id'),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function redirectToEditionTemplate()
|
||||
{
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.templates.update",
|
||||
array(
|
||||
'template_id' => $this->getRequest()->get('template_id'),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function redirectToListTemplate()
|
||||
{
|
||||
$this->redirectToRoute('admin.configuration.templates.default');
|
||||
}
|
||||
|
||||
// Process delete failure, which may occurs if template is in use.
|
||||
protected function performAdditionalDeleteAction($deleteEvent)
|
||||
{
|
||||
if ($deleteEvent->getProductCount() > 0) {
|
||||
|
||||
$this->getParserContext()->setGeneralError(
|
||||
$this->getTranslator()->trans(
|
||||
"This template is in use in some of your products, and cannot be deleted. Delete it from all your products and try again."
|
||||
)
|
||||
);
|
||||
|
||||
return $this->renderList();
|
||||
}
|
||||
|
||||
// Normal delete processing
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -127,7 +127,7 @@ class BaseController extends ContainerAware
|
||||
/**
|
||||
* Returns the session from the current request
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Session\SessionInterface
|
||||
* @return \Thelia\Core\HttpFoundation\Session\Session
|
||||
*/
|
||||
protected function getSession()
|
||||
{
|
||||
@@ -198,9 +198,9 @@ class BaseController extends ContainerAware
|
||||
*
|
||||
* @param string $url
|
||||
*/
|
||||
public function redirect($url, $status = 302)
|
||||
public function redirect($url, $status = 302, $cookies = array())
|
||||
{
|
||||
Redirect::exec($url, $status);
|
||||
Redirect::exec($url, $status, $cookies);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,7 +39,7 @@ class BaseInstallController extends BaseController
|
||||
{
|
||||
$parser = $this->container->get("thelia.parser");
|
||||
|
||||
// Define the template thant shoud be used
|
||||
// Define the template that shoud be used
|
||||
$parser->setTemplate("install");
|
||||
|
||||
return $parser;
|
||||
|
||||
@@ -33,18 +33,61 @@ class InstallController extends BaseInstallController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$this->verifyStep(1);
|
||||
//$this->verifyStep(1);
|
||||
|
||||
$this->getSession()->set("step", 1);
|
||||
|
||||
$this->render("index.html");
|
||||
return $this->render("index.html");
|
||||
}
|
||||
|
||||
public function checkPermission()
|
||||
{
|
||||
$this->verifyStep(2);
|
||||
//$this->verifyStep(2);
|
||||
|
||||
$permission = new CheckPermission();
|
||||
//$permission = new CheckPermission();
|
||||
|
||||
$this->getSession()->set("step", 2);
|
||||
return $this->render("step-2.html");
|
||||
}
|
||||
|
||||
public function databaseConnection()
|
||||
{
|
||||
//$this->verifyStep(2);
|
||||
|
||||
//$permission = new CheckPermission();
|
||||
|
||||
$this->getSession()->set("step", 3);
|
||||
return $this->render("step-3.html");
|
||||
}
|
||||
|
||||
public function databaseSelection()
|
||||
{
|
||||
//$this->verifyStep(2);
|
||||
|
||||
//$permission = new CheckPermission();
|
||||
|
||||
$this->getSession()->set("step", 4);
|
||||
return $this->render("step-4.html");
|
||||
}
|
||||
|
||||
public function generalInformation()
|
||||
{
|
||||
//$this->verifyStep(2);
|
||||
|
||||
//$permission = new CheckPermission();
|
||||
|
||||
$this->getSession()->set("step", 5);
|
||||
return $this->render("step-5.html");
|
||||
}
|
||||
|
||||
public function thanks()
|
||||
{
|
||||
//$this->verifyStep(2);
|
||||
|
||||
//$permission = new CheckPermission();
|
||||
|
||||
$this->getSession()->set("step", 6);
|
||||
return $this->render("thanks.html");
|
||||
}
|
||||
|
||||
protected function verifyStep($step)
|
||||
|
||||
Reference in New Issue
Block a user