我正在使用FosUserBundle在我的网站中注册和验证用户。但我遇到麻烦导致用户会话很快就会松动。有时5分钟,有时10分钟,然后用户再次被重定向到登录表单,导致许多用户离开我的网站。
这是我目前在我的项目中所拥有的:
composer.json
{"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.6.*",
"doctrine/orm": "~2.2,>=2.2.3,<2.5",
"doctrine/dbal": "<2.5",
"doctrine/doctrine-bundle": "~1.2",
"twig/extensions": "~1.0",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"symfony/yaml": "2.7.*@dev",
"symfony/filesystem": "~2.6",
"sensio/distribution-bundle": "~3.0,>=3.0.12",
"sensio/framework-extra-bundle": "~3.0,>=3.0.2",
"incenteev/composer-parameter-handler": "~2.0",
"friendsofsymfony/user-bundle": "~2.0@dev",
"friendsofsymfony/jsrouting-bundle": "@stable",
"knplabs/knp-snappy-bundle": "dev-master",
"jms/serializer-bundle": "0.13.*"
},
"require-dev": {
"sensio/generator-bundle": "~2.3"
}
}
config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: "@MoovityUserBundle/Resources/config/services.yml" }
- { resource: "@MoovityBackendBundle/Resources/config/services.yml" }
framework:
#esi: ~
translator: { fallback: "%locale%" }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
cookie_lifetime: 0
gc_maxlifetime: 14400
fragments: ~
http_method_override: true
# translator: ~
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ MoovityBackendBundle ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
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, add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
fos_user:
db_driver: orm
firewall_name: main
user_class: Moovity\UserBundle\Entity\User
registration:
confirmation:
enabled: true
from_email:
address: noreply@mywebsite.com
sender_name: mywebsite
template: MoovityBackendBundle:Mail:mail_fos_user_register_template.html.twig
# template: FOSUserBundle:Registration:email.html.twig
form:
type: moovity_user_registration
resetting:
email:
from_email:
address: resetpass@mywensite.com
sender_name: My Website Reset Password
template: FOSUserBundle:Resetting:email.html.twig
form:
type: moovity_user_resetting
service:
mailer: fos_user.mailer.twig_swift
#fos_rest:
# routing_loader:
# default_format: json
security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
# id: fos_user.user_provider.username
id: fos_user.user_provider.username_email
firewalls:
main:
pattern: ^/
form_login:
login_path: fos_user_registration_register
check_path: fos_user_security_check
provider: fos_userbundle
csrf_provider: form.csrf_provider
# always_use_default_target_path: true
# Redirección despues de loguear
default_target_path: moovity_backend_homepage
logout:
path: fos_user_security_logout
target: fos_user_registration_register
# target: fos_user_security_login
anonymous: true
security: true
remember_me:
key: 57361cdee0bb68f4e4b71f06b28fc07e
lifetime: 6000
我做错了什么?
答案 0 :(得分:0)
好的,我注意到fosuserbundle正在失去与Symfony 2.6的会话,所以我切换到2.3,现在它似乎正在工作。
非常感谢。
答案 1 :(得分:0)
我认为问题在于翻译。 得到相同的错误,尝试删除参数中的区域设置并使用〜
重置它如果是问题,请发布