protected function getObjectFromData($data)
 {
     $deligatedUser = new DeligatedUser();
     $deligatedUser->setId(intval($data['ud_id']));
     $deligatedUser->setType($data['ud_type']);
     $deligatedUser->setUniqueId($data['ud_unique_id']);
     if ($data['ud_name']) {
         $deligatedUser->setName($data['ud_name']);
     }
     if ($data['ud_access_token']) {
         $deligatedUser->setAccessToken($data['ud_access_token']);
     }
     if ($data['ud_gender']) {
         $deligatedUser->setGender($data['ud_gender']);
     }
     if ($data['ud_email']) {
         $deligatedUser->setEmail($data['ud_email']);
     }
     if ($data['ud_birthday']) {
         $deligatedUser->setBirthday(new Carbon($data['ud_birthday']));
     }
     if ($data['ud_locale']) {
         $deligatedUser->setLocale($data['ud_locale']);
     }
     if ($data['ud_avatar']) {
         $deligatedUser->setAvatar($data['ud_avatar']);
     }
     if ($data['ud_firstname']) {
         $deligatedUser->setFirstname($data['ud_firstname']);
     }
     if ($data['ud_lastname']) {
         $deligatedUser->setLastname($data['ud_lastname']);
     }
     if ($data['u_id']) {
         $user = \Neuron\MapperFactory::getUserMapper()->getFromId($data['u_id']);
         if ($user) {
             $deligatedUser->setUser($user);
         }
     }
     $deligatedUser->setCreatedAt(strtotime($data['created_at']));
     $deligatedUser->setUpdatedAt(strtotime($data['updated_at']));
     return $deligatedUser;
 }
Exemplo n.º 2
0
 public function login()
 {
     $this->initialize();
     $helper = new FacebookRedirectLoginHelper(URLBuilder::getAbsoluteURL($this->module->getRoutePath() . '/login/' . $this->getToken(), array('next' => 1)));
     if (!$this->request->input('next')) {
         $loginUrl = $helper->getLoginUrl($this->scopes);
         return Response::redirect($loginUrl);
     } else {
         try {
             $session = $helper->getSessionFromRedirect();
         } catch (FacebookRequestException $ex) {
             // When Facebook returns an error
             return Response::error($ex->getMessage());
         } catch (\Exception $ex) {
             // When validation fails or other local issues
             return Response::error($ex->getMessage());
         }
         if ($session) {
             // Check if this user is already registered.
             $request = new FacebookRequest($session, 'GET', '/me', array('fields' => 'id,name,gender,verified,locale,timezone,email,birthday,first_name,last_name'));
             $response = $request->execute();
             $graphObject = $response->getGraphObject();
             $data = $graphObject->asArray();
             // Create an object.
             $user = new DeligatedUser();
             $user->setType('facebook');
             $user->setUniqueId($data['id']);
             $user->setAccessToken((string) $session->getAccessToken());
             if (isset($data['name'])) {
                 $user->setName($data['name']);
             }
             if (isset($data['gender'])) {
                 switch (strtoupper($data['gender'])) {
                     case DeligatedUser::GENDER_FEMALE:
                     case DeligatedUser::GENDER_MALE:
                         $user->setGender(strtoupper($data['gender']));
                         break;
                 }
             }
             if (isset($data['locale'])) {
                 $user->setLocale($data['locale']);
             }
             if (isset($data['email'])) {
                 $user->setEmail($data['email']);
             }
             if (isset($data['birthday'])) {
                 if (strlen($data['birthday']) == 10) {
                     $parts = explode('/', $data['birthday']);
                     $user->setBirthday(Carbon::createFromDate($parts[2], $parts[0], $parts[1]));
                 }
             }
             if (isset($data['first_name'])) {
                 $user->setFirstname($data['first_name']);
             }
             if (isset($data['last_name'])) {
                 $user->setLastname($data['last_name']);
             }
             $user->setAvatar('https://graph.facebook.com/' . $user->getUniqueId() . '/picture?type=large');
             // Touchy touchy!
             return $this->setDeligatedUser($user);
         }
     }
 }