Inheritance: extends User
 /**
  * Try to login with Facebook
  * @param array
  * @return boolean
  */
 public function login($arrProfile = null)
 {
     if (parent::login() === true) {
         return true;
     }
     // Return if the user is not found
     if (!$arrProfile || $this->findBy('fblogin', $arrProfile['id']) == false) {
         \Message::addError($GLOBALS['TL_LANG']['ERR']['invalidLogin']);
         return false;
     }
     // Return if the user ID does not match
     if (!$this->fblogin || $this->fblogin != $arrProfile['id']) {
         \Message::addError($GLOBALS['TL_LANG']['ERR']['invalidLogin']);
         return false;
     }
     $this->setUserFromDb();
     // Update the record
     $this->lastLogin = $this->currentLogin;
     $this->currentLogin = time();
     $this->loginCount = $GLOBALS['TL_CONFIG']['loginCount'];
     $this->save();
     // Generate the session
     $this->generateSession();
     $this->log('User "' . $this->username . '" has logged in', get_class($this) . ' login()', TL_ACCESS);
     // HOOK: post login callback
     if (isset($GLOBALS['TL_HOOKS']['postLogin']) && is_array($GLOBALS['TL_HOOKS']['postLogin'])) {
         foreach ($GLOBALS['TL_HOOKS']['postLogin'] as $callback) {
             $this->import($callback[0], 'objLogin', true);
             $this->objLogin->{$callback}[1]($this);
         }
     }
     return true;
 }
Example #2
0
 /**
  * Tests an unauthenticated user.
  *
  * @runInSeparateProcess
  * @preserveGlobalState disabled
  * @expectedException \Symfony\Component\Security\Core\Exception\UsernameNotFoundException
  */
 public function testUnauthenticatedUser()
 {
     /** @var FrontendUser|object $user */
     $user = FrontendUser::getInstance();
     $user->authenticated = false;
     new ContaoToken($user);
 }
 /**
  * {@inheritdoc}
  *
  * @return BackendUser|FrontendUser The user object
  */
 public function loadUserByUsername($username)
 {
     $this->framework->initialize();
     if ($this->isBackendUsername($username)) {
         return BackendUser::getInstance();
     }
     if ($this->isFrontendUsername($username)) {
         return FrontendUser::getInstance();
     }
     throw new UsernameNotFoundException('Can only load user "frontend" or "backend".');
 }
 /**
  * {@inheritdoc}
  */
 public function prepareRules(IFilter $objFilter, $arrFilterUrl)
 {
     $member = FrontendUser::getInstance();
     if ($this->get('member_group') && $member->isMemberOf($this->get('member_group')) && !$this->get('no_member')) {
         foreach ($this->arrChildren as $objChildSetting) {
             $objChildSetting->prepareRules($objFilter, $arrFilterUrl);
         }
     }
     if ($this->get('no_member') && !FE_USER_LOGGED_IN) {
         foreach ($this->arrChildren as $objChildSetting) {
             $objChildSetting->prepareRules($objFilter, $arrFilterUrl);
         }
     }
 }
 /**
  * Check the permission
  *
  * @param array $entry
  *
  * @return bool
  */
 private function checkPermission(array $entry)
 {
     if (!$this->isInternalLink($entry)) {
         return true;
     }
     if (($pageModel = $this->fetchPageModel($entry)) === null) {
         return false;
     }
     $pageModel->loadDetails();
     // Check if user is logged in
     if (!FE_USER_LOGGED_IN && $pageModel->protected && !BE_USER_LOGGED_IN) {
         return false;
     }
     // Check the user groups if the page is protected
     if ($pageModel->protected && !BE_USER_LOGGED_IN) {
         $groups = $pageModel->groups;
         // required for empty()
         if (!is_array($groups) || empty($groups) || !count(array_intersect($groups, FrontendUser::getInstance()->groups))) {
             return false;
         }
     }
     return true;
 }
 /**
  * Retrieves the currently logged in user
  *
  * Usage:
  *
  *      $phpbbuser = System::getContainer()->get('phpbb_bridge.connector')->getCurrentUser();
  *      echo $phpbbuser->username
  *      echo $phpbbuser->user_email
  *      echo $phpbbuser->user_birthday
  *
  * @todo Should we check if frontend user is also logged in on contao side?
  *
  * @return object|null
  * @throws \Exception
  */
 public function getCurrentUser()
 {
     if ($this->debug) {
         System::log("phpbb_bridge: " . __METHOD__, __METHOD__, TL_ACCESS);
     }
     // unset any session data if the session does not belong to a member
     if (!FE_USER_LOGGED_IN) {
         System::getContainer()->get('session')->set('phpbb_user', null);
     }
     // Checks session if user data is already initialized (and not anonym user) or tries to check status (which then set user data to session)
     if (FE_USER_LOGGED_IN && System::getContainer()->get('session')->get('phpbb_user', null) === null) {
         $user = FrontendUser::getInstance();
         // Test if user is member of forum groups. Only throws a warning atm
         // @todo Make being member of forum group mandatory?
         $isForumMember = false;
         foreach ($this->getForumMemberGroupIds() as $groupId) {
             if ($user->isMemberOf($groupId)) {
                 $isForumMember = true;
                 continue;
             }
         }
         $phpbbUser = $this->getUser($user->username);
         // Throw warning if a adequate phpbb user was found but the contao member is not member of forum groups
         if ($phpbbUser !== null && $isForumMember === false) {
             System::log('Warning: Found Forum user but not being member of forum member groups. Maybe reassign or clear', __METHOD__, TL_ERROR);
         }
         System::getContainer()->get('session')->set('phpbb_user', $phpbbUser);
     }
     return System::getContainer()->get('session')->get('phpbb_user', null);
 }
Example #7
0
 /**
  * Check whether an element is visible in the front end
  *
  * @param \Model|\ContentModel|\ModuleModel $objElement The element model
  *
  * @return boolean True if the element is visible
  */
 public static function isVisibleElement(\Model $objElement)
 {
     // Only apply the restrictions in the front end
     if (TL_MODE != 'FE' || BE_USER_LOGGED_IN) {
         return true;
     }
     $blnReturn = true;
     // Protected element
     if ($objElement->protected) {
         if (!FE_USER_LOGGED_IN) {
             $blnReturn = false;
         } else {
             $groups = deserialize($objElement->groups);
             if (empty($groups) || !is_array($groups) || !count(array_intersect($groups, \FrontendUser::getInstance()->groups))) {
                 $blnReturn = false;
             }
         }
     } elseif ($objElement->guests && FE_USER_LOGGED_IN) {
         $blnReturn = false;
     }
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['isVisibleElement']) && is_array($GLOBALS['TL_HOOKS']['isVisibleElement'])) {
         foreach ($GLOBALS['TL_HOOKS']['isVisibleElement'] as $callback) {
             $blnReturn = static::importStatic($callback[0])->{$callback}[1]($objElement, $blnReturn);
         }
     }
     return $blnReturn;
 }
 /**
  * Logout a user from contao via incoming phpbb logout request
  *
  * @Route("/logout")
  */
 public function logoutAction()
 {
     $this->validateRequest();
     $user = FrontendUser::getInstance();
     $result = $user->logout();
     $response = new JsonResponse();
     $response->setData(array('logout_status' => $result));
     return $response;
 }