コード例 #1
0
ファイル: LoadUserData.php プロジェクト: sev28/flyaround_s2
 public function load(ObjectManager $em)
 {
     $factory = $this->getSecurityManager();
     $faker = $this->getFaker();
     // user romain
     $user1 = new User();
     $user1->addGroup($em->merge($this->getReference('group-admin')));
     $user1->setFirstname('Romain');
     $user1->setLastname('Coeur');
     $user1->setFirstname('Romain');
     $user1->setLastname('Coeur');
     $user1->setEmail('*****@*****.**');
     $user1->setUsername('romain');
     $user1->setEnabled(true);
     $user1->setSuperAdmin(true);
     $user1->setLocked(false);
     $this->addReference('user-romain', $user1);
     $encoder = $factory->getEncoder($user1);
     $encodedPassword = $encoder->encodePassword('Rogvog4', $user1->getSalt());
     $user1->setPassword($encodedPassword);
     $em->persist($user1);
     // user admin
     $user2 = new User();
     $user2->addGroup($em->merge($this->getReference('group-admin')));
     $user2->setEmail('*****@*****.**');
     $user2->setUsername('admin');
     $user2->setFirstname('Steeve');
     $user2->setLastname('Jobs');
     $user2->setEnabled(true);
     $user2->setSuperAdmin(true);
     $user2->setLocked(false);
     $this->addReference('user-admin', $user2);
     $encoder = $factory->getEncoder($user2);
     $encodedPassword = $encoder->encodePassword('password', $user2->getSalt());
     $user2->setPassword($encodedPassword);
     $em->persist($user2);
     // user user
     $user3 = new User();
     $user3->addGroup($em->merge($this->getReference('group-user')));
     $user3->setEmail('*****@*****.**');
     $user3->setUsername('user');
     $user3->setFirstname('User');
     $user3->setLastname('Jobs');
     $user3->setEnabled(true);
     $user3->setSuperAdmin(true);
     $user3->setLocked(false);
     $this->addReference('user-user', $user3);
     $encoder = $factory->getEncoder($user3);
     $encodedPassword = $encoder->encodePassword('password', $user3->getSalt());
     $user3->setPassword($encodedPassword);
     $em->persist($user3);
     // user tom
     $user4 = new User();
     $user4->addGroup($em->merge($this->getReference('group-admin')));
     $user4->setFirstname('Tom');
     $user4->setLastname('Nana');
     $user4->setEmail('*****@*****.**');
     $user4->setEnabled(true);
     $user4->setUsername('tom');
     $user4->setSuperAdmin(false);
     $user4->setLocked(false);
     $this->addReference('user-tom', $user4);
     $encoder = $factory->getEncoder($user4);
     $encodedPassword = $encoder->encodePassword('azerty', $user4->getSalt());
     $user4->setPassword($encodedPassword);
     $em->persist($user4);
     foreach (range(1, 43) as $id) {
         $user = new User();
         $user->addGroup($em->merge($this->getReference('group-user')));
         $user->setFirstname($faker->firstName);
         $user->setLastname($faker->lastName);
         $user->setEmail($faker->safeEmail);
         $user->setPhone($faker->phoneNumber);
         $user->setUsername($faker->userName);
         $user->setPassword('');
         $user->setEnabled(true);
         $user->setLocked(false);
         $this->addReference('user-' . $id, $user);
         $em->persist($user);
     }
     $em->flush();
 }
 /**
  * {@inheritDoc}
  */
 public function setPassword($password)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setPassword', array($password));
     return parent::setPassword($password);
 }