标签: fosuserbundle

登录后,FOSUserBundle从登录页面重定向

如果管理员用户或前端用户甚至在登录后尝试访问登录页面,我只是想要这样做

/admin/login (admin user) 
Run Code Online (Sandbox Code Playgroud)

要么

/login (front end user)
Run Code Online (Sandbox Code Playgroud)

那么他们应该像/admin或那样被重定向回相关的主页/

redirect login symfony fosuserbundle

30
推荐指数
3
解决办法
4万
查看次数

FOS UserBundle无法登录

关于我的UserBundle,我又回到了另一个问题:通过Symfony2安装和配置FOS捆绑包时,一切都很完美,它甚至让我创建了2个正确插入我的数据库的用户.

但是,每次我尝试登录这些帐户时,都会出现以下错误

Warning: Erroneous data format for unserializing 'VillaPrivee\UserBundle\Entity\User' in /Users/Vianney/Projets/VillaPrivee/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php line 869
Run Code Online (Sandbox Code Playgroud)

这就是869行所指的:

/**
     * Creates a new instance of the mapped class, without invoking the constructor.
     *
     * @return object
     */
    public function newInstance()
    {
        if ($this->_prototype === null) {
            $this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
        }

        return clone $this->_prototype;
    }
Run Code Online (Sandbox Code Playgroud)

这是我的用户实体:

namespace VillaPrivee\UserBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * …
Run Code Online (Sandbox Code Playgroud)

symfony doctrine-orm fosuserbundle

27
推荐指数
2
解决办法
1万
查看次数

Symfony 2.7/3 - Doctrine:您已请求不存在的服务"fos_user.doctrine_registry"

今天做作曲家更新突然收到以下错误:

[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]您已请求不存在的服务"fos_user.doctrine_registry".

当composer执行cache:clear --no-warmup命令时.

搜索找到了一个与从doctrine转换为MongoDB相关的答案,但解决方案对我不起作用.我在使用Doctrine.我试过Fosuserbundle dev-master,dev-master @ dev,2.0.0-alpha1和2.0.0-alpha3.

还有其他建议吗?几天前,Composer更新工作正常.

doctrine symfony fosuserbundle symfony-2.7 symfony-2.8

27
推荐指数
1
解决办法
1万
查看次数

在使用FOSUserBundle进行用户注册期间添加默认角色

版本:Symfony 2.2

当用户在我的网站上注册时,我正在尝试添加默认角色.我使用FOSUserBundle,我看到当用户注册角色字段在数据库中为空时.我从这个庞大的包开始,它不是很容易理解.所以我阅读了所有的文档,我不知道该怎么做.

现在,我创建一个事件来动态添加这个角色,但它不起作用(我没有错误,但我的数据库仍然是空的)我甚至不知道这是做这个的好方法吗?

我的活动:

use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\FormEvent;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class AddDefaultRoleListener implements EventSubscriberInterface {

  private $container;

  public function __construct(Container $container)
  {
    $this->container = $container;
  }

  /**
   * {@inheritDoc}
   */
  public static function getSubscribedEvents()
  {
    return array(
        FOSUserEvents::REGISTRATION_SUCCESS => 'onAddDefaultRoleSuccess',
    );
  }

  public function onAddDefaultRoleSuccess(FormEvent $event)
  {
    $doctrine = $this->container->get('doctrine');
    $em = $doctrine->getManager();

    $user = $event->getForm()->getData();
    $user->addRole('ROLE_USER');
    //$user->setRoles(array('ROLE_USER'));

    $em->persist($user);
  }
}
Run Code Online (Sandbox Code Playgroud)

如你所见,我创建一个简单的事件,听取REGISTRATION_SUCCESS,但似乎没有任何工作.这是我第一次尝试使用事件和服务.所以,如果有人有建议,我会接受:)

谢谢

symfony fosuserbundle

26
推荐指数
2
解决办法
3万
查看次数

您已请求不存在的服务"security.context"

我创建服务但它不起作用

services:
    redirectionListener:
          class: Front\EcommerceBundle\Listener\RedirectionListener
          arguments: ["@service_container","@session"]
          tags:
            - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
Run Code Online (Sandbox Code Playgroud)

这是我的课

namespace Front\EcommerceBundle\Listener;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;

class RedirectionListener
{
    public function __construct(ContainerBuilder $container, Session $session)
    {
        $this->session = $session;
        $this->router = $container->get('router');
        $this->securityContext = $container->get('security.context');
    }

