Пример #1
0
 public function initAuthenticatedUser(User $activeUser)
 {
     $_SESSION['Auth'] = array('Email' => $activeUser->getEmail(), 'Password' => $activeUser->getPassword(), 'Id' => $activeUser->getId());
     if ($activeUser->getFacebookId()) {
         $_SESSION['Auth']['FacebookId'] = $activeUser->getFacebookId();
     }
     // If a return url is in session unset it and redirect to it
     $returnUrl = ArrayHelper::getSafeFromArray($_SESSION, SessionKeys::RETURN_URL_AFTER_LOGIN, null);
     if ($returnUrl) {
         unset($_SESSION[SessionKeys::RETURN_URL_AFTER_LOGIN]);
         HTTPHelper::redirectToUrl($returnUrl);
     }
 }
Пример #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");
     }
 }
Пример #3
0
 /**
  * Store book to add in cache and redirect to correct page
  */
 public function prepareAddAction()
 {
     try {
         $globalContext = new \Sb\Context\Model\Context();
         // checking if book is already in DB
         $isBookInDb = false;
         $bookInUserLib = false;
         if ($globalContext->getIsShowingFriendLibrary()) {
             Flash::addItem(__("Vous ne pouvez pas ajouter un livre à la bibliothèque d'un ami.", "s1b"));
         }
         $destination = HTTPHelper::Link(Urls::USER_BOOK_ADD_CHOICE, null, false, false);
         if (ArrayHelper::getSafeFromArray($_POST, Constants::BORROW_FROM_FRIENDS, null)) {
             $destination = HTTPHelper::Link(Urls::USER_BOOK_BORROW_FROM_FRIENDS, null, false, false);
         }
         // Remove book to add in cache
         ZendFileCache::getInstance()->remove(Constants::BOOK_TO_ADD_PREFIX . session_id());
         // Get Book from POST
         $book = new Book();
         BookMapper::map($book, $_POST, "book_");
         if ($book->getId()) {
             $isBookInDb = true;
         } else {
             $bookInDb = BookDao::getInstance()->getOneByCodes($book->getISBN10(), $book->getISBN13(), $book->getASIN());
             if ($bookInDb) {
                 $isBookInDb = true;
                 $book = $bookInDb;
             }
         }
         // Si le livre existe déjà en base
         // Vérification de l'existence du livre pour l'utilisateur
         // et si oui redirection vers la page d'édition
         if ($isBookInDb) {
             $userBook = UserBookDao::getInstance()->getByBookIdAndUserId($globalContext->getConnectedUser()->getId(), $book->getId());
             if ($userBook && !$userBook->getIs_deleted()) {
                 $bookInUserLib = true;
                 // If the user is trying to borrow the book we display a flash message
                 if (ArrayHelper::getSafeFromArray($_POST, Constants::BORROW_FROM_FRIENDS, null)) {
                     Flash::addItem(__("Vous avez déjà ce livre dans votre bibliothèque.", "s1b"));
                 }
             }
         }
         // On complète les infos qui manquent éventuellement
         if (!$book->IsComplete()) {
             Trace::addItem('Requêtage de Google.');
             BookHelper::completeInfos($book);
         }
         if (!$book->IsValid()) {
             Flash::addItem('Il manque certaines données pour ajouter ce livre à notre base de données.');
             HTTPHelper::redirectToReferer();
         } else {
             ZendFileCache::getInstance()->save($book, Constants::BOOK_TO_ADD_PREFIX . session_id());
         }
         if ($isBookInDb) {
             if ($bookInUserLib) {
                 HTTPHelper::redirectToUrl(HTTPHelper::Link($book->getLink()));
             } else {
                 HTTPHelper::redirectToUrl($destination);
             }
         } else {
             HTTPHelper::redirectToUrl($destination);
         }
     } 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");
     }
 }