/** * * @return \Doctrine\ORM\EntityManager */ private static function getEntityManager() { $sbConfig = new \Sb\Config\Model\Config(); $cache = new \Doctrine\Common\Cache\ApcCache(); $cache->setNamespace($sbConfig->getApcCacheNamespace()); $config = new \Doctrine\ORM\Configuration(); $driverImpl = $config->newDefaultAnnotationDriver(array("/Sb/Db/Model")); $config->setMetadataDriverImpl($driverImpl); // settings caches $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $config->setResultCacheImpl($cache); $config->setProxyDir("Sb/Db/Proxies"); $config->setProxyNamespace('Proxies'); $config->setAutoGenerateProxyClasses(false); $connectionOptions = array('driver' => 'pdo_mysql', 'user' => $sbConfig->getDatabaseParams()->user, 'password' => $sbConfig->getDatabaseParams()->password, 'host' => $sbConfig->getDatabaseParams()->host, 'dbname' => $sbConfig->getDatabaseParams()->name); // Create EntityManager $entityManager = \Doctrine\ORM\EntityManager::create($connectionOptions, $config); $entityManager->getEventManager()->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit('utf8', 'utf8_general_ci')); return $entityManager; }
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"); } }
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"); } }
public function submitImportAction() { try { $globalContext = new \Sb\Context\Model\Context(); $globalConfig = new Sb\Config\Model\Config(); $tpl = new \Sb\Templates\Template("import"); $isbnsInFile = $this->getIsbnsInFile($globalContext); if ($isbnsInFile) { if (count($isbnsInFile) > $globalConfig->getMaxImportNb()) { Flash::addItem(sprintf(__("Il n'est pas possible d'importer plus de %s livres.", "s1b"), $globalConfig->getMaxImportNb())); } else { //\Sb\Flash\Flash::addItem(count($isbnsInFile) . " ont été soumis dans votre fichier d'import."); Flash::addItem(sprintf(__("%s livre(s) ont été soumis dans votre fichier d'import.", "s1b"), count($isbnsInFile))); /// RECHERCHE DES LIVRES (base et amazon) $resultingBooks = $this->searchBooks($isbnsInFile, $globalConfig); /// AJOUT DES LIVRES dans la base $booksAlReadyImported = array(); $booksCorrectlyImported = array(); $this->loadBooks($resultingBooks, $booksAlReadyImported, $booksCorrectlyImported, $globalContext); // MET A JOUR le résumé de l'import $this->updateSummary($isbnsInFile, $tpl, $booksAlReadyImported, $booksCorrectlyImported, $globalContext); } } else { $tpl->set("summary", ""); Flash::addItem(__("Aucun ISBN n'a pu être lu dans le fichier soumit.", "s1b")); } } 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"); } }