2016-04-12 11 views
-1

私は、ユーザーを管理するためにバンドルFOSUserを使用していますが、私が問題になるのは、手動でパスを入力するとログインします。私がバーブラウザ/ログオンをしてログを記録していれば、自動的に私/インデックスをリダイレクトして、フォームを再表示してログインすることができます。symfony2は一度記録されたビューのログインを表示しません

私はお手伝いできますか?

security: 
encoders: 
    FOS\UserBundle\Model\UserInterface: sha512 
role_hierarchy: 
    ROLE_USER:  ROLE_USER 
    ROLE_ADMIN:  ROLE_ADMIN 
    ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] 

providers: 
    fos_userbundle: 
     id: fos_user.user_provider.username 

firewalls: 
    main: 
     pattern: ^/ 
     form_login: 
      check_path: /login_check 
      login_path:/
      provider: fos_userbundle 
      always_use_default_target_path: false 
      default_target_path: /index 

     logout: 
      path: /logout 
      target:/
     anonymous: ~ 
     #http_basic: 
     # realm: "Secured Demo Area" 

access_control: 
    - { path: ^/$, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    - { path: ^/admin, role: ROLE_SUPER_ADMIN } 
    - { path: ^/index, role: ROLE_USER, requires_channel: http} 
    #- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https } 

私のコントローラはこれです:あなたがあるためにあなたのセキュリティシステムを編集すること

if($this->getUser() instanceof your_user_entity){ 
    return $this->redirectToRoute('route_of_your_index'); 
} 

さも

ような何かを行うことができ、ログインコントローラで

class SecurityController extends ContainerAware 
{ 
public function loginAction() 
{ 
    $request = $this->container->get('request'); 
    $session = $request->getSession(); 


    if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) { 
     $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR); 
    } elseif (null !== $session && $session->has(SecurityContext::AUTHENTICATION_ERROR)) { 
     $error = $session->get(SecurityContext::AUTHENTICATION_ERROR); 
     $session->remove(SecurityContext::AUTHENTICATION_ERROR); 
    } else { 
     $error = ''; 
    } 

    if ($error) { 

     $error = $error->getMessage(); 
    } 

    $lastUsername = (null === $session) ? '' : $session->get(SecurityContext::LAST_USERNAME); 

    $csrfToken = $this->container->get('form.csrf_provider')->generateCsrfToken('authenticate'); 

    return $this->renderLogin(array(
     'last_username' => $lastUsername, 
     'error'   => $error, 
     'csrf_token' => $csrfToken, 
    )); 
} 


protected function renderLogin(array $data) 
{ 
    $template = sprintf('FOSUserBundle:Security:login.html.%s', $this->container->getParameter('fos_user.template.engine')); 

    return $this->container->get('templating')->renderResponse($template, $data); 
} 

public function checkAction() 
{ 
    throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.'); 
} 

public function logoutAction() 
{ 
    throw new \RuntimeException('You must activate the logout in your security firewall configuration.'); 
} 
} 
+0

security.ymlファイルの内容を入力してください。 – LMS94

+0

メッセージを編集するだけです。 – elAIR

答えて

0

自動

+0

このエラーが発生しました "Acme \ UserBundle \ Controller \ SecurityController"クラスの "getUser"メソッドを呼び出そうとしました – elAIR

+0

コントローラがコントローラを拡張する必要があります –

関連する問題