Exemple #1
0
 public function load(ObjectManager $manager)
 {
     $encoder = new MessageDigestPasswordEncoder('sha512', true, 10);
     $admin = new User();
     $admin->setUsername('messi');
     // On cré un salt pour amélioré la sécurité
     $admin->setPassword($encoder->encodePassword('admin', $admin->getSalt()));
     $admin->setEmail('*****@*****.**');
     $admin->setRoles(array('ROLE_ADMIN'));
     $admin->setEnabled(true);
     $user = new User();
     $user->setUsername('louis');
     // On cré un salt pour amélioré la sécurité
     $user->setPassword($encoder->encodePassword('michel', $user->getSalt()));
     $user->setEmail('*****@*****.**');
     $user->setRoles(array('ROLE_AUTEUR'));
     $user->setEnabled(true);
     $validPassword = $encoder->isPasswordValid($user->getPassword(), 'michel', $user->getSalt());
     if ($validPassword) {
         $manager->persist($admin);
         $manager->persist($user);
     }
     // On déclenche l'enregistrement
     $manager->flush();
 }
Exemple #2
0
 public function load(ObjectManager $manager)
 {
     // Liste des noms de catégorie à ajouter
     $role_employe = new Role("ROLE_EMPLOYE");
     $manager->persist($role_employe);
     $manager->flush();
     $role_gestionnaire = new Role("ROLE_GESTIONNAIRE");
     $manager->persist($role_gestionnaire);
     $manager->flush();
     $role_admin = new Role("ROLE_ADMIN");
     $manager->persist($role_admin);
     $manager->flush();
     $role_superadmin = new Role("ROLE_SUPER_ADMIN");
     $manager->persist($role_superadmin);
     $manager->flush();
     $user = new User();
     $user->setNom("Njomo Rostand");
     $user->setVilleResidence("Yaounde");
     $user->setNoPieceIdent("123456789");
     $user->setPoste("Stagiare");
     $user->setUsername("rostand");
     $user->setSalt(md5(time()));
     $encoder = new MessageDigestPasswordEncoder('sha512', true, 10);
     $password = $encoder->encodePassword('rostand', $user->getSalt());
     $user->setPassword($password);
     $user->addRole($role_employe);
     $manager->persist($user);
     $manager->flush();
     $user = new User();
     $user->setNom("Marlone NJ");
     $user->setVilleResidence("Douala");
     $user->setNoPieceIdent("9874563210");
     $user->setPoste("Gestionnaire de credit");
     $user->setUsername("marlone");
     $user->setSalt(md5(time()));
     $encoder = new MessageDigestPasswordEncoder('sha512', true, 10);
     $password = $encoder->encodePassword('marlone', $user->getSalt());
     $user->setPassword($password);
     $user->addRole($role_gestionnaire);
     $manager->persist($user);
     $manager->flush();
     $user = new User();
     $user->setNom("Rostand  Nj");
     $user->setVilleResidence("Buea");
     $user->setNoPieceIdent("123456789");
     $user->setPoste("Dj internationnal");
     $user->setUsername("rostandnj");
     $user->setSalt(md5(time()));
     $encoder = new MessageDigestPasswordEncoder('sha512', true, 10);
     $password = $encoder->encodePassword('rostandnj', $user->getSalt());
     $user->setPassword($password);
     $user->addRole($role_admin);
     $manager->persist($user);
     $manager->flush();
 }