Пример #1
0
 public static function returnError($mesg, $rerequest = false)
 {
     FSLTools::returnErrors(array($mesg), $rerequest);
 }
Пример #2
0
 public function processSubmitLogin()
 {
     $facebookApi = $this->initApi(Tools::getValue('accessToken'));
     try {
         $response = $facebookApi->get('/me?fields=id,name,email,first_name,last_name,gender');
         $user = $response->getGraphUser();
         $social_customer = new FacebookCustomer();
         if (!$social_customer->getByUserId($user->getId())) {
             $social_customer->id_user = $user->getId();
             $social_customer->username = $user->getName();
             // name
             $social_customer->firstname = $user->getFirstName();
             // first_name
             $social_customer->lastname = $user->getLastName();
             // last_name
             $social_customer->email = $user->getEmail();
             if ($user->getPicture() && $user->getPicture()->getUrl()) {
                 $social_customer->picture_url = $user->getPicture()->getUrl();
             } else {
                 $social_customer->picture_url = "https://graph.facebook.com/" . $user->getId() . "/picture";
             }
             //?type=square";
             if (!$social_customer->email) {
                 if (!Tools::isSubmit("rerequest")) {
                     FSLTools::returnError(Tools::displayError('Email authorization must be granted.'), true);
                 }
                 // Revoke permissions
                 $facebookApi->delete('/' . $user->getId() . '/permissions');
                 FSLTools::returnErrors(array());
                 // No error message
             }
             if ($user->getGender()) {
                 $social_customer->id_gender = $user->getGender() == 'female' ? 2 : 1;
             }
             // gender
             if ($user->getBirthday()) {
                 $birth_date = explode('/', $user->getBirthday());
                 // birthday : MM/DD/YYYY
                 $birth_year = $birth_date[2];
                 $birth_month = $birth_date[0];
                 $birth_day = $birth_date[1];
                 $social_customer->birthday = $birth_year . '-' . $birth_month . '-' . $birth_day;
             }
             $location = $user->getLocation();
             if ($location) {
                 /* TODO */
             }
         }
         return $social_customer;
     } catch (Facebook\Exceptions\FacebookResponseException $e) {
         // When Graph returns an error
         FSLTools::returnError(sprintf(Tools::displayError('Facebook Graph returned an error: %s'), $e->getMessage()));
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         // When validation fails or other local issues
         FSLTools::returnError(sprintf(Tools::displayError('Facebook SDK returned an error: %s'), $e->getMessage()));
     }
 }