예제 #1
0
 /**
  * 
  * @param unknown $username
  * @throws UsernameNotFoundException
  * @return unknown
  */
 public function loadUserByUsername($username)
 {
     $user = $this->findUserByFbId($username);
     try {
         $fbdata = $this->facebook->api('/me');
     } catch (FacebookApiException $e) {
         $fbdata = null;
     }
     if (empty($user) and !empty($fbdata)) {
         $user = $this->userManager->findUserBy(array('email' => $fbdata['email']));
     }
     if (!empty($fbdata)) {
         if (empty($user)) {
             $user = $this->userManager->createUser();
             $user->setEnabled(true);
             $user->setPassword('');
         }
         // TODO use http://developers.facebook.com/docs/api/realtime
         $user->setFBData($fbdata);
         if (count($this->validator->validate($user, 'Facebook'))) {
             // TODO: the user was found obviously, but doesnt match our expectations, do something smart
             throw new UsernameNotFoundException('The facebook user could not be stored');
         }
         $this->userManager->updateUser($user);
     }
     if (empty($user)) {
         throw new UsernameNotFoundException('The user is not authenticated on facebook');
     }
     return $user;
 }
예제 #2
0
 protected function FindUserAndUpdateToken(FacebookSessionPersistence $facebook, $fbid)
 {
     $em = $this->getDoctrine()->getManager();
     $repository = $this->getDoctrine()->getRepository('MimazooSoaBundle:Player');
     $player = $repository->findOneByFbId($fbid);
     if ($player != false) {
         $player->setFbAccessToken($facebook->getAccessToken());
         $em->persist($player);
         $em->flush();
         $this->getLogger()->info("Updating token information for player id: " . $player->getId());
         return $player;
     }
     //Player is new
     return false;
 }