예제 #1
0
 /**
  * Get Local Expert populated with info from Facebook account
  *
  * @param string $code
  * @return LocalAuthor
  */
 public function getFBPrefilledLocalAuthor($fbInfo)
 {
     $localAuthor = new LocalAuthor();
     $localAuthor->setFirstName($fbInfo['firstName']);
     $localAuthor->setLastName($fbInfo['lastName']);
     $localAuthor->setPassword(null);
     return $localAuthor;
 }
 public function indexAction(Request $request)
 {
     $session = $this->getRequest()->getSession();
     if (!$session->has('redirect')) {
         $session->set('redirect', $request->headers->get('referer'));
     }
     $securityContext = $this->get('security.context');
     if ($securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
         return new RedirectResponse($this->generateUrl('buggl_homepage'));
     }
     $session = $this->getRequest()->getSession();
     $token = $request->get('ref', '');
     if (!empty($token)) {
         $session->set('invitation_token', $token);
     }
     $facebookRegistrationUrl = $this->generateUrl('signup_via_facebook_url');
     $twitterRegistrationUrl = $this->generateUrl('signup_via_twitter_url');
     $googlePlusRegistrationUrl = $this->generateUrl('signup_via_google_plus_url');
     $localAuthor = new LocalAuthor();
     if ($session->get('via_modal')) {
         $email = $session->remove('email');
         $firstName = $session->remove('first_name');
         $lastName = $session->remove('last_name');
         $localAuthor->setEmail($email);
         $localAuthor->setFirstName($firstName);
         $localAuthor->setLastName($lastName);
         $session->remove('via_modal');
     }
     $form = $this->createForm(new LocalAuthorType(0), $localAuthor);
     $response = $this->handleRegistration($request, $form);
     if (!is_null($response)) {
         return $response;
     }
     $slug = substr(strrchr($request->getUri(), "/"), 1);
     $metas = $this->get('buggl_seo.static_page')->buildMetaAttributes($slug);
     $googleApiKey = $this->get('buggl_main.constants')->get('google_maps_api_key');
     $data = array('form' => $form->createView(), 'googleApiKey' => $googleApiKey, 'facebookRegistrationUrl' => $facebookRegistrationUrl, 'twitterRegistrationUrl' => $twitterRegistrationUrl, 'googlePlusRegistrationUrl' => $googlePlusRegistrationUrl, 'requirePassword' => true, 'metas' => $metas);
     return $this->render('BugglMainBundle:Frontend/Registration:registration.html.twig', $data);
 }
 public function setFirstName($firstName)
 {
     $this->__load();
     return parent::setFirstName($firstName);
 }
 public function registerLocalAuthor($data)
 {
     $password = isset($data['password']['first']) ? $this->encoder->encodePassword($data['password']['first'], '') : null;
     $email = isset($data['fbId']) ? $data['email'] : $data['email']['first'];
     $localAuthor = new LocalAuthor();
     $localAuthor->setFirstName($data['firstName']);
     $localAuthor->setLastName($data['lastName']);
     $localAuthor->setEmail($email);
     $localAuthor->setPassword($password);
     $localAuthor->setEmailVerified(1);
     // (isset($data['fbEmail']) && $email == $data['fbEmail']) ?  $this->constants->get('EMAIL_VERIFIED') : $this->constants->get('EMAIL_UNVERIFIED')
     $localAuthor->setIsLocalAuthor($data['type']);
     $localAuthor->setDateJoined(new \DateTime(date('Y-m-d H:i:s')));
     $localAuthor->setStatus(0);
     $localAuthor->setStreetCredit(0);
     $localAuthor->setIsApproved(1);
     $localAuthor->setIsBetaParticipant(isset($data['betaToken']));
     $localAuthor->setLastActive(new \DateTime(date('Y-m-d H:i:s')));
     $localAuthor->setLastInactiveNotificationSent(new \DateTime(date('Y-m-d H:i:s')));
     $this->entityManager->persist($localAuthor);
     $bypassLocation = true;
     if ($data['type'] == 1 and !$bypassLocation) {
         // this is in preparation for when location would be non-required : Nash Lesigon - May 8, 2014
         if (strlen(trim($data['country'])) && strlen(trim($data['city']))) {
             $location = new Location();
             $location->setLocalAuthor($localAuthor);
             // find city by name, if not found create new city
             // data['city], data['country']
             $country = $this->entityManager->getRepository('BugglMainBundle:Country')->findOneByName($data['country']);
             if (!is_null($country)) {
                 $city = $this->entityManager->getRepository('BugglMainBundle:City')->findOneBy(array('name' => $data['city'], 'country' => $country));
                 if (is_null($city)) {
                     $city = new City();
                     $city->setCountry($country);
                     $city->setName($data['city']);
                     $this->entityManager->persist($city);
                 }
                 $location->setCity($city);
                 $this->entityManager->persist($location);
             }
         }
     }
     $this->entityManager->flush();
     $profile = new Profile();
     $profile->setLocalAuthor($localAuthor);
     if (isset($data['fbId'])) {
         $this->socialMediaService->saveFacebookInfo($data, $localAuthor);
         $tempPath = 'uploads/profile_pics';
         $uploadRootDir = $this->serviceContainer->get('kernel')->getRootdir() . '/../web/' . $tempPath;
         $filename = 'fb_' . $data['fbId'] . '.jpg';
         copy('https://graph.facebook.com/' . $data['fbId'] . '/picture?width=285&height=285', $uploadRootDir . '/' . $filename);
         $profile->setProfilePic($filename);
         $profile->setWork($data['fbWork']);
         $profile->setBirthDate($data['fbBirthday']);
         $this->entityManager->persist($profile);
         $this->entityManager->flush();
     } else {
         if (isset($data['twitterId'])) {
             $this->socialMediaService->saveTwitterInfo($data, $localAuthor);
         } else {
             if (isset($data['googlePlusId'])) {
                 $this->socialMediaService->saveGooglePlusInfo($data, $localAuthor);
             } else {
                 $this->entityManager->persist($profile);
                 $this->entityManager->flush();
             }
         }
     }
     return $localAuthor;
 }