2015-01-12 97 views
0

在我的要求中,用戶收到一封帶有網址的電子郵件,一旦他點擊用戶將通過身份驗證過程導航到網址。在security.yml中獲取當前網址

因此,爲了將用戶重定向到我使用(Pass parameters when redirect),我打算通過重定向URL作爲參數就像

login_path: %accounts_host%/signin?redirect=%need_current_url_here%

security.yml和捕獲之內。因而這裏所說的方法點擊URL $url=$_GET['redirect'];並相應地提供重定向。

我的查詢是我怎樣才能從security.yml訪問當前的URL,以便我可以將它附加到login_path

我對此很新,任何示例/文檔都非常感謝。 :)

PS

認證是另一個symonfy2應用程序中完成在這一點,我不能使用referer命令,因爲它會爲空。這就是爲什麼我試圖通過你的重定向url作爲參數。 :)

+0

@CSchulz它在那裏我試圖在URL中傳遞簽名作爲內paramerter後重定向相同的認證過程security.yml。 –

+0

這是不是像你在重定向到sigin網址之前調用一樣?例如:call yourapp/url => yourapp/signin => yourapp/url – CSchulz

+0

@CSchulz我試過這種使用'referer'方法,但是一旦它導航到登錄引用者總是null.so那就是爲什麼我試圖通過在要導航的url中作爲參數。 –

回答

2

我會建議使用入口點和成功處理程序。

security.yml:

firewalls:   # Required 
    # Examples: 
    somename: 
     entry_point: some.service.id 
     ... 
     form_login: 
      ... 
      success_handler: some.service.id 

SuccessHandler(source):

<?php 
namespace StatSidekick\UserBundle\Handler; 

use Symfony\Component\HttpFoundation\JsonResponse; 
use Symfony\Component\HttpFoundation\Response; 
use Symfony\Component\HttpFoundation\Request; 
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; 
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler; 
use Symfony\Component\Security\Http\HttpUtils; 

class AuthenticationSuccessHandler extends DefaultAuthenticationSuccessHandler { 

    public function __construct(HttpUtils $httpUtils, array $options) { 
     parent::__construct($httpUtils, $options); 
    } 

    public function onAuthenticationSuccess(Request $request, TokenInterface $token) { 
     // Create if necessary a redirect response otherwise use the parent one with 
     // $response = parent::onAuthenticationSuccess($request, $token); 

     return $response; 
    } 
} 

入口點(source):

當用戶在所有沒有被認證(即,當令牌存儲器 還沒有令牌),防火牆的入口點將被調用編輯爲 「開始」認證過程。入口點應該實現 AuthenticationEntryPointInterface,它只有一個方法:開始()...