Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixing sonata-project#412 and an issue with `security.context` having a _null_ token
with "non-standard" security.yml configuration the login/register page could be behind no firewall, implying there won't be any token from the security.context service
  • Loading branch information
net02 authored and Daniele Bartocci committed Jun 12, 2015
1 parent e9e2262 commit e2d40ef
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Controller/RegistrationFOSUser1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
*/
class RegistrationFOSUser1Controller extends ContainerAware
{
public function registerAction()
public function registerAction($template = "register")
{
$user = $this->container->get('security.context')->getToken()->getUser();
$user = $this->container->get('security.context')->getToken() ? $this->container->get('security.context')->getToken()->getUser() : null;

if ($user instanceof UserInterface) {
$this->container->get('session')->getFlashBag()->set('sonata_user_error', 'sonata_user_already_authenticated');
Expand Down Expand Up @@ -79,7 +79,7 @@ public function registerAction()

$this->container->get('session')->set('sonata_user_redirect_url', $this->container->get('request')->headers->get('referer'));

return $this->container->get('templating')->renderResponse('FOSUserBundle:Registration:register.html.'.$this->getEngine(), array(
return $this->container->get('templating')->renderResponse('FOSUserBundle:Registration:' . $template . '.html.'.$this->getEngine(), array(
'form' => $form->createView(),
));
}
Expand Down
4 changes: 2 additions & 2 deletions Controller/SecurityFOSUser1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SecurityFOSUser1Controller extends SecurityController
{
public function loginAction()
{
$user = $this->container->get('security.context')->getToken()->getUser();
$user = $this->container->get('security.context')->getToken() ? $this->container->get('security.context')->getToken()->getUser() : null;

if ($user instanceof UserInterface) {
$this->container->get('session')->getFlashBag()->set('sonata_user_error', 'sonata_user_already_authenticated');
Expand All @@ -37,4 +37,4 @@ public function loginAction()

return parent::loginAction();
}
}
}
2 changes: 1 addition & 1 deletion Resources/views/Security/base_login.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ file that was distributed with this source code.
</div>
<div class="col-sm-6">
{% block sonata_user_registration %}
{% render controller("SonataUserBundle:RegistrationFOSUser1:register") %}
{{ render(controller("SonataUserBundle:RegistrationFOSUser1:register", { 'template': 'register_content'})) }}
{% endblock %}
</div>
</div>
Expand Down

0 comments on commit e2d40ef

Please sign in to comment.