我想在FOSUserBundle(Symfony2)中创建一个新用户,但我总是得到相同的消息(我正在使用php app/console fos:user:create
):
没有为帐户"MyProject\UserBundle\Entity\User"配置编码器.
进口顺序正确
public function registerBundles()
{
$bundles = array(
//...
new MyProject\UserBundle\MyProjectUserBundle(),
new FOS\UserBundle\FOSUserBundle(),
);
Run Code Online (Sandbox Code Playgroud)
安全文件:
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
Run Code Online (Sandbox Code Playgroud)
但我总是得到同样的错误......你知道如何解决这个问题吗?这里的解决方案 对我不起作用
谢谢
我想在FOSUserBundle / profile/edit上激活电子邮件确认
在/ profile/edit中,您已经登录,您可以编辑用户名或输入当前密码的电子邮件地址.现在我想发送一封确认电子邮件,如果用户编辑电子邮件地址:)
在FOSUserBundle配置参考中我没有找到设置来执行此操作... https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/configuration_reference.md
这些是我目前的设置:
fos_user:
db_driver: orm
firewall_name: main
user_class: Acme\CoreBundle\Entity\User
registration:
confirmation: { enabled: true }
from_email:
address: noreply@%domain%
sender_name: %site_name% Staff
resetting:
token_ttl: %reset_password_ttl%
Run Code Online (Sandbox Code Playgroud)
有人可以帮帮我吗?
我尝试使用以下命令从命令窗口创建具有FOsUserBundle的管理员用户:
php app/console fos:user:create
Run Code Online (Sandbox Code Playgroud)
在我的项目中,管理员用户以强制性的方式扩展其他用户.所以,当我选择用户名,邮件和密码时,它会告诉我:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'latitude' cannot be null
Run Code Online (Sandbox Code Playgroud)
如何在AdminUser中设置值"latitude"?我也使用PUGXMultiUserBundle.
我正在尝试使用Symfony2和FOSRestBundle来构建一个REST框架,而我却失败了.
我做了以下事情:
在我的deps文件中:
[FOSRest]
git=git://github.com/FriendsOfSymfony/FOSRest.git
target=fos/FOS/Rest
[FOSRestBundle]
git=git://github.com/FriendsOfSymfony/FOSRestBundle.git
target=bundles/FOS/RestBundle
[JMSSerializerBundle]
git=git://github.com/schmittjoh/JMSSerializerBundle.git
target=bundles/JMS/SerializerBundle
Run Code Online (Sandbox Code Playgroud)
在我的apps/config.yml中
fos_rest:
view:
formats:
rss: true
xml: false
templating_formats:
html: true
force_redirects:
html: true
failed_validation: HTTP_BAD_REQUEST
default_engine: twig
sensio_framework_extra:
view:
annotations: false
Run Code Online (Sandbox Code Playgroud)
在我的控制器中:
namespace Rest\WebServiceBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use FOS\RestBundle\View\View;
class DefaultController extends Controller
{
public function indexAction($name)
{
$view = View::create()
->setStatusCode(200)
->setData($name);
return $this->get('fos_rest.view_handler')->handle($view);
}
}
Run Code Online (Sandbox Code Playgroud)
当我转到URL:http://local.symfony.com/web/app_dev.php/hello/test
我明白了:
Unable to find template "".
500 Internal Server Error - InvalidArgumentException
2 linked Exceptions: Twig_Error_Loader » …
Run Code Online (Sandbox Code Playgroud) 我很难覆盖Symfony2使用的FOS用户包所使用的标签.
我已经覆盖了Form类,但是没有像"setOption"这样的元素的选项,只有getter.
我可以删除一个元素,然后用适当的标签再次添加它,但这似乎是一种矫枉过正.是否有任何好的方法可以覆盖表单元素或者只是翻译键?
我会用FOSUserBundle为Symfony2写一个测试.
目前我尝试了一些方法,没有人工作.
我需要一个像"createAuthClient"这样的函数.
这是我的基础课.我发布它是因为你可以更好地理解我的问题.
<?php
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\BrowserKit\Cookie;
class WebTestMain extends WebTestCase
{
protected static $container;
static protected function createClient(array $options = array(), array $server = array())
{
$client = parent::createClient($options, $server);
self::$container = self::$kernel->getContainer();
return $client;
}
static function createAuthClient(array $options = array(), array $server = array())
{
// see lines below with my tries
}
}
Run Code Online (Sandbox Code Playgroud)
第一次尝试:
if(static::$kernel === null)
{
static::$kernel = static::createKernel($options);
static::$kernel->boot();
}
if(static::$container === null)
{
self::$container = self::$kernel->getContainer();
}
$parameters …
Run Code Online (Sandbox Code Playgroud) 我想在注册之后将用户重定向到另一个表单,然后才能访问我网站上的任何内容(例如https://github.com/FriendsOfSymfony/FOSUserBundle/issues/387).
所以我在doc中创建了一个eventListener:
<?php
namespace rs\UserBundle\EventListener;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\UserEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
/**
* Listener responsible to change the redirection at the end of the password resetting
*/
class RegistrationConfirmedListener implements EventSubscriberInterface
{
private $router;
public function __construct(UrlGeneratorInterface $router)
{
$this->router = $router;
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
{
return array(
FOSUserEvents::REGISTRATION_CONFIRMED => 'onRegistrationConfirmed'
);
}
public function onRegistrationConfirmed()
{
$url = $this->router->generate('rsWelcomeBundle_check_full_register');
$response = new RedirectResponse($url);
return $response;
}
} …
Run Code Online (Sandbox Code Playgroud) 在FOUserBundle中,我希望能够更改最小长度,最大长度的验证设置,而不是用户名和密码等字段的空白.
我能够@Assert
在我的自定义字段上进行一些验证,但现在我想知道如何更改FOSUserBundle的用户名验证?
这些字段是自动生成的,所以我无法将它们添加到我的User
实体中......默认情况下,它允许像{^|
...等字符看起来不太好.
我遵循以下文档:https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_templates.rst
我选择创建一个子捆绑和覆盖模板,所以在我的捆绑中
class MyBundle extends Bundle
{
//declare bundle as a child of the FOSUserBundle so we can override the parent bundle's templates
public function getParent()
{
return 'FOSUserBundle';
}
}
Run Code Online (Sandbox Code Playgroud)
在我的包中,我添加了以下文件
MyBundle
\Resources
\views
\Security
login.html.twig
Run Code Online (Sandbox Code Playgroud)
匹配文档中提到的FOS捆绑结构
login.html.twig
{% extends 'AnotherBundle::layout.html.twig' %}
{% block title %}Log In{% endblock %}
{% block content %}
{% block fos_user_content %}{% endblock %}
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
当我进入登录页面时,我的标题加载正常,但是没有登录表单,出错了什么?
编辑:请参阅下面的我自己的解决方案,在撰写本文时,它正在运作但不完美.我会喜欢一些批评和反馈,如果我把一些我觉得非常可靠的东西放在一起,那么我会为面临同样挑战的其他人制作一篇howto博客文章.
几天来我一直在努力奋斗,如果我走在正确的道路上,我希望有人能告诉我.
我有一个带有FOSRestBundle webservice的系统,我正在使用FOSUserBundle和HWIOAuthBundle来验证用户.
我想为webservice设置无状态api密钥身份验证.
我已经阅读了http://symfony.com/doc/current/cookbook/security/api_key_authentication.html,这看起来很简单,我已经安装了UecodeApiKeyBundle,这似乎只是本书页面的一个实现.
我的问题是n00b ...现在怎么样?书籍页面和包都涵盖了通过API密钥对用户进行身份验证,但不涉及日志用户流,生成API密钥,允许用户注册等.我真正想要的是用于登录的简单API端点,注册,以及我的应用开发者可以使用的注销.像/ api/v1/login等等.
我想我可以处理注册....虽然登录让我感到困惑.根据一些额外的阅读,在我看来,我需要做的登录是这样的:
在api/v1/login创建一个接受POST请求的控制器.请求看起来像{_username:foo,_ password:bar}或类似{facebook_access_token:foo.或者,facebook登录可能需要不同的操作,例如/ user/login/facebook,并且只需重定向到HWIOAuthBundle路径}.
如果请求包含_username和_password参数,那么我需要将请求转发到login-check(我不确定这个.我可以自己处理这个表单吗?或者,我应该手动检查用户名和密码数据库?)
添加一个登录事件监听器,如果用户认证成功,则为用户生成一个api密钥(当然,如果我自己没有检查它,这是必要的)
在POST请求的响应中返回API密钥(这会打破post-redirect-get策略,但是我没有看到任何问题)我认为这消除了上面列出的重定向登录检查选项.
你可能会看到我很困惑.这是我的第一个Symfony2项目,关于安全的书页很简单......但似乎掩盖了一些细节,这使我不确定要采取的方法.
提前致谢!
================================================== ===========
编辑:
我已经安装了API密钥身份验证,与相关的相关菜谱文章完全相同:http://symfony.com/doc/current/cookbook/security/api_key_authentication.html
为了处理用户的登录,我创建了一个自定义控制器方法.我怀疑这是完美的,我很乐意听到一些关于如何改进它的反馈,但我相信我正走在正确的道路上,因为我的流程正在发挥作用.这是代码(请注意,还在开发的早期......我还没有看过Facebook登录,只有简单的用户名/密码登录):
class SecurityController extends FOSRestController
{
/**
* Create a security token for the user
*/
public function tokenCreateAction()
{
$request = $this->getRequest();
$username = $request->get('username',NULL);
$password = $request->get('password',NULL);
if (!isset($username) || !isset($password)){
throw new BadRequestHttpException("You must pass username and password fields");
}
$um = $this->get('fos_user.user_manager');
$user = $um->findUserByUsernameOrEmail($username);
if (!$user instanceof \Acme\UserBundle\Entity\User) …
Run Code Online (Sandbox Code Playgroud) fosuserbundle ×10
symfony ×10
php ×2
admin ×1
cmd ×1
phpunit ×1
redirect ×1
rest ×1
unit-testing ×1
validation ×1