I want to create a new form for creating new users. I created my own AdminController
with these functions:
public function createNewUsersEntity()
{
return $this->container->get('fos_user.user_manager')->createUser();
}
public function prePersistUsersEntity(User $user)
{
$this->get('fos_user.user_manager')->updatePassword($user);
$this->container->get('fos_user.user_manager')->updateUser($user, false);
}
public function preUpdateUsersEntity(User $user)
{
$this->get('fos_user.user_manager')->updatePassword($user);
$this->container->get('fos_user.user_manager')->updateUser($user, false);
}
But the password is not being encrypted.
This is my config.yml
file:
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: AppBundle\Entity\User
use_listener: false
In my security.yml
file:
app/config/security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
always_use_default_target_path: true
default_target_path: /admin
failure_path: /
# if you are using Symfony < 2.8, use the following config instead:
# csrf_provider: form.csrf_provider
logout: true
anonymous: true
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
and this is the constructor from my User entity:
public function __construct()
{
parent::__construct();
}
On another hand, when a user is added to the system, I need it with ROLE_USER
role, but I don't know what to do for changing that.
Two Problems: Password is not encrypted and the role is not defined.