/**
  * Affiliates'levels.
  *
  * @return boolean
  */
 public static function auth()
 {
     $oSession = new Framework\Session\Session();
     $oBrowser = new Framework\Navigation\Browser();
     $bIsConnect = (int) $oSession->exists('affiliate_id') && $oSession->get('affiliate_ip') === Framework\Ip\Ip::get() && $oSession->get('affiliate_http_user_agent') === $oBrowser->getUserAgent();
     /** Destruction of the object and minimize CPU resources **/
     unset($oSession, $oBrowser);
     return $bIsConnect;
 }
Exemplo n.º 2
0
 /**
  * Users'levels.
  *
  * @return boolean
  */
 public static function auth()
 {
     $oSession = new Session();
     $oBrowser = new Browser();
     $bIsConnect = (int) $oSession->exists('member_id') && $oSession->get('member_ip') === Ip::get() && $oSession->get('member_http_user_agent') === $oBrowser->getUserAgent();
     /** Destruction of the object and minimize CPU resources **/
     unset($oSession, $oBrowser);
     return $bIsConnect;
 }
 /**
  * Parser for the System variables.
  *
  * @param string $sVar
  * @return The new parsed text
  */
 public function parse($sVar)
 {
     /*** Not to parse a text ***/
     if (preg_match('/#!.+!#/', $sVar)) {
         $sVar = str_replace(array('#!', '!#'), '', $sVar);
         return $sVar;
     }
     /***** Site Variables *****/
     $oRegistry = Registry::getInstance();
     $sVar = str_replace('%site_name%', $oRegistry->site_name, $sVar);
     $sVar = str_replace('%url_relative%', PH7_RELATIVE, $sVar);
     $sVar = str_replace(array('%site_url%', '%url_root%'), $oRegistry->site_url, $sVar);
     $sVar = str_replace('%url_static%', PH7_URL_STATIC, $sVar);
     $sVar = str_replace('%page_ext%', PH7_PAGE_EXT, $sVar);
     unset($oRegistry);
     /***** Affiliate Variables *****/
     $oSession = new Session();
     $sAffUsername = $oSession->exists('affiliate_username') ? $oSession->get('affiliate_username') : 'aid';
     $sVar = str_replace('%affiliate_url%', Uri::get('affiliate', 'router', 'refer', $sAffUsername), $sVar);
     unset($oSession);
     /***** Global Variables *****/
     $sVar = str_replace('%ip%', Ip::get(), $sVar);
     /***** Kernel Variables *****/
     $sVar = str_replace('%software_name%', Kernel::SOFTWARE_NAME, $sVar);
     $sVar = str_replace('%software_company%', Kernel::SOFTWARE_COMPANY, $sVar);
     $sVar = str_replace('%software_author%', 'Pierre-Henry Soria', $sVar);
     $sVar = str_replace('%software_version_name%', Kernel::SOFTWARE_VERSION_NAME, $sVar);
     $sVar = str_replace('%software_version%', Kernel::SOFTWARE_VERSION, $sVar);
     $sVar = str_replace('%software_build%', Kernel::SOFTWARE_BUILD, $sVar);
     $sVar = str_replace('%software_email%', Kernel::SOFTWARE_EMAIL, $sVar);
     $sVar = str_replace('%software_website%', Kernel::SOFTWARE_WEBSITE, $sVar);
     // Output
     return $sVar;
 }
 /**
  * @return boolean Return "true" If we believe that this person takes too much request otherwise "false"
  */
 public function session()
 {
     $oSession = new Session();
     if (!$oSession->exists(static::COOKIE_NAME)) {
         $oSession->set(static::COOKIE_NAME, 1);
     } else {
         $oSession->set(static::COOKIE_NAME, $oSession->get(static::COOKIE_NAME) + 1);
     }
     if ($oSession->get(static::COOKIE_NAME) > PH7_DDOS_MAX_SESSION_PAGE_LOAD) {
         $oSession->remove(static::COOKIE_NAME);
         // Remove Session
         $bStatus = true;
     } else {
         $bStatus = false;
     }
     unset($oSession);
     return $bStatus;
 }
 public static function checkGroup()
 {
     $oSession = new Framework\Session\Session();
     if (!$oSession->exists('member_group_id')) {
         $oSession->regenerateId();
         $oSession->set('member_group_id', '1');
         // By default, it's the Visitor's group (ID 1)
     }
     $rStmt = Db::getInstance()->prepare('SELECT permissions FROM' . Db::prefix('Memberships') . 'WHERE groupId = :groupId LIMIT 1');
     $rStmt->bindValue(':groupId', $oSession->get('member_group_id'), \PDO::PARAM_INT);
     $rStmt->execute();
     $oFetch = $rStmt->fetch(\PDO::FETCH_OBJ);
     Db::free($rStmt);
     unset($oSession);
     return Framework\CArray\ObjArr::toObject(unserialize($oFetch->permissions));
 }
