예제 #1
0
 public function createAdmin($email, $username, $password, $roles, $lastName = '', $firstName = '')
 {
     $user = new User();
     $user->setEmail($email);
     $user->setEnabled(0);
     $user->setUsername($username);
     $user->setSubscribe(new \DateTime('now'));
     $user->setRoles(serialize($roles));
     $user->setLastName($lastName);
     $user->setFirstName($firstName);
     $salt = uniqid(mt_rand(), true);
     $options = ['cost' => 11, 'salt' => $salt];
     $user->setSalt($salt);
     $user->setPassword(password_hash($password, PASSWORD_BCRYPT, $options));
     $this->em->persist($user);
     $this->em->flush();
 }