Ejemplo n.º 1
0
 public function load(ObjectManager $manager)
 {
     $role = new Role();
     $role->setName('IS_AUTHENTICATED_ANONYMOUSLY');
     $manager->persist($role);
     $manager->flush();
     $role = new Role();
     $role->setName('ROLE_USER');
     $manager->persist($role);
     $manager->flush();
     $role = new Role();
     $role->setName('ROLE_ADMIN');
     $manager->persist($role);
     $manager->flush();
     $user = new User();
     $user->setEmail('test-1');
     $user->setSalt(md5(time()));
     $user->setIsActive(true);
     $user->getUserRoles()->add($role);
     $encoder = new MessageDigestPasswordEncoder('sha1', true, 10);
     $password = $encoder->encodePassword('admin', $user->getSalt());
     $user->setPassword($password);
     $manager->persist($user);
     $manager->flush();
 }
Ejemplo n.º 2
0
 public function createAction()
 {
     $manager = $this->getDoctrine()->getEntityManager();
     $role = new Role();
     $role->setName('ROLE_ADMIN');
     $manager->persist($role);
     $user = new User();
     $user->setUsername('test');
     $user->setSalt(md5(time()));
     $user->setIsActive(true);
     //$user->setRole('ROLE_ADMIN');
     // шифрует и устанавливает пароль для пользователя,
     // эти настройки совпадают с конфигурационными файлами
     $user->getUserRoles()->add($role);
     $encoder = new MessageDigestPasswordEncoder('sha1', true, 10);
     $password = $encoder->encodePassword('admin', $user->getSalt());
     $user->setPassword($password);
     $manager->persist($user);
     return new Response((string) print_r($user));
     //$manager->flush();
 }