public function init()
 {
     // Checks is user is connected
     AuthentificationSvc::getInstance()->checkUserIsConnected();
     $globalContext = new \Sb\Context\Model\Context();
     $this->context = $globalContext;
 }
 public function init()
 {
     // Checks is user is connected
     AuthentificationSvc::getInstance()->checkUserIsConnected();
     /* Initialize action controller here */
     $ajaxContext = $this->_helper->getHelper('AjaxContext');
     $ajaxContext->addActionContext('get-page', 'html')->addActionContext('sort', 'html')->initContext();
 }
Exemple #3
0
 public function __construct()
 {
     $this->setBaseDirectory(BASE_PATH);
     $this->setBaseUrl(BASE_URL);
     $this->setDefaultImage(\Sb\Helpers\BookHelper::getDefaultImage());
     // Set context param user
     $userId = \Sb\Authentification\Service\AuthentificationSvc::getInstance()->getConnectedUserId();
     if ($userId) {
         $user = \Sb\Db\Dao\UserDao::getInstance()->get($userId);
         $this->setConnectedUser($user);
     }
 }
 public function init()
 {
     // Checks is user is connected
     AuthentificationSvc::getInstance()->checkUserIsConnected();
 }
 public function profileAction()
 {
     $globalContext = new \Sb\Context\Model\Context();
     // Users profile are only accessible for connected users
     AuthentificationSvc::getInstance()->checkUserIsConnected();
     $noUser = true;
     $friendId = $this->_getParam("uid");
     if ($friendId) {
         $friend = UserDao::getInstance()->get($friendId);
         $this->view->friend = $friend;
         if ($friend) {
             $noUser = false;
             if ($friend->getId() == $globalContext->getConnectedUser()->getId()) {
                 Flash::addItem(__("Il s'agit de votre profil!", "s1b"));
                 HTTPHelper::redirectToReferer();
             } else {
                 $requestingUser = $globalContext->getConnectedUser();
                 if (SecurityHelper::IsUserAccessible($friend, $requestingUser)) {
                     $this->view->friendSetting = $friend->getSetting();
                     $this->view->isFriend = UserSvc::getInstance()->areUsersFriends($globalContext->getConnectedUser(), $friend);
                     // getting currently reading or lastly read books
                     $currentlyReading = UserBookDao::getInstance()->getReadingNow($friend->getId());
                     $lastlyReads = UserBookDao::getInstance()->getListLastlyRead($friend->getId());
                     if ($currentlyReading && $lastlyReads) {
                         $this->view->currentlyReadingOrLastlyReadBooks = array_merge(array($currentlyReading), $lastlyReads);
                     } elseif ($lastlyReads) {
                         $this->view->currentlyReadingOrLastlyReadBooks = $lastlyReads;
                     } elseif ($currentlyReading) {
                         $this->view->currentlyReadingOrLastlyReadBooks = array($currentlyReading);
                     }
                     // Getting friend currently reading user books
                     $this->view->allCurrentlyReadingUserBooks = UserBookDao::getInstance()->getCurrentlyReadingsNow($friend->getId());
                     if (count($this->view->allCurrentlyReadingUserBooks) > 1) {
                         $this->view->placeholder('footer')->append("<script src=\"" . $globalContext->getBaseUrl() . 'Resources/js/simple-carousel/simple.carousel.js' . "\"></script>\n");
                         $this->view->placeholder('footer')->append("<script>\$(function() {initCarousel('carousel-currentreadings', 298, 190)});</script>\n");
                     }
                     // Getting friend last boh books
                     $bohUserBooks = UserBookDao::getInstance()->getListUserBOH($friend->getId());
                     $this->view->bohBooks = array_map(array($this, "getBook"), $bohUserBooks);
                     // Getting books friend could like
                     $this->view->booksHeCouldLikes = BookSvc::getInstance()->getBooksUserCouldLike($friend->getId());
                     if ($this->view->booksHeCouldLikes && count($this->view->booksHeCouldLikes) > 0) {
                         $this->view->placeholder('footer')->append("<script src=\"" . $globalContext->getBaseUrl() . 'Resources/js/waterwheel-carousel/jquery.waterwheelCarousel.min.js' . "\"></script>\n");
                         $this->view->placeholder('footer')->append("<script>\$(function() {initCoverFlip('bookUserCouldLike', 90)});</script>\n");
                     }
                     // Getting friend's friends last reviews
                     $this->view->friendLastReviews = UserEventSvc::getInstance()->getUserLastEventsOfType($friend->getId(), EventTypes::USERBOOK_REVIEW_CHANGE);
                     // Getting friend last friends added events
                     $this->view->friendLastFriendsAddedEvents = UserEventSvc::getInstance()->getUserLastEventsOfType($friend->getId(), EventTypes::USER_ADD_FRIEND);
                     if (count($this->view->friendLastFriendsAddedEvents) > 1) {
                         $this->view->placeholder('footer')->append("<script src=\"" . $globalContext->getBaseUrl() . 'Resources/js/simple-carousel/simple.carousel.js' . "\"></script>\n");
                         $this->view->placeholder('footer')->append("<script>\$(function() {initCarousel('carousel-friendlastfriends', 298, 85)});</script>\n");
                     }
                     // Getting friend last events
                     $this->view->friendLastEvents = UserEventSvc::getInstance()->getUserLastEventsOfType($friend->getId(), null, 15);
                     $this->view->placeholder('footer')->append("<script>\n\n                            toInit.push(\"attachUserEventsExpandCollapse()\");\n\n                            function attachUserEventsExpandCollapse() {_attachExpandCollapseBehavior(\"js_userLastEvents\", \"userEvent\", \"Voir moins d'activités\", \"Voir plus d'activités\");}\n\n                        </script>\n");
                 } else {
                     Flash::addItem(__("Vous ne pouvez pas accéder à ce profil.", "s1b"));
                     HTTPHelper::redirectToReferer();
                 }
             }
         }
     }
     if ($noUser) {
         Flash::addItem(__("Cet utilisateur n'existe pas.", "s1b"));
         HTTPHelper::redirectToReferer();
     }
 }
 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");
     }
 }