有人可以解释一下如何在控制器中手动创建记住我的cookie吗?
我希望用户在按下"注册"按钮后保持登录状态,而不必在之后使用他们的凭据登录.
我试图手动创建一个cookie,但我猜测cookie值是不正确的,因此"记住我"功能不起作用.设置具有正确名称的cookie.我检查过了.
当使用具有用户凭据的正常登录过程时,记住我的功能按预期工作.
security.yml security.yml记得我
security:
firewalls:
main:
remember_me:
lifetime: 86400
domain: ~
path: /
key: myKey
Run Code Online (Sandbox Code Playgroud)
这就是我现在所拥有的,即使设置了cookie,它也不起作用.
$um = $this->get('fos_user.user_manager');
$member = $um->createUser();
… Form stuff with bindRequest etc.
$um->updatePassword($member);
$um->updateUser($member);
$providerKey = $this->container->getParameter('fos_user.firewall_name');
$securityKey = 'myKey';
$token = new RememberMeToken($member, $providerKey, $securityKey,
$member->getRoles());
$this->container->get('security.context')->setToken($token);
$redirectResponse = new RedirectResponse($url);
$redirectResponse->headers->setCookie(
new \Symfony\Component\HttpFoundation\Cookie(
'REMEMBERME',
base64_encode(implode(':', array($member->getUsername(),
$member->getPassword()))),
time() + 60*60*24
)
);
return $redirectResponse;
Run Code Online (Sandbox Code Playgroud)
更新:
我也尝试使用反射处理PersistentTokenBasedRememberMeServices类,但它不起作用.一个cookie被设置但它不起作用
$token = $this->container->get('security.context')->getToken();
$providerKey = $this->container->getParameter('fos_user.firewall_name');
$securityKey = 'myKey';
$persistenService = new
PersistentTokenBasedRememberMeServices(array($um), …Run Code Online (Sandbox Code Playgroud) 在一个应用程序中,我使用长轮询实现了一个javascript聊天.由于每个域只允许一个Ajax请求,我想将轮询请求移动到子域.
所以我有两个域:
dev.site.com
poll.dev.site.com
Run Code Online (Sandbox Code Playgroud)
在我的config.yml我输入以下内容:
framework:
session:
domain: .dev.site.com
cookie_domain: .dev.site.com
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试通过Ajax在子域上进行轮询,Symfony不会让我登录.
关于如何在子域上保持会话的任何想法?我正在使用FOSUserBundle
我正在使用FOSUserBundle和Group选项.注册工作.创建小组也是有效的.如果我创建2个组,admin和client,并且手动添加:1:{i:0; s:10:"ROLE_ADMIN";}到fos_group表中的admin组,然后在fos_user_user_group中进行MANULLY设置和输入用户到管理员组,使用该用户登录将能够以管理员身份登录.
然而,这种方法显然存在一些缺点.我现在可以使用什么来将用户添加到组中?使用promote命令行选项只会将角色添加到该用户但在fos_user表中,并且因为我正在使用组,所以我怀疑不再使用fos_user表的roles列.如果它仍然有用,我如何以编程方式将用户分配给组?
我的另一个重要问题是如何为组分配角色.也许我没有得到关于整个群体想法的东西,但我本来希望能够在创建时为群组添加角色,但"新"形式只询问群组名称并且没有似乎存在相当于组的用户提升命令.
谢谢.
我使用Symfony和boostrap来定制我的网站的风格.我有一个twig文件:register_content.html.twig,其中包含一个注册表单.
在我的index.html.twig中我希望有类似的东西:
<a href="{{ path('fos_user_registration_register') }}" class="btn" data-toggle="modal">Je m'inscris !</a>
Run Code Online (Sandbox Code Playgroud)
要在模态窗口中显示寄存器表单的内容,但它不起作用.
我尝试使用twitter-bootstrap文档:http: //bootstrap.braincrafted.com/javascript#modals
但我无法找到一种方法在symfony中轻松应用它...
你可以帮帮我吗 ?
谢谢
我见过很多人试图使用FOSUserBundle.
我现在已经挣扎了6个小时了.只是为了能够制作自定义用户注册表单.基本文档长达6页:基本.从我的角度来看,以下是使用FOSUserBundle的所有缺点:
fos_user.因此,您必须将所有代码建立在您的user实体上,而实体是您的实体BaseUser.如果你的数据库遵循一个约定(就像wordpress那样,所有表都以其开头wp_),这会破坏你的约定.所以我只是想知道:如果使用FOSUserBundle有什么意义呢?如果我已经完成了注册过程,该过程遵循Symfony帮助(表单,表单验证和会话)中解释的基本内容,我只是复制粘贴我的代码,从我的角度来看,这比安装要快得多,配置,继承,修改FOSUserBundle等.
知道我做了什么,FOSUserBundle有什么优势?什么可以让我改变并花费更多的时间来使它与我的项目一起工作,而不是从另一个项目中重新使用我的(表单,表单验证和会话)?
我需要在FOSUserBundle中更改确认电子邮件的模板.我有这个设置,但它不起作用:
fos_user:
db_driver: orm
firewall_name: main
user_class: Acme\UserBundle\Entity\User
registration:
confirmation:
enabled: true
email:
template: AcmeUserBundle:User:confirm.email.twig
Run Code Online (Sandbox Code Playgroud)
错误是:
Unrecognized options "email" under "fos_user.registration"
Run Code Online (Sandbox Code Playgroud) 我在Symfony2项目中使用FOSUserBundle.我找不到任何合理的解释如何覆盖表单字段验证.我需要将密码字段验证设置为至少7个字符,至少一个小写字母,至少一个大写字母和至少一个数字.我找到的解决方案似乎没有任何解决方案.有任何想法吗?
我想知道是否有用户登录后调用函数.
这是我想要调用的代码:
$point = $this->container->get('process_points');
$point->ProcessPoints(1 , $this->container);
Run Code Online (Sandbox Code Playgroud) 我试图安装sonata admin bundle来管理我的用户.
我使用FOS用户包.
我已经说明了,但是出了什么问题,我找不到.
我有错误:
无法自动确定基本路由名称,请在C:\ Users\Alexandre\hubiC\www\questionnaire\app/config中baseRouteName为管理类定义默认值UserBundle\Admin\UserAdmin.(从"C:\ Users\Alexandre\hubiC\www\questionnaire\app/config\routing.yml"导入).
在我的服务中,我有:
services:
sonata.admin.user:
class: UserBundle\Admin\UserAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Content", label: "User" }
arguments:
- ~
- UserBundle\Entity\User
- ~
calls:
- [ setTranslationDomain, [UserBundle]]
Run Code Online (Sandbox Code Playgroud)
在我的配置中:
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: @UserBundle/Resources/config/admin.yml }
sonata_block:
default_contexts: [cms]
blocks:
# Enable the SonataAdminBundle block
sonata.admin.block.admin_list:
contexts: [admin]
# Your other blocks …Run Code Online (Sandbox Code Playgroud) 在我个人的Symfony 3.2项目(https://github.com/pc-magas/photoalbum)上因为我想获得一个Json而不是基于http://www.webtipblog.com/adding-an-ajax-login的重定向-form-to-a-symfony-project /我做了以下身份验证管理器:
<?php
namespace AppBundle\Security;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
class AuthenticationHandler implements AuthenticationSuccessHandlerInterface, AuthenticationFailureHandlerInterface
{
private $router;
private $session;
/**
* Constructor
*
* @author Joe Sexton <joe@webtipblog.com>
* @param RouterInterface $router
* @param Session $session
*/
public function __construct( RouterInterface $router, Session $session )
{
$this->router = $router;
$this->session = $session;
}
/**
* onAuthenticationSuccess
* …Run Code Online (Sandbox Code Playgroud) fosuserbundle ×10
symfony ×8
php ×2
modal-dialog ×1
passwords ×1
remember-me ×1
session ×1
sonata-admin ×1
subdomain ×1
symfony-2.1 ×1
validation ×1