Example #1
0
 public function registrationOauthCompleted(OAuthResponseEvent $event)
 {
     $em = $this->em;
     if (!$event->getUser()->isEnabled()) {
         return;
     }
     $user = $event->getUser();
     if ($user->getAthlete() == null) {
         $athlete = new Athlete();
         $athlete->setName($user->getUsername());
         $profilePicture = $event->getResponse()->getProfilePicture();
         if ($profilePicture != null) {
             $image = new Image();
             $fileContent = file_get_contents($profilePicture);
             $image->setName("Facebook profile image");
             $image->setContent(base64_encode($fileContent));
             $athlete->setImage($image);
         }
         $user->setAthlete($athlete);
         $em->persist($athlete);
         $em->flush();
     }
 }
Example #2
0
 private function setAthlete($athleteName)
 {
     $athlete = $this->manager->getRepository('OesteveGrupetaBundle:Athlete')->findOneBy(array('name' => $athleteName));
     if (!$athlete) {
         $athlete = new Athlete();
     }
     $athlete->setName($athleteName);
     $athlete->setSlug(Slug::slugify($athleteName));
     return $athlete;
 }