2016-04-12 28 views
-1

Kullanıcıları yönetmek için FOSUser paketini kullanıyorum, sorunu elime koyduğumda imzaladığınız zaman oturum açma/oturum açma formunu yeniden belirten ve ne istediğimi Eğer bar tarayıcı/oturum açma koyduysanız ve oturum açmadan bana otomatik olarak beni/dizini yeniden yönlendirirseniz, formu yeniden görüntülemek için formu yeniden görüntüleyin.Symfony2 bakışı göremedi giriş yaptıktan sonra

Yardımcı olabilir misiniz? Oturum açma kontrolörü olarak

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

Lütfen security.yml dosya içeriğini sağlayın – LMS94

+0

Tamam, Sadece mesajı düzenleyin. – elAIR

cevap

0

olmak o

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

Yoksa

Edit gibi güvenlik sistemini bir şey yapabilirim:

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 } 

Benim denetleyicisi budur otomatik

+0

Bu hatayı alıyorum "Acme \ UserBundle \ Controller \ SecurityController" sınıfındaki "getUser" yöntemini çağırmayı deneyin. – elAIR

+0

Denetleyiciniz denetleyiciyi genişletmeli –

İlgili konular