public function postOnFacebookAction()
 {
     try {
         $home = $this->view->url(array("module" => "default", "controller" => "index", "action" => "index"));
         $returnUri = $this->view->url(array("module" => "member", "controller" => "chronicle", "action" => "post-on-facebook"));
         // Testing if user is facebook connected
         $facebookSvc = new FacebookSvc(SHARE1BOOK_FACEBOOK_API_ID, SHARE1BOOK_FACEBOOK_SECRET, $returnUri, $home);
         $facebookUser = $facebookSvc->getUser();
         if ($facebookUser) {
             $sessionData = new Zend_Session_Namespace(self::EDIT_CHRONICLE_NAMESPACE);
             /* @var $chronicle Chronicle */
             $chronicle = ChronicleDao::getInstance()->get($sessionData->chronicleId);
             if ($this->postOnFacebook($chronicle, $facebookSvc)) {
                 Flash::addItem(__("Votre post sur facebook a été effectué avec succès.", "s1b"));
             } else {
                 Flash::addItem(__("Une erreur s'est produite lors de votre post sur facebook", "s1b"));
             }
             $this->redirect("default/index/index");
         } else {
             $this->redirect($facebookSvc->getFacebookLogInUrl());
         }
     } catch (\Exception $e) {
         Trace::addItem(sprintf("Une erreur s'est produite dans \"%s->%s\", TRACE : %s\"", get_class(), __FUNCTION__, $e->getTraceAsString()));
         $this->forward("error", "error", "default");
     }
 }
Esempio n. 2
0
 public function facebookLogAction()
 {
     try {
         $globalConfig = new Sb\Config\Model\Config();
         $accountDeleted = __("Votre compte a été supprimé.", "s1b");
         $home = HTTPHelper::Link("");
         $loginFaceBook = HTTPHelper::Link(Urls::LOGIN_FACEBOOK);
         // Testing if user is facebook connected
         $facebookSvc = new FacebookSvc($globalConfig->getFacebookApiId(), $globalConfig->getFacebookSecret(), $loginFaceBook, $home);
         $facebookUser = $facebookSvc->getUser();
         if ($facebookUser) {
             // If yes, testing if a user exist in db (and not deleted)
             // Search a matching activated user in DB
             $faceBookEmail = $facebookUser->getEmail();
             $facebookId = $facebookUser->getUid();
             $userInDB = \Sb\Db\Dao\UserDao::getInstance()->getFacebookUser($faceBookEmail);
             if (!$userInDB) {
                 // If no existing user => create an account and redirect to user homepage
                 // create user in db
                 $userFromFB = new User();
                 UserMapper::mapFromFacebookUser($userFromFB, $facebookUser);
                 $userFromFB->setToken(sha1(uniqid(rand())));
                 $userFromFB->setDeleted(false);
                 $setting = new UserSetting();
                 UserSettingHelper::loadDefaultSettings($setting);
                 $userFromFB->setSetting($setting);
                 $userInDB = UserDao::getInstance()->add($userFromFB);
                 // send confirmation email
                 $subject = sprintf(__("Votre compte %s a été créé avec Facebook", "s1b"), Constants::SITENAME);
                 MailSvc::getInstance()->send($userInDB->getEmail(), $subject, MailHelper::faceBookAccountCreationEmailBody($userInDB->getFirstName()));
                 // Test if the email matches invitations and set them to accepted and validated
                 InvitationSvc::getInstance()->setInvitationsAccepted($userInDB->getEmail());
                 // Send warning email to webmaster
                 MailSvc::getInstance()->send(\Sb\Entity\Constants::WEBMASTER_EMAIL . ", berliozd@gmail.com, rebiffe_olivier@yahoo.fr", __("nouveau user via facebook", "s1b"), $userInDB->getEmail());
                 // send message in user internal mailbox
                 MessageSvc::getInstance()->createWelcomeMessage($userInDB->getId());
                 // redirect to user homepage
                 AuthentificationSvc::getInstance()->loginSucces($userInDB);
             } elseif ($userInDB->getDeleted()) {
                 // In user deleted, display a message and redirect to referer
                 Flash::addItem($accountDeleted);
                 $facebookSvc->cleanUser();
                 $facebookUser = null;
                 $faceBookEmail = null;
                 $facebookId = null;
                 HTTPHelper::redirectToReferer();
             } else {
                 // If yes => connect and redirect to user homepage
                 if (!$userInDB->getConnexionType() != ConnexionType::FACEBOOK) {
                     $userInDB->setConnexionType(ConnexionType::FACEBOOK);
                 }
                 if (!$userInDB->getFacebookId()) {
                     $userInDB->setFacebookId($facebookUser->getUid());
                 }
                 if (!$userInDB->getPicture()) {
                     $userInDB->setPicture($facebookUser->getPic_small());
                 }
                 if (!$userInDB->getPictureBig()) {
                     $userInDB->setPictureBig($facebookUser->getPic());
                 }
                 if (!$userInDB->getFacebookLanguage()) {
                     $userInDB->setFacebookLanguage($facebookUser->getLocale());
                 }
                 if (!$userInDB->getGender()) {
                     $userInDB->setGender($facebookUser->getSex());
                 }
                 if (!$userInDB->getCity()) {
                     $userInDB->setCity($facebookUser->getHometown_location());
                 }
                 if (!$userInDB->getBirthDay()) {
                     $userInDB->setBirthDay($facebookUser->getBirthday());
                 }
                 $userInDB->setLastLogin(new \DateTime());
                 UserDao::getInstance()->update($userInDB);
                 AuthentificationSvc::getInstance()->loginSucces($userInDB);
             }
         } else {
             // If no, redirect to facebook login page
             HTTPHelper::redirectToUrl($facebookSvc->getFacebookLogInUrl());
         }
     } catch (\Exception $e) {
         Trace::addItem(sprintf("Une erreur s'est produite dans \"%s->%s\", TRACE : %s\"", get_class(), __FUNCTION__, $e->getTraceAsString()));
         $this->forward("error", "error", "default");
     }
 }
