diff --git a/core/lib/Thelia/Admin/Controller/AdminController.php b/core/lib/Thelia/Admin/Controller/AdminController.php index 27d0ef707..bef1b1288 100755 --- a/core/lib/Thelia/Admin/Controller/AdminController.php +++ b/core/lib/Thelia/Admin/Controller/AdminController.php @@ -1,19 +1,55 @@ . */ +/* */ +/*************************************************************************************/ namespace Thelia\Admin\Controller; +use Thelia\Form\AdminLogin; class AdminController extends BaseAdminController { public function indexAction() { - return $this->render("login.html"); + + $form = $this->getFormBuilder(); + + $adminLogin = new AdminLogin(); + + $form = $adminLogin->buildForm($form, array())->getForm(); + + $request = $this->getRequest(); + + if($request->isMethod("POST")) { + $form->bind($request); + + if($form->isValid()) { + //TODO + } else { + //TODO + } + } + + return $this->render("login.html", array( + "form" => $form->createView() + )); } } \ No newline at end of file diff --git a/core/lib/Thelia/Admin/Controller/BaseAdminController.php b/core/lib/Thelia/Admin/Controller/BaseAdminController.php index 47ec7a476..3aa0e9281 100755 --- a/core/lib/Thelia/Admin/Controller/BaseAdminController.php +++ b/core/lib/Thelia/Admin/Controller/BaseAdminController.php @@ -24,6 +24,10 @@ namespace Thelia\Admin\Controller; use Symfony\Component\Routing\RequestContext; use Symfony\Component\DependencyInjection\ContainerAware; +use Symfony\Component\HttpFoundation\Response; + +use Thelia\Form\BaseForm; +use Thelia\Model\ConfigQuery; /** * @@ -44,7 +48,7 @@ class BaseAdminController extends ContainerAware */ public function render($templateName, $args = array()) { - $args = array('lang' => 'fr'); + $args = array_merge($args, array('lang' => 'fr')); $response = new Response(); @@ -53,7 +57,7 @@ class BaseAdminController extends ContainerAware public function renderRaw($templateName, $args = array()) { - $args = array('lang' => 'fr'); + $args = array_merge($args, array('lang' => 'fr')); return $this->getParser()->render($templateName, $args); } @@ -76,5 +80,15 @@ class BaseAdminController extends ContainerAware return $parser; } + public function getFormFactory() + { + return BaseForm::getFormFactory($this->getRequest(), ConfigQuery::read("form.secret.admin", md5(__DIR__))); + } + + public function getFormBuilder() + { + return $this->getFormFactory()->createBuilder("form"); + } + } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index 407606604..ea44af4a4 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -88,7 +88,7 @@ class Form implements SmartyPluginInterface $template->assign("options", $form->vars); - $template->assign("name", $form->vars["name"]); + $template->assign("name", $form->vars["full_name"]); $template->assign("value", $form->vars["value"]); $template->assign("label", $form->vars["label"]); $attr = array(); @@ -119,7 +119,7 @@ class Form implements SmartyPluginInterface foreach ($form->getIterator() as $row) { if ($this->isHidden($row) && $row->isRendered() === false) { - $return .= sprintf($field, $row->vars["name"], $row->vars["value"]); + $return .= sprintf($field, $row->vars["full_name"], $row->vars["value"]); } } @@ -136,7 +136,7 @@ class Form implements SmartyPluginInterface $form = $params["form"]; if (! $form instanceof \Symfony\Component\Form\FormView) { - throw new \InvalidArgumentException("form parameter in form_field block must be an instance of + throw new \InvalidArgumentException("form parameter in form_enctype function must be an instance of Symfony\Component\Form\FormView"); } diff --git a/core/lib/Thelia/Form/BaseForm.php b/core/lib/Thelia/Form/BaseForm.php index bd5dbdaef..1f3f15d79 100644 --- a/core/lib/Thelia/Form/BaseForm.php +++ b/core/lib/Thelia/Form/BaseForm.php @@ -36,7 +36,7 @@ class BaseForm { * @param Request $request * @return \Symfony\Component\Form\FormFactoryInterface */ - public static function getFormFactory(Request $request) + public static function getFormFactory(Request $request, $secret = null) { $form = Forms::createFormFactoryBuilder() ->addExtension(new HttpFoundationExtension()) @@ -44,7 +44,7 @@ class BaseForm { new CsrfExtension( new SessionCsrfProvider( $request->getSession(), - ConfigQuery::read("form.secret", md5(__DIR__)) + $secret ?: ConfigQuery::read("form.secret", md5(__DIR__)) ) ) )->getFormFactory(); diff --git a/templates/admin/default/login.html b/templates/admin/default/login.html index b059bb222..879c76cda 100755 --- a/templates/admin/default/login.html +++ b/templates/admin/default/login.html @@ -15,9 +15,14 @@

{intl l='Thelia Back Office'}

-
- - + + {form_field_hidden form=$form} + {form_field form=$form.username} + + {/form_field} + {form_field form=$form.password} + + {/form_field}