Symfony 3有问题验证

时间:2016-09-21 23:26:42

标签: authentication symfony

大家好我有一个问题,我在我的项目中使用symfony 3.1我的本地机器中的卫生认证工作正常但是当我部署到服务器如果验证成功我重定向到主页但我松了身份验证并再次成为匿名者。 事件,当我想在部署中注册新用户时,它不起作用,错误是错误的csrf。 似乎在部署中导航器不发送cookie或不接受它们。 我真的很困惑因为在我的本地服务器上这一切都很好 真的需要帮助。 THX

security.yml:

security:
    encoders:
        UserBundle\Entity\User: bcrypt
    providers:
        database_users:
            entity: {class: UserBundle:User, property: mail}
firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false
    main:
        anonymous: ~
        guard:
            authenticators:
                - form_login_authenticator

confing.yml:

    imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: services.yml }
    - { resource: "@VendeurBundle/Resources/config/services.yml" }
    - { resource: "@UserBundle/Resources/config/services.yml" }

# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
    locale: fr

framework:
    #esi:             ~
    translator:      { fallbacks: ["%locale%"] }
    secret:          "%secret%"
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    #serializer:      { enable_annotations: true }
    templating:
        engines: ['twig']
    default_locale:  "%locale%"
    trusted_hosts:   ~
    trusted_proxies: ~
    session:
        # http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
        handler_id:  session.handler.native_file
        save_path:   "%kernel.root_dir%/../var/sessions/%kernel.environment%"
        cookie_lifetime: 1000

    fragments:       ~
    http_method_override: true
    assets: ~

# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"
    form_themes:
        - 'bootstrap_3_horizontal_layout.html.twig'

# Doctrine Configuration
doctrine:
    dbal:
        driver:   pdo_mysql
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        # if using pdo_sqlite as your database driver:
        #   1. add the path in parameters.yml
        #     e.g. database_path: "%kernel.root_dir%/data/data.db3"
        #   2. Uncomment database_path in parameters.yml.dist
        #   3. Uncomment next line:
        #     path:     "%database_path%"

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true

# Swiftmailer Configuration
swiftmailer:
    transport: "%mailer_transport%"
    host:      "%mailer_host%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"
    spool:     { type: memory }
stof_doctrine_extensions:
    orm:
        default:
            timestampable: true

white_october_pagerfanta:
    exceptions_strategy:
        out_of_range_page:        ~
        not_valid_current_page:   ~

控制器:

    /**
 * @Route("/connexion", name="security_login")
 */
public function loginAction()
{
    if ($this->isAuthenticated()) {
        return $this->redirectToRoute('homepage');
    }
    $helper = $this->get('security.authentication_utils');
    return $this->render(':connexion:login.html.twig', array(
        // last username entered by the user (if any)
        'last_username' => $helper->getLastUsername(),
        // last authentication error (if any)
        'error' => $helper->getLastAuthenticationError(),
    ));
}

/**
 * @Route("/logout", name="logout")
 * @Security("is_authenticated()")
 */
public function logoutAction()
{
    $this->container->get('security.token_storage')->setToken(null);
    return $this->redirectToRoute("homepage");
}

/**
 * @Route("/login_check", name="security_login_check")
 */
public function loginCheckAction()
{
    // will never be executed
}

更新:我发现问题是服务器为每个请求销毁会话但我不知道如何解决它。

0 个答案:

没有答案