我正在尝试更改我的应用程序中的注册表单的模板,以便我可以添加一些其他HTML.这是/My/UserBundle/Resources/views/Registration/register.html.twig文件:
{% extends "MyUserBundle::layout.html.twig" %}
{% block fos_user_content %}
<section class="register site-content">
<header>
<h1>{{ 'layout.register'|trans({}, 'FOSUserBundle') }}</h1>
</header>
<div class="block">
{% include "FOSUserBundle:Registration:register_content.html.twig" %}
</div>
</section>
{% endblock fos_user_content %}
Run Code Online (Sandbox Code Playgroud)
我已成功覆盖layout.html.twig:
{% extends 'MyMainBundle::layout.html.twig' %}
{% block title %}{{ site_name }}{% endblock %}
{% block content %}
{% for key, message in app.session.getFlashes() %}
<div class="{{ key }}">
{{ message|trans({}, 'FOSUserBundle') }}
</div>
{% endfor %}
{% block fos_user_content %}{% endblock %}
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
以及form.html.twig:
{% extends 'FOSUserBundle::form.html.twig' %} …
Run Code Online (Sandbox Code Playgroud) 有谁知道如何扩展FOSUserBundle中的Mailer类?
我正在实施一个非常基本的父母电子邮件检查(所有验证都在表单上完成,以强制输入父母的电子邮件),如果在用户实体上填充了父电子邮件字段,那么它应该将电子邮件发送到该地址而不是用户的电子邮件.
到目前为止,我已尝试过以下内容:
namespace SSERugby\UserBundle\Mailer;
use FOS\UserBundle\Mailer\Mailer as BaseMailer;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\Routing\RouterInterface;
class Mailer extends BaseMailer
{
public function sendConfirmationEmailMessage(UserInterface $user)
{
$email = $user->getEmail();
$parentEmail = $user->getParentEmail();
if(isset($parentEmail)&&(trim($parentEmail)!='')){
$email = $parentEmail;
}
$template = $this->parameters['confirmation.template'];
$url = $this->router->generate('fos_user_registration_confirm', array('token' => $user->getConfirmationToken()), true);
$rendered = $this->templating->render($template, array(
'user' => $user,
'confirmationUrl' => $url
));
$this->sendEmailMessage($rendered, $this->parameters['from_email']['confirmation'], $email);
}
}
Run Code Online (Sandbox Code Playgroud)
它似乎只是忽略被覆盖的类并使用默认值,我已经在测试之前清除了缓存.
谢谢
我创建了自己的用户Bundle,扩展了FOSUserBundle.
在我的UserBundle中,我有一个memberID字段,带有setter和getter.
我已经可以使用EntityManager通过memberID找到用户,然后我可以通过UserManager找到用户匹配用该EntityManager查询获得的用户名/ email/...但是...
有没有办法使用UserManager查找UserByMemberID?
谢谢.
当我创建一个将用于研究健康领域患者的Web应用程序时,我希望我的所有用户都是完全匿名的.我是否可以通过简单的方式摆脱email和email_canonical字段而无需在包本身中重写内容,例如通过在我自己的包中对我的User Class执行某些操作?
编辑:我做了这个:
/**
* @ORM\Column(nullable=true)
**/
protected $email;
/**
* @ORM\Column(nullable=true)
**/
protected $emailCanonical;
Run Code Online (Sandbox Code Playgroud)
在我的用户实体类中.Bu twhen我做php app/console doctrine:schema:update --force我得到
[Doctrine\ORM\Mapping\MappingException] 在字段或鉴别器列映射中
实体'Pan100\MoodLogBundle\Enti
ty\User' 上的列'email'的重复定义.
编辑2:忘了说这是在扩展FOUserBundle的模型类User作为BaseUser的类中完成的...
我安装了FOS Userbundle来学习它,但我决定不再需要它了.然后我做了以下删除它.删除后,我运行作曲家更新.
现在当我尝试清除生产模式的缓存时,我得到以下错误.在开发模式下清除缓存工作正常.
可以告诉我我做错了什么或我缺少什么来删除FOS用户包并能够在生产模式中清除缓存?
PHP Fatal error: Class 'FOS\UserBundle\EventListener\LastLoginListener' not found in /var/www/html/HealthFitness/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php on line 142
PHP Stack trace:
PHP 1. {main}() /var/www/html/HealthFitness/app/console:0
PHP 2. Symfony\Component\Console\Application->run() /var/www/html/HealthFitness/app/console:27
PHP 3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /var/www/html/HealthFitness/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:121
PHP 4. Symfony\Component\DependencyInjection\Container->get() /var/www/html/HealthFitness/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:86
PHP 5. appProdProjectContainer->getEventDispatcherService() /var/www/html/HealthFitness/app/bootstrap.php.cache:2037
PHP 6. Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher->addSubscriberService() /var/www/html/HealthFitness/app/cache/prod/appProdProjectContainer.php:343
Run Code Online (Sandbox Code Playgroud) production-environment clear-cache removeall symfony fosuserbundle
我使用Symfony2和FOSUserBundle.
我想防止登录页面上的暴力攻击.
为此我在事件上创建了一个监听器:
AuthenticationEvents::AUTHENTICATION_FAILURE
Run Code Online (Sandbox Code Playgroud)
除了IP,我还想获得用户在尝试登录时传递的"用户名".通过这种方式,我可以获得一些黑客试图入侵该帐户的用户.同时考虑到同一个IP可以属于多个用户,我可以通过这种方式进行区分,如果我在一秒钟内获得5次尝试,如果我真的面临攻击,或者只是有5个用户大致同时无法进行身份验证(但也许是"背后"那个地址有150个用户,所以它可以发生;)).
有什么方法可以获得表单中传递的用户名吗?
当然,在记录IP,用户名和时间戳之后,我需要实现将可疑IP添加到黑名单表的部分.然后,我将决定是否实施选民,或禁止IP我的应用程序编写Apache配置文件.
谢谢!
我试图在用户登录FOSUserBundle后执行一个函数,在我的config.yml中我设置了服务:
services:
authentication.success.listener:
class: MyCompany\MyBundle\EventListener\AuthenticationEventListener
arguments: [@router]
tags:
- { name: kernel.event_subscriber }
Run Code Online (Sandbox Code Playgroud)
然后,我用方法创建Listener类:
<?php
namespace MyCompany\MyBundle\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\UserEvent;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Cookie as Cookie;
class AuthenticationEventListener implements EventSubscriberInterface
{
private $router;
public function __construct(UrlGeneratorInterface $router)
{
$this->router = $router;
}
public static function getSubscribedEvents()
{
return array(
FOSUserEvents::SECURITY_IMPLICIT_LOGIN => 'onAuthenticationSuccess',
);
}
public function onAuthenticationSuccess(UserEvent $event)
{
//my actions goes here...
}
}
?>
Run Code Online (Sandbox Code Playgroud)
当我尝试登录时,之后没有任何反应,我写了一些错误的代码来生成异常,但一切顺利......显然这个功能并没有被排除在外.
有什么帮助吗?
我是Symfony2的新手,后来是FOSUserBundle.我理解捆绑包是什么以及使用它的内容但是我对如何使用捆绑包与我已经存在的视图和控制器相关联有疑问.
我已经设置了捆绑包并让它工作但我对下一个任务感到困惑.
设置:在FOSUserBundle的登录页面上,我希望将"管理员用户"路由到某个页面,将"普通用户"路由到另一个页面.我在哪里放置这个逻辑?我目前在我的捆绑包的DefaultController中有它但得到页面:localhost isn't working...localhost redirected you too many times...
我清除了缓存但仍然是相同的结果.
DefaultController:
namespace Pas\ShopTestBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
class DefaultController extends Controller
{
/**
* @Route("/")
* @Template()
*/
public function indexAction(Request $request) {
if ('admin_login' === $request->get('_route')) {
return $this->redirectToRoute('product'); //just test to product
} else {
return $this->redirectToRoute('login'); //just test to login
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我的ULTIMATE目标是,一旦用户登录,就会在他们发送到的页面上显示他们的用户名.我该如何编码呢?它去哪儿了?
我非常感谢你的帮助,谢谢大家.
Symfony 2.7:FOSUserBundle 2.0
编辑:security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
ROLE_ADMIN: ROLE_ADMIN
ROLE_NORMAL: ROLE_NORMAL
# http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
providers: …
Run Code Online (Sandbox Code Playgroud) 嗨,我正在尝试在我的自定义模板中包含FOSUser Bundle的登录表单.像那样:
{% include 'FOSUserBundle:Security:login.html.twig' %}
Run Code Online (Sandbox Code Playgroud)
但我有这个错误:
Variable "error" does not exist in FOSUserBundle:Security:login.html.twig at line 7
有没有办法在我的控制器中添加一些内容而不包含模板?
我们有一个Symofny 2.8应用程序,在服务场所,我们使用OS \ UserBundle \ Util \ LegacyFormHelper中的LegacyFormHelper。
看来,在实际的更新中该类已删除,我想知道为什么。
所以实际上,我正在寻找在FormType中使用RepeatedType的可能性,该代码类似于
->add('plainPassword', LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\RepeatedType'), array(
'type' => LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\PasswordType'),
'options' => array('translation_domain' => 'FOSUserBundle'),
'first_options' => array('label' => 'form.password', 'attr' => array('placeholder' => 'Passwort')),
'second_options' => array('label' => 'form.password_confirmation'),
'invalid_message' => 'fos_user.password.mismatch',
'required' => false
))
Run Code Online (Sandbox Code Playgroud)
现在,我们要在没有LegacyFormHelper的情况下进行编码。
有想法吗?
问候托马斯
fosuserbundle ×10
symfony ×10
php ×2
twig ×2
brute-force ×1
clear-cache ×1
doctrine-orm ×1
extending ×1
findby ×1
removeall ×1
symfony-2.3 ×1