我想转移到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
我从头开始了一个Symfony2项目,然后安装了FOSUserBundle.
然后,我编写了(实际上,使用ORM Designer生成)一些需要在它们之间以及与User实体之间建立关系的实体.
我Items属于Users,Collections属于Users该组Items,等等.
由于我使用了FOSUserBundle,我只有一个基本的用户类(https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md,步骤3a),使用注释定义,没有config/doctrine文件夹,也没有User.yml文件.
然后我创建了MyBundle/Resources/config/doctrine文件夹并添加了yml上面提到的文件.
当我尝试使用命令行工具生成实体时,一切正常:它将从我的yml文件创建实体.
然而,在这一点上,试图加载在浏览器在登录以前工作时(我只用了网址FOSUserBundle安装)将抛出这个错误:
MappingException:没有为类'X\MyBundle\Entity\User'找到名为'/var/www/concert/src/X/MyBundle/Resources/config/doctrine/User.orm.yml'的映射文件.
只要*.orm.ym文件config/doctrine夹中有l文件,以下操作(例如生成CRUD逻辑)将无法工作.如果我删除它们,CRUD生成将工作,但生成实际的mysql表不会.
玩弄这些让我到了一个点,我也可以得到表,但如果我尝试使用新生成的CRUD所涉及的任何url,那么实际的应用程序不起作用,因为实体基于yml(我删除它以使事情"工作")它将没有任何映射知识.
这本质上是错误的吗?要使基于yml的实体与基于FOSUserBundle的用户实体相关联,并且仍然能够获得漂亮的命令行生成工具?
我真的很紧张,因为缺少足够的资源来安装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) 如何从Facebook Connect获取正确的用户数据,如配置文件图片(当前返回null),名字和姓氏(似乎现在只是实现全名)?
facebook facebook-graph-api symfony fosuserbundle hwioauthbundle
我有一个使用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
我正在为我的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记住我不工作,浏览器重启时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 ×5
cookies ×1
doctrine-orm ×1
events ×1
facebook ×1
md5 ×1
oauth-2.0 ×1
passwords ×1
sonata-admin ×1
symfony4 ×1
varnish ×1