-1

I am trying to update the password for an user using EasyAdminBundle integrated with FOSUserBundle, I have followed the steps showed in the documentation but no luck... :(

I am able to update the username, email, enabled, but not the password, which I am setting in the Plain Password field.

Is there I am doing wrong or missing?

Thanks!

relez
  • 750
  • 2
  • 13
  • 28

2 Answers2

1

You also need to update your routing file :

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
Stéphane
  • 83
  • 1
  • 4
  • And something else to check : in security.yml, under providers, fos_userbundle, id: fos_user.user_provider.username_email to be able to log in both with username and email – Stéphane Oct 12 '16 at 14:58
0

Show some config code with user entity configuration.

In config.yaml I added code:

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'}

Then in AdminController(Admin controller is my own implementation, AdminController class extends EasyAdminController, this step is very important! All my code in AdminController file:

<?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);
    }
}

Now you should declare your new custom AdminController implementation in routing.yaml:

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

More info about overriding the Default AdminController

Good luck! :)

Krzysztof Raciniewski
  • 4,735
  • 3
  • 21
  • 42