Exemplo n.º 6
0
 /**
  * Constructor.
  *
  * @param object \PH7\Framework\Session\Session $oSession
  * @param object \PH7\Framework\Mvc\Request\Http $oHttpRequest
  * @param object \PH7\Framework\Registry\Registry $oRegistry
  * @return void
  */
 public function __construct(Session $oSession, HttpRequest $oHttpRequest, Registry $oRegistry)
 {
     parent::__construct();
     /*** Import the libraries ***/
     Import::lib('Service.Google.OAuth.Google_Client');
     Import::lib('Service.Google.OAuth.contrib.Google_Oauth2Service');
     $oClient = new \Google_Client();
     $oClient->setApplicationName($oRegistry->site_name);
     $this->_setConfig($oClient);
     $oOauth = new \Google_Oauth2Service($oClient);
     if ($oHttpRequest->getExists('code')) {
         $oClient->authenticate();
         $oSession->set('token', $oClient->getAccessToken());
         $this->sUrl = Uri::get('connect', 'main', 'home');
     }
     if ($oSession->exists('token')) {
         $oClient->setAccessToken($oSession->get('token', false));
     }
     if ($oClient->getAccessToken()) {
         // User info is ok? Here we will be connect the user and/or adding the login and registering routines...
         $oUserModel = new UserCoreModel();
         // Get information of user
         $aUserData = $oOauth->userinfo->get();
         if (!($iId = $oUserModel->getId($aUserData['email']))) {
             // Add User if it does not exist in our database
             $this->add(escape($aUserData, true), $oUserModel);
             // Add User Avatar
             if (!empty($aUserData['picture'])) {
                 $this->setAvatar($aUserData['picture']);
             }
             $this->oDesign->setFlashMsg(t('You have now been registered! %0%', (new Registration())->sendMail($this->_aUserInfo, true)->getMsg()));
             $this->sUrl = Uri::get('connect', 'main', 'register');
         } else {
             // Login
             $this->setLogin($iId, $oUserModel);
             $this->sUrl = Uri::get('connect', 'main', 'home');
         }
         // Add the access token
         $oSession->set('token', $oClient->getAccessToken());
         unset($oUserModel);
     } else {
         $this->sUrl = $oClient->createAuthUrl();
     }
     unset($oClient, $oOauth);
 }
Exemplo n.º 7
0
    protected function isOnline($sUsername)
    {
        $oUserModel = new UserCoreModel();
        $iProfileId = $oUserModel->getId(null, $sUsername);
        $bIsOnline = $oUserModel->isOnline($iProfileId, Framework\Mvc\Model\DbConfig::getSetting('userTimeout'));
        unset($oUserModel);
        return $bIsOnline;
    }
    protected function sanitize($sText)
    {
        $sText = escape($sText);
        $sText = str_replace("\n\r", "\n", $sText);
        $sText = str_replace("\r\n", "\n", $sText);
        $sText = str_replace("\n", "<br>", $sText);
        return $sText;
    }
    public function __destruct()
    {
        unset($this->_oHttpRequest, $this->_oMessengerModel);
    }
}
// Go only is the member id connected
if (UserCore::auth()) {
    $oSession = new Session();
    // Go start_session() function.
    if (empty($_SESSION['messenger_username'])) {
        $_SESSION['messenger_username'] = $oSession->get('member_username');
    }
    unset($oSession);
    new MessengerAjax();
}
 /**
  * If a user is logged, get "approximately" the relative age for better and more intuitive search.
  *
  * @param object \PH7\UserCoreModel $oUserModel
  * @param object \PH7\Framework\Session\Session $oSession
  * @return array 'min_age' and 'max_age' which is the approximately age the user is looking for.
  */
 protected static function getAgeVals(UserCoreModel $oUserModel, Session $oSession)
 {
     $iMinAge = (int) DbConfig::getSetting('minAgeRegistration');
     $iMaxAge = (int) DbConfig::getSetting('maxAgeRegistration');
     if (UserCore::auth()) {
         $sBirthDate = $oUserModel->getBirthDate($oSession->get('member_id'));
         $aAge = explode('-', $sBirthDate);
         $iAge = (new Year($aAge[0], $aAge[1], $aAge[2]))->get();
         $iMinAge = $iAge - 5 < $iMinAge ? $iMinAge : $iAge - 5;
         $iMaxAge = $iAge + 5 > $iMaxAge ? $iMaxAge : $iAge + 5;
     }
     return ['min_age' => $iMinAge, 'max_age' => $iMaxAge];
 }