public function createNewUser($socialProfile, $type)
 {
     $em = $this->container->get('doctrine')->getManager();
     $user = new User();
     $profile = new Profile();
     $tokenGenerator = $this->container->get('fos_user.util.token_generator');
     $plainPassword = substr($tokenGenerator->generateToken(), 0, 12);
     $password = $this->generatePassword($plainPassword, $user);
     $profile->setSocialId($type, $socialProfile['id']);
     $user->setEnabled(true);
     if (!empty($socialProfile['birthday'])) {
         $profile->setBirthdate(new \DateTime($socialProfile['birthday']));
     }
     if (!empty($socialProfile['first_name'])) {
         $user->setFirstName($socialProfile['first_name']);
     }
     if (!empty($socialProfile['last_name'])) {
         $user->setLastName($socialProfile['last_name']);
     }
     if (empty($socialProfile['username'])) {
         $socialProfile['username'] = implode(" ", array($socialProfile['first_name'], $socialProfile['last_name']));
         if (empty($socialProfile['username'])) {
             $socialProfile['username'] = $socialProfile['id'];
         }
     }
     $user->setUsername($socialProfile['username']);
     if (!empty($socialProfile['email'])) {
         $user->setEmail($socialProfile['email']);
     }
     $user->setPassword($password);
     $user->setProfile($profile);
     $em->persist($user);
     $em->flush();
     //  Send Confirmation Email
     $this->sendEmail($user, $plainPassword);
     return $user;
 }
 /**
  * {@inheritDoc}
  */
 public function setSocialId($fieldName, $fieldValue)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setSocialId', array($fieldName, $fieldValue));
     return parent::setSocialId($fieldName, $fieldValue);
 }