    public function onKernelRequest(GetResponseEvent $event)
    {
        $route = $event->getRequest()->attributes->get('_route');

        if ($route == 'livraison' || $route == 'validation') {
            if ($this->session->has('panier')) {
                if (count($this->session->get('panier')) == 0)
                    $event->setResponse(new RedirectResponse($this->router->generate('panier')));
            }

            if (!is_object($this->securityContext->getToken()->getUser())) {
                $this->session->getFlashBag()->add('notification','Vous devez …
Run Code Online (Sandbox Code Playgroud)

php symfony fosuserbundle symfony-security

26
推荐指数
1
解决办法
1万
查看次数

FOSUserBundle - BadCredentialsException

我使用FOSUserBundle提供用户授权和注册.一切正常,但当我尝试使用不存在的用户名登录时,我收到此错误:

exception 'Symfony\Component\Security\Core\Exception\BadCredentialsException'
with message 'Bad credentials' in
/var/www/OnTheWay/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php:73
Stack trace:
#0 /var/www/OnTheWay/app/cache/dev/classes.php(120): session_start()
#1 /var/www/OnTheWay/app/cache/dev/classes.php(198): Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->start()
#2 /var/www/OnTheWay/app/cache/dev/classes.php(498): Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->getBag('attributes')
Run Code Online (Sandbox Code Playgroud)

我试过找到一个解决方案,但我没有得到任何结果.

php symfony fosuserbundle

24
推荐指数
1
解决办法
7102
查看次数

FOSUserBundle和Symfony 3.0?

FOSUserBundle可以与symfony 3一起使用吗?无法在其网站上看到有关该信息的任何信息.

我刚刚安装了Symfony 3的新副本,确实composer update已经尝试安装FOSUserBundle.

在控制台上接收不太友好的东西;)

composer require friendsofsymfony/user-bundle

  Problem 1
    - Conclusion: remove symfony/symfony v3.0.0
    - Conclusion: don't install symfony/symfony v3.0.0
    - friendsofsymfony/user-bundle v1.3.0 requires symfony/security-bundle 2.1.* -> satisfiable by symfony/security-bundle[v2.1.0, v2.1.1, v2.1.10, v2.1.11, v2.1.12, v2.1.13, v2.1.2, v2.1.3, v2.1.4, v2.1.5, v2.1.6, v2.1.7, v2.1.8, v2.1.9].
    - friendsofsymfony/user-bundle v1.3.1 requires symfony/security-bundle >=2.1,<2.3-dev -> satisfiable by symfony/security-bundle[v2.1.0, v2.1.1, v2.1.10, v2.1.11, v2.1.12, v2.1.13, v2.1.2, v2.1.3, v2.1.4, v2.1.5, v2.1.6, v2.1.7, v2.1.8, v2.1.9, v2.2.0, v2.2.1, v2.2.10, v2.2.11, v2.2.2, v2.2.3, v2.2.4, v2.2.5, v2.2.6, v2.2.7, …
Run Code Online (Sandbox Code Playgroud)

php symfony fosuserbundle composer-php

23
推荐指数
2
解决办法
1万
查看次数

检查密码并使用FOSUserBundle手动创建用户

我在我的应用程序中使用FOSUserBundle.我想通过HTTP服务做两件事:

  1. 检查密码.该服务可能如下所示(密码不会被加密):

    public function checkPasswordValidity($userId, $password) {
        $user = $this->getDoctrine()
            ->getRepository('MyCompany\UserBundle\Entity\User')
            ->find($userId);
    
        if (specialFunction($user , $password))
            echo 'Valid Password';
        else
            echo 'Invalid Password';
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. 通过其他HTTP服务创建新用户.参数将是用户名和密码.

passwords symfony fosuserbundle

22
推荐指数
2
解决办法
2万
查看次数

强制不要求字段

我正在使用Symfony2和FOSUserBundle.

正如文档中详述的那样,我已在User实体中覆盖并创建了"name"属性.

我做了所有必要的事情,最后让这个字段显示在表单视图中.

问题是:当我去form_widget(form.name)生成输入html标签时,会在其中生成required ="required"属性.这会导致引擎在未填充字段时将输入变为红色.

如何告诉Symfony2不要强制使用该字段?我猜它必须在这里:

        parent::buildForm($builder, $options);

    // add your custom field
    $builder->add('name', 'text', array('label' => 'form.name'));
    $builder->remove('username');
Run Code Online (Sandbox Code Playgroud)

或者在这里:

    /**
 * @ORM\Column(type="string", length="255")
 *
 * @Assert\MinLength(limit="0", message="The name is too short.", groups={"Registration", "Profile"})
 * @Assert\MaxLength(limit="255", message="The name is too long.", groups={"Registration", "Profile"})
 */
private $name;
Run Code Online (Sandbox Code Playgroud)

php symfony fosuserbundle

21
推荐指数
1
解决办法
3万
查看次数

忘记密码功能fosuserbundle

我已经谷歌搜索了几个小时,无法找到有关如何在FOSUserBundle中实现"忘记密码"功能的任何信息

这是捆绑的一部分还是我必须自己创建的东西.

fosuserbundle symfony-2.3

21
推荐指数
1
解决办法
3万
查看次数