-1

我正在尝试使用与 FOSUserBundle 集成的 EasyAdminBundle 更新用户的密码,我已按照文档中显示的步骤进行操作,但没有运气... :(

我可以更新已启用的用户名、电子邮件,但不能更新我在“纯密码”字段中设置的密码。

我做错了什么或失踪了吗?

谢谢!

4

2 回答 2

1

您还需要更新您的路由文件:

https://github.com/javiereguiluz/EasyAdminBundle/blob/master/Resources/doc/book/7-complex-dynamic-backends.md#customization-based-on-overriding-the-default-admincontroller

# app/config/routing.yml
    # resource: "@EasyAdminBundle/Controller/"           <-- REMOVE this line
    resource: "@AppBundle/Controller/AdminController.php" # <-- ADD this line
    type:     annotation
    prefix:   /admin
于 2016-10-12T14:49:03.463 回答
0

显示一些带有用户实体配置的配置代码。

在 config.yaml 我添加了代码:

entities:
  User:
    class: AppNg\Symfony\AuthBundle\Entity\User
    form:
      fields:
        - username
        - email
        - enabled
        - lastLogin
        - { property: 'plainPassword', type: 'text', type_options: { required: false } }
        - { property: 'roles', type: 'choice', type_options: { multiple: true, choices: { 'ROLE_USER': 'ROLE_USER', 'ROLE_ADMIN': 'ROLE_ADMIN' } } }
    label: 'Users list'
    edit:
      title: 'user_edit'
    new:
      title: 'add_new_user'
    list:
      title: 'users_list'
      actions:
        - {name: 'edit'}
        - {name: 'delete'}
      fields:
        - { property: 'id'}
        - { property: 'username'}
        - { property: 'email'}
        - { property: 'lastLogin'}
        - { property: 'locked'}
        - { property: 'enabled'}

然后在AdminController(Admin控制器是我自己的实现,AdminController类扩展EasyAdminController,这一步很重要!我在AdminController文件中的所有代码:

<?php

namespace AdminPanelBundle\Controller;

use JavierEguiluz\Bundle\EasyAdminBundle\Controller\AdminController as EasyAdminController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;

class AdminController extends EasyAdminController
{
    /**
     * @Route("/", name="easyadmin")
     * @param Request $request
     * @return   \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
     */
    public function indexAction(Request $request)
    {
        return parent::indexAction($request);
    }

    public function createNewUserEntity()
    {
        return $this->get('fos_user.user_manager')->createUser();
    }

    public function prePersistUserEntity($user)
    {
        $this->get('fos_user.user_manager')->updateUser($user, false);
    }

    public function preUpdateUserEntity($user)
    {
       $this->get('fos_user.user_manager')->updateUser($user, false);
    }
}

现在您应该在 routing.yaml 中声明新的自定义 AdminController 实现:

admin_panel:
    resource: "@AdminPanelBundle/Controller/"
    type:     annotation
    prefix:   /admin

有关覆盖默认 AdminController 的更多信息

祝你好运!:)

于 2016-10-13T08:46:03.267 回答