createUser() public method

Creates an empty user instance
public createUser ( ) : User
return User
Exemplo n.º 1
0
 /**
  * Creates a user and returns it.
  *
  * @param string $username
  * @param string $password
  * @param string $email
  * @param bool   $active
  * @param bool   $superadmin
  *
  * @return \FOS\UserBundle\Model\UserInterface
  */
 public function create($username, $password, $email, $active, $superadmin)
 {
     $discriminator = $this->discriminator;
     switch ($this->type) {
         case 'staff':
             $class = 'Truckee\\MatchBundle\\Entity\\Staff';
             break;
         case 'admin':
             $class = 'Truckee\\MatchBundle\\Entity\\Admin';
             break;
         case 'volunteer':
             $class = 'Truckee\\MatchBundle\\Entity\\Volunteer';
             break;
         default:
             break;
     }
     $discriminator->setClass($class);
     $user = $this->userManager->createUser();
     $user->setUsername($username);
     $user->setFirstname($this->firstname);
     $user->setLastname($this->lastname);
     $user->setEmail($email);
     $user->setPlainPassword($password);
     $user->setEnabled((bool) $active);
     $this->userManager->updateUser($user, true);
     return $user;
 }
Exemplo n.º 2
0
 public function create()
 {
     /** @var User $user */
     $user = $this->userManager->createUser();
     $user->setPlainPassword(md5(rand(1000000, 9999999), false));
     $user->setEnabled(true);
     return $user;
 }
 /**
  * Create user from response
  *
  * @param UserResponseInterface $response
  *
  * @return User
  */
 private function createUserFromResponse(UserResponseInterface $response)
 {
     /** @var User $user User */
     $user = $this->userManager->createUser();
     $user->setUsername($response->getUsername())->setFullName($response->getRealName())->setEmail($response->getEmail())->setEnabled(true)->setPlainPassword(uniqid())->setFacebookId($response->getUsername())->setFacebookAccessToken($response->getAccessToken());
     $this->eventDispatcher->dispatch(AppEvents::FACEBOOK_USER_CONNECTED, new FacebookUserConnectedEvent($user));
     $this->userManager->updateUser($user);
     return $user;
 }
Exemplo n.º 4
0
 /**
  * Creates a user and returns it.
  *
  * @param string $username
  * @param string $password
  * @param string $email
  * @param Boolean $active
  * @param Boolean $superadmin
  * @return \FOS\UserBundle\Model\UserInterface
  */
 public function create($username, $password, $email, $active, $superadmin)
 {
     $user = $this->userManager->createUser();
     $user->setUsername($username);
     $user->setEmail($email);
     $user->setPlainPassword($password);
     $user->setEnabled((bool) $active);
     $user->setSuperAdmin((bool) $superadmin);
     $this->userManager->updateUser($user);
     return $user;
 }
Exemplo n.º 5
0
 /**
  * Creates a user and returns it.
  *
  * @param string $email
  * @param string $password
  * @param string $fullname
  * @param string $institution
  * @param bool   $active
  * @param bool   $superadmin
  *
  * @return User
  */
 public function create($email, $password, $fullname, $institution, $active, $superadmin)
 {
     $user = $this->userManager->createUser();
     $user->setEmail($email);
     $user->setPlainPassword($password);
     $user->setFullname($fullname);
     $user->setInstitution($institution);
     $user->setEnabled($active);
     $user->setSuperAdmin($superadmin);
     $this->userManager->updateUser($user);
     return $user;
 }
Exemplo n.º 6
0
 /**
  * @param $email
  * @param $password
  * @return \FOS\UserBundle\Model\UserInterface
  * @throws ValidationException
  */
 public function registerUser($email, $password)
 {
     $user = $this->userManager->createUser();
     $user->setUsername($email);
     $user->setEmail($email);
     $user->setPlainPassword($password);
     $user->setEnabled(true);
     $errors = $this->validator->validate($user, null, array('registration'));
     if ($errors->count() > 0) {
         throw new ValidationException($errors);
     }
     $this->userManager->updateUser($user);
     return UserDTO::withEntity($user);
 }
Exemplo n.º 7
0
 /**
  * Creates a user and returns it.
  *
  * @param string  $username
  * @param string  $password
  * @param string  $email
  * @param Boolean $active
  * @param Boolean $superadmin
  *
  * @return \FOS\UserBundle\Model\UserInterface
  */
 public function create($username, $password, $email, $active, $superadmin, $company, $legalSituation, $phoneNumber, $url)
 {
     $user = $this->userManager->createUser();
     $user->setUsername($username);
     $user->setEmail($email);
     $user->setPlainPassword($password);
     $user->setEnabled((bool) $active);
     $user->setSuperAdmin((bool) $superadmin);
     $user->setCompany($company);
     $user->setLegalSituation($legalSituation);
     $user->setPhoneNumber($phoneNumber);
     $user->setUrl($url);
     $this->userManager->updateUser($user);
     return $user;
 }