Esempio n. 3
0
 public function logOffAction()
 {
     try {
         $globalConfig = new Sb\Config\Model\Config();
         if (isset($_COOKIES) && array_key_exists("PHPSESSID", $_COOKIES)) {
             unset($_COOKIES["PHPSESSID"]);
         }
         // destruction du cookie de connexion PHPSESSID 3600 correspond à 60 min
         if (ini_get("session.use_cookies")) {
             $params = session_get_cookie_params();
             setcookie(session_name(), '', time() - 3600, $params["path"], $params["domain"], $params["secure"], $params["httponly"]);
         }
         $tmpLang = null;
         if (isset($_SESSION) && array_key_exists('WPLANG', $_SESSION)) {
             $tmpLang = $_SESSION['WPLANG'];
         }
         session_destroy();
         $_SESSION['WPLANG'] = $tmpLang;
         $facebookSvc = new FacebookSvc($globalConfig->getFacebookApiId(), $globalConfig->getFacebookSecret(), HTTPHelper::Link(Urls::USER_HOME), HTTPHelper::Link(Urls::LOGIN), HTTPHelper::Link(Urls::LOGIN));
         $faceBookUser = $facebookSvc->getUser();
         $facebookSvc->cleanUser();
         if ($faceBookUser) {
             HTTPHelper::redirect($facebookSvc->getFacebookLogOutUrl());
         }
         Flash::addItem(__("Déconnexion réussie", "s1b"));
         // Redirecting to login page
         HTTPHelper::redirect("");
     } catch (\Exception $e) {
         Trace::addItem(sprintf("Une erreur s'est produite dans \"%s->%s\", TRACE : %s\"", get_class(), __FUNCTION__, $e->getTraceAsString()));
         $this->forward("error", "error", "default");
     }
 }