Skip to content

Commit 775449a

Browse files
committed
Merge pull request #1937 from XWB/patch-2
Fixed deprecated app.security
2 parents 5bc3648 + 3b65b9f commit 775449a

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Controller/RegistrationController.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,23 @@ public function confirmedAction()
140140

141141
return $this->render('FOSUserBundle:Registration:confirmed.html.twig', array(
142142
'user' => $user,
143+
'targetUrl' => $this->getTargetUrlFromSession(),
143144
));
144145
}
146+
147+
private function getTargetUrlFromSession()
148+
{
149+
// Set the SecurityContext for Symfony <2.6
150+
if (interface_exists('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')) {
151+
$tokenStorage = $this->get('security.token_storage');
152+
} else {
153+
$tokenStorage = $this->get('security.context');
154+
}
155+
156+
$key = sprintf('_security.%s.target_path', $tokenStorage->getToken()->getProviderKey());
157+
158+
if ($this->get('session')->has($key)) {
159+
return $this->get('session')->get($key);
160+
}
161+
}
145162
}

Resources/views/Registration/confirmed.html.twig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
{% block fos_user_content %}
66
<p>{{ 'registration.confirmed'|trans({'%username%': user.username}) }}</p>
7-
{% if app.session is not empty %}
8-
{% set targetUrl = app.session.get('_security.' ~ app.security.token.providerKey ~ '.target_path') %}
9-
{% if targetUrl is not empty %}<p><a href="{{ targetUrl }}">{{ 'registration.back'|trans }}</a></p>{% endif %}
7+
{% if targetUrl %}
8+
<p><a href="{{ targetUrl }}">{{ 'registration.back'|trans }}</a></p>
109
{% endif %}
1110
{% endblock fos_user_content %}

0 commit comments

Comments
 (0)