我想转移到Symfony2,因为它的现代性和良好的编程给我留下了深刻的印象.
现在我从我的旧系统中获取一个用户表,有10,000个用户,我不想通过让他们设置一个新密码来激怒他们....所以我希望他们能够使用他们的旧密码登录
下面是我的用户表如何看起来像有关登录/注册的3个主要字段的伪代码:
id, int(10) unsigned NOT NULL
username varchar(40) NOT NULL
passhash varchar(32) NOT NULL
secret varchar(20) NOT NULL
Run Code Online (Sandbox Code Playgroud)
在注册时,数据以这种方式生成:
$secret = mksecret ();
$passhash = md5 ($secret . $password_formfield . $secret);
Run Code Online (Sandbox Code Playgroud)
在登录时,以下列方式检查数据:
if ($row['passhash'] != md5 ($row['secret'] . $password_formfield . $row['secret']))
{
//show login error
}
Run Code Online (Sandbox Code Playgroud)
那么如何在FOSUserBundle中最好地处理它,而不必编辑太多文件?
我正在使用FOSUserBundle,我需要能够从2个不同的路由(或更多)登录.这些路线将具有不同的模板,并且还会登录到不同的区域.登录之间唯一不同的是所需的权限.路线将是符合的路线
site.com/login
site.com/admin/login
还有可能是site.com/ajax_login
我已经能够通过从FOSUserBundle login.html.twig(被覆盖)中删除除CSRF令牌之外的所有内容,然后创建呈现自己的登录框和登录路径的路由,来研究如何获取不同的模板. (这样只会渲染CSRF令牌).这不适用于admin/login,因为表单会回发登录,如果失败则会显示该页面.
有没有简单的方法来实现这一目标?
我正在使用Symfony 2.1作为项目,使用FOSUserBundle来管理用户.
我正在尝试自定义更改密码表单,但我无法很好地显示错误消息.实际上,当输入错误填充时,在标签和输入之间打印错误消息(具有列表结构).但我喜欢在输入之后或之下显示它.
此外,我想在设置页面中显示我的更改密码表单,因此我需要显示其他一些表单.如何将此表单集成到页面中的精确位置?
在此先感谢,Valentin
我真的很紧张,因为缺少足够的资源来安装SonataDoctrineMongoDBAdminBundle以及它的依赖项如sonataUserBundle.我一直试图安装这个捆绑包15天.我做了各种各样的agaian,并再次在奏鸣曲的官方页面中讲述了什么.但它不能正常工作.在将sonataUserBundle扩展为ApplicationUserBundle之后,我的最终文档是:
user.php的
<?php
/**
* This file is part of the <name> project.
*
* (c) <yourname> <youremail>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Application\Sonata\UserBundle\Document;
use Sonata\UserBundle\Document\BaseUser as BaseUser;
/**
* This file has been generated by the EasyExtends bundle ( http://sonata-project.org/bundles/easy-extends )
*
* References :
* working with object : http://www.doctrine-project.org/docs/mongodb_odm/1.0/en/reference/working-with-objects.html
*
* @author <yourname> <youremail>
*/
class User extends …Run Code Online (Sandbox Code Playgroud) symfony fosuserbundle symfony-sonata sonata-admin sonata-user-bundle
我正在尝试在FOSUserBundle上实现事件
<?php
namespace EasyApp\UserBundle\Service;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Doctrine\Bundle\DoctrineBundle\Registry as Doctrine;
use EasyApp\UserBundle\Entity\UserLogin;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\FormEvent;
use FOS\UserBundle\FOSUserBundle;
class LoginManager implements EventSubscriberInterface
{
/** @var \Symfony\Component\Security\Core\SecurityContext */
private $securityContext;
/** @var \Doctrine\ORM\EntityManager */
private $em;
/**
* Constructor
*
* @param SecurityContext $securityContext
* @param Doctrine $doctrine
*/
public function __construct(SecurityContext $securityContext, Doctrine $doctrine)
{
$this->securityContext = $securityContext;
$this->em = $doctrine->getEntityManager();
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
{
return array(
FOSUserEvents::SECURITY_IMPLICIT_LOGIN => 'onSecurityImplicitLogin',
FOSUserEvents::REGISTRATION_COMPLETED=> 'onRegistrationCompleted' …Run Code Online (Sandbox Code Playgroud) 我有一个使用FosOauth2Serverbundle,FosRestBundle和FosUserBundle在Symfony2中编写的RESTful Api.我计划在我的api前面涂清漆作为反向代理.由于我的应用程序使用我的api总是发送access_token作为参数或标头清漆缓存几乎每个请求作为不同的请求,它是无效的.因为我在我的控制器中使用access_token的用户来保证安全性,有时用于内容,所以我无法从vcl_recv中的请求中完全删除access_token请求.在互联网上进行了几次搜索之后,我遇到了一个身份验证解决方案http://www.adayinthelifeof.nl/2012/07/06/using-varnish-to-offload-and-cache-your-oauth-requests/.但是,我无法弄清楚如何告诉FosUserBundle当前用户在header中传递security.yml中的安全性:
access_control:
- { path: ^/2013-08-30/foo$, role: ROLE_USER, requires_channel: https, methods: [GET] }
Run Code Online (Sandbox Code Playgroud)
简而言之,我怎样才能告诉FosUserBundle当前用户的请求(从清漆发送)标头?
varnish symfony oauth-2.0 fosuserbundle fosoauthserverbundle
我遇到了关于FOSUserBundle最重要的可能性的无数问题,并且在使用Twig的继承机制时发现了一些"设计不连贯",我想澄清一下,因为它在某些项目中真的令人不安......
从我读过的内容来看,我们应该如何覆盖模板.比方说,登录模板(Security/login.html.twig).首先,我需要覆盖全局FOSUser布局(layout.html.twig').
全球FOSUser布局
{% extends "::layout.html.twig" %}
{% block title %}Page title{% endblock title %}
{% block body %}
<div id="container">
{% block fos_user_content %}{% endblock %}
</div>
{% endblock body %}
Run Code Online (Sandbox Code Playgroud)
在title和body块到HTML引用<title>和<body>标签(全球).现在,谈到登录本身,这就是我写的内容.
登录表格
{% extends "MyUserBundle::layout.html.twig" %}
{% block fos_user_content %}
{% if error %}
<div class="error">{{ error|trans({}, 'FOSUserBundle') }}</div>
{% endif %}
<form action="{{ path("fos_user_security_check") }}" method="post">
<input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />
<label …Run Code Online (Sandbox Code Playgroud) 我正在为我的JS驱动的应用程序制作REST API.
在登录期间,登录表单通过AJAX提交到/rest/login我的API的url .
虽然我已经为API和应用程序本身分离了防火墙,但它们共享相同的上下文,这应该意味着,当用户对API进行身份验证时,他也会针对应用程序进行身份验证.因此,当服务器返回204时,页面将重新加载,它应该将用户重定向到应用程序,因为他现在已登录.
我试图使用check_loginFOSUserBundle的预制页面并指向/rest/login那里.
login:
path: /rest/login
defaults:
_controller: FOSUserBundle:Security:check
methods: [ POST ]
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为它总是返回重定向,无论如何.我阅读了symfony的文档,找不到如何制作自定义check_login页面.我需要的是这样的事情
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use FOS\RestBundle\Controller\Annotations\View;
class SecurityController {
/**
* @View(statusCode=204)
*/
public function loginAction($username, $password) {
/* first I need to somehow authenticate user
using normal authentication, that I've set up */
...
/* Then I need to return 204 or throw exception,
based on result.
This is done using FOSRestBundle and it's …Run Code Online (Sandbox Code Playgroud) php restful-authentication symfony fosuserbundle fosrestbundle
在我的symfony 2.7应用程序中,我有基于FOSUserBundle的用户实体.必须连接用户才能访问addAction()表单.
我的用户实体与另一个名为parc的实体链接.这是我的两个实体的代码.
Users.php
class Users extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
$this->parcs = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="Parcs", inversedBy="users")
* @ORM\JoinTable(name="users_parcs",
* joinColumns={
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="parc_id", referencedColumnName="id")
* }
* )
*/
private $parcs;
/**
* Get parcs
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getParcs()
{
return $this->parcs;
}
/**
* Set parcs …Run Code Online (Sandbox Code Playgroud) 我有一个非常类似的问题:Symfony记住我不工作,浏览器重启时cookie被销毁
不幸的是,他们的解决方案并没有在Symfony 4中修复它.
用户登录后,将创建cookie"REMEMBERME".如果我重新启动浏览器,我仍然可以看到我的cookie,但是当我访问安全性下的页面时IS_AUTHENTICATED_REMEMBERED,它不起作用,我被重定向到登录页面,然后销毁cookie并且用户必须再次登录.
我一直在开发官方文档中解释的身份验证过程(实际上,没有花哨的定制,没有FOSUSERBUNDLE).
您可以在文档中找到我的service.yaml
security:
encoders:
App\Entity\User:
algorithm: bcrypt
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
in_memory: { memory: ~ }
our_db_provider:
entity:
class: App\Entity\User
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
http_basic: ~
provider: our_db_provider
anonymous: ~
form_login:
login_path: login
check_path: login
default_target_path: dashboard
remember_me:
secret: '%kernel.secret%'
lifetime: 604800 # 1 week in seconds
path: /
secure: true
name: REMEMBERME
remember_me_parameter: _remember_me
logout:
path: /logout
target: /
secured_area:
form_login:
csrf_token_generator: security.csrf.token_manager
provider: …Run Code Online (Sandbox Code Playgroud) fosuserbundle ×10
symfony ×9
php ×6
forms ×2
cookies ×1
events ×1
many-to-many ×1
md5 ×1
oauth-2.0 ×1
overriding ×1
passwords ×1
sonata-admin ×1
symfony4 ×1
twig ×1
varnish ×1