Exemplo n.º 8
0
 /**
  * Creates a user and returns it.
  *
  * @param string $username
  * @param string $password
  * @param string $email
  * @param string $name
  * @param string $lastName
  * @param bool   $active
  * @param bool   $superadmin
  *
  * @return \FOS\UserBundle\Model\UserInterface
  */
 public function create($username, $password, $email, $name, $lastName, $active, $superadmin, $changePassword)
 {
     $user = $this->userManager->createUser();
     $user->setUsername($username);
     $user->setEmail($email);
     $user->setPlainPassword($password);
     $user->setName($name);
     $user->setLastName($lastName);
     $user->setEnabled((bool) $active);
     $user->setSuperAdmin((bool) $superadmin);
     if ((bool) $changePassword) {
         $user->setPasswordExpireAt(new \DateTime());
     }
     $this->userManager->updateUser($user);
     return $user;
 }
Exemplo n.º 9
0
 /**
  * Fixes the user, Drupal does not provide a hook for anonymous user
  */
 public function fixAnonymousUser()
 {
     global $user;
     if (!$user || $user->uid != 0) {
         return;
     }
     $user = $this->userManager->createUser()->fromDrupalUser($user);
 }
Exemplo n.º 10
0
 /**
  * Create user from response
  *
  * @param UserResponseInterface $response
  *
  * @return User
  */
 private function createUserFromResponse(UserResponseInterface $response)
 {
     $email = $response->getEmail() ?: $response->getUsername() . '@example.com';
     /** @var User $user */
     $user = $this->userManager->createUser();
     $user->setEmail($email);
     $user->setUsername($response->getNickname());
     $user->setEnabled(true);
     $user->setPlainPassword(uniqid());
     $user->setGithubId($response->getUsername());
     // Move to separate listener
     if (in_array($response->getUsername(), $this->adminGitHubIds)) {
         $user->addRole('ROLE_ADMIN');
     }
     $this->userManager->updateUser($user);
     return $user;
 }
Exemplo n.º 11
0
 /**
  * Creates a user and returns it.
  *
  * @param string  $username
  * @param string  $password
  * @param string  $email
  * @param Boolean $active
  * @param Boolean $superadmin
  * @param array   $userproperties
  *
  * @return \FOS\UserBundle\Model\UserInterface
  */
 public function create($username, $password, $email, $active, $superadmin, $userproperties = null)
 {
     $user = $this->userManager->createUser();
     $user->setUsername($username);
     $user->setEmail($email);
     $user->setPlainPassword($password);
     $user->setEnabled((bool) $active);
     $user->setSuperAdmin((bool) $superadmin);
     if (!is_null($userproperties) && is_array($userproperties) && count($userproperties) > 0) {
         foreach ($userproperties as $method => $value) {
             if (method_exists($user, $method)) {
                 $user->{$method}($value);
             }
         }
     }
     $this->userManager->updateUser($user);
     return $user;
 }
 /**
  * @param \Hatimeria\ExtJSBundle\Parameter\ParameterBag $params
  * @param mixed $user
  * @return \Hatimeria\ExtJSBundle\Response\Form
  */
 public function process($params, $user = null)
 {
     $validationGroup = 'Profile';
     if (null === $user) {
         $validationGroup = 'Registration';
         $user = $this->um->createUser();
     }
     $options = array('data_class' => $this->userClass, 'validation_groups' => array($validationGroup));
     $type = new UserFormType();
     $type->setExtend($this->extensionCollector->getExtensions());
     $form = $this->formFactory->create($type, $user, $options);
     $form->bind($params->all());
     $result = new Form($form);
     if ($result->isValid()) {
         $this->um->updateUser($user);
         return $user;
     }
     return $result;
 }
 /**
  * Creates a new principal.
  *
  * This method receives a full path for the new principal. The mkCol object
  * contains any additional webdav properties specified during the creation
  * of the principal.
  *
  * @param string $path
  * @param MkCol  $mkCol
  */
 public function createPrincipal($path, MkCol $mkCol)
 {
     // create new user
     $username = str_replace('principal/', '', $path);
     $user = $this->user_manager->createUser();
     $user->setUsername($username);
     $user->setForename($username);
     $this->_em->persist($user);
     $this->_em->flush();
 }
