Ejemplo n.º 1
0
 /**
  * Build a new user and return it.
  *
  * @param string $username the user name
  * @param string $fullname the full name
  * @param string $role     the role, as remembered in LoadRoleData
  *
  * @return User
  */
 private function buildUser($username, $fullname, $role)
 {
     $user = new User();
     $user->setUsername($username);
     $user->setFullname($fullname);
     $user->setIsActive(true);
     $user->addRole($this->getReference($role));
     $user->setInstitution("");
     $user->generateSalt();
     $encoder = $this->container->get('security.encoder_factory')->getEncoder($user);
     $user->setPassword($encoder->encodePassword('supersecret', $user->getSalt()));
     return $user;
 }
Ejemplo n.º 2
0
 /**
  * Build a new user and return it.
  *
  * @param string $username the user name
  * @param string $fullname the full name
  * @param string $role     the role, as remembered in LoadRoleData
  *
  * @return User
  */
 private function buildUser($manager, $username, $fullname, $role = null)
 {
     $user = new User();
     // AdminUserType sets the username to the email address, so do that here as well.
     $user->setUsername($username);
     $user->setEmail($username);
     $user->setFullname($fullname);
     $user->setInstitution("");
     $user->setEnabled(true);
     $user->setLocked(false);
     if ($role !== null) {
         $user->addRole($role);
     }
     $user->setPlainPassword('supersecret');
     $manager->persist($user);
     return $user;
 }
Ejemplo n.º 3
0
 /**
  * Grant a role to a user
  *
  * @param string $role
  * @param User $user
  */
 public function grantRole($role, $user)
 {
     $user->addRole($role);
 }