Exemplo n.º 14
0
 /**
  * {@inheritDoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $userInfo = $this->getUserInfo($response);
     $service = $response->getResourceOwner()->getName();
     $user = $this->userManager->findUserBy(array("{$service}Id" => $userInfo['id']));
     if ($user instanceof PersonInterface) {
         $user = parent::loadUserByOAuthUserResponse($response);
         $serviceName = $response->getResourceOwner()->getName();
         $setter = 'set' . ucfirst($serviceName) . 'AccessToken';
         $user->{$setter}($response->getAccessToken());
         return $user;
     }
     $userInfo = $this->checkEmail($service, $userInfo);
     $user = $this->userManager->createUser();
     $this->setUserInfo($user, $userInfo, $service);
     if ($userInfo['first_name']) {
         $user->setFirstName($userInfo['first_name']);
     }
     if ($userInfo['family_name']) {
         $user->setSurname($userInfo['family_name']);
     }
     if ($service === 'facebook') {
         $this->setFacebookData($user, $response->getResponse());
     }
     $username = Uuid::uuid4()->toString();
     if (!UsernameValidator::isUsernameValid($username)) {
         $username = UsernameValidator::getValidUsername();
     }
     $availableUsername = $this->userManager->getNextAvailableUsername($username, 10, Uuid::uuid4()->toString());
     $user->setUsername($availableUsername);
     $user->setEmail($userInfo['email']);
     $user->setPassword('');
     $user->setEnabled(true);
     $this->userManager->updateCanonicalFields($user);
     /** @var ValidatorInterface $validator */
     $validator = $this->container->get('validator');
     /** @var ConstraintViolationList $errors */
     $errors = $validator->validate($user, ['LoginCidadaoProfile']);
     if (count($errors) > 0) {
         foreach ($errors as $error) {
             if ($error->getPropertyPath() === 'email' && method_exists($error, 'getConstraint') && $error->getConstraint() instanceof UniqueEntity) {
                 throw new DuplicateEmailException($service);
             }
         }
     }
     $form = $this->formFactory->createForm();
     $form->setData($user);
     $request = $this->container->get('request');
     $eventResponse = new RedirectResponse('/');
     $event = new FormEvent($form, $request);
     $this->dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);
     $this->userManager->updateUser($user);
     $this->dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $eventResponse));
     return $user;
 }
Exemplo n.º 15
0
 /**
  * Creates a new Resource from the given parameters.
  *
  * @param FormInterface $form
  *
  * @return Resource
  */
 public function create(FormInterface $form)
 {
     $formData = $form->getData();
     /** @var UserEntity $user */
     $user = $this->userManager->createUser();
     $user->setUsername($formData['username']);
     $user->setEmail($formData['email']);
     $user->setPlainPassword($formData['password']);
     $user->setEnabled(true);
     $this->userManager->updateUser($user);
     return $this->createResourceFromUser($user);
 }
 /**
  * {@inheritdoc}
  */
 public function process(Request $request, Form $form, UserResponseInterface $userInformation)
 {
     if (null !== $this->registrationFormHandler) {
         $formHandler = $this->reconstructFormHandler($request, $form);
         // make FOSUB process the form already
         $processed = $formHandler->process();
         // if the form is not posted we'll try to set some properties
         if (!$request->isMethod('POST')) {
             $form->setData($this->setUserInformation($form->getData(), $userInformation));
         }
         return $processed;
     }
     if ($request->isMethod('POST')) {
         $user = $this->userManager->createUser();
         $user->setEnabled(true);
         $form->setData($this->setUserInformation($user, $userInformation));
         $form->handleRequest($request);
         return $form->isValid();
     }
     return false;
 }
Exemplo n.º 17
0
 /**
  * Creates a user and returns it.
  *
  * @param string  $username
  * @param string  $password
  * @param string  $email
  * @param string  $locale
  * @param Boolean $active
  * @param Boolean $superadmin
  *
  * @return \FOS\UserBundle\Model\UserInterface
  */
 public function create($username, $password, $email, $locale, $active, $superadmin)
 {
     $user = $this->userManager->createUser();
     $user->setUsername($username);
     $user->setEmail($email);
     $user->setLocale($locale);
     $user->setPlainPassword($password);
     $user->setEnabled((bool) $active);
     $user->setSuperAdmin((bool) $superadmin);
     $this->userManager->updateUser($user);
     /*
     $userProfile = new UserProfile();
     $userProfile->setUser($user);
     $em = $this->getDoctrine()->getManager();
     $em->persist($userProfile);
     $em->flush();
     
     $user->setProfile($userProfile);
     $this->userManager->updateUser($user);
     */
     return $user;
 }
Exemplo n.º 18
0
 public function findOrCreate($username, $object)
 {
     $user = $this->findUserByUsername($username);
     if (!$user) {
         /** @var Usuario $user */
         $user = $this->userManager->createUser();
         $user->setUsername($username);
         if ($object instanceof Coordinador) {
             $user->setTipo(Usuario::COORDINADOR);
             $user->addRole('ROLE_COORDINADOR');
         }
         if ($object instanceof Director) {
             $user->setTipo(Usuario::DIRECTOR);
             $user->addRole('ROLE_DIRECTOR');
         }
         $user->setEmail($object->getEmail());
         $user->setRelated($object->getRelated());
     }
     $user->setPlainPassword($object->getPassword());
     $user->setEnabled($object->getActivo());
     $this->userManager->updateUser($user);
     return $user;
 }
Exemplo n.º 19
0
 /**
  * @inheritdoc
  */
 public function createNew()
 {
     return $this->FOSUserManager->createUser();
 }