/** * 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); }
/** * @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'); // Visitor's group } unset($oSession); $rStmt = Db::getInstance()->prepare('SELECT permissions FROM' . Db::prefix('Memberships') . 'WHERE groupId = :groupId LIMIT 1'); $rStmt->bindParam(':groupId', $_SESSION[Framework\Config\Config::getInstance()->values['session']['prefix'] . 'member_group_id'], \PDO::PARAM_INT); $rStmt->execute(); $oFetch = $rStmt->fetch(\PDO::FETCH_OBJ); Db::free($rStmt); return Framework\CArray\ObjArr::toObject(unserialize($oFetch->permissions)); }
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)); }
/** * Set a user authentication. * * @param object $oUserData User database object. * @param object \PH7\UserCoreModel $oUserModel * @param object \PH7\Framework\Session\Session $oSession * @return void */ public function setAuth($oUserData, UserCoreModel $oUserModel, Session $oSession) { // Is disconnected if the user is logged on as "affiliate" or "administrator". if (AffiliateCore::auth() || AdminCore::auth()) { $oSession->destroy(); } // Regenerate the session ID to prevent the session fixation $oSession->regenerateId(); // Now we connect the member $aSessionData = ['member_id' => $oUserData->profileId, 'member_email' => $oUserData->email, 'member_username' => $oUserData->username, 'member_first_name' => $oUserData->firstName, 'member_sex' => $oUserData->sex, 'member_group_id' => $oUserData->groupId, 'member_ip' => Ip::get(), 'member_http_user_agent' => (new Browser())->getUserAgent(), 'member_token' => Various::genRnd($oUserData->email)]; $oSession->set($aSessionData); (new Framework\Mvc\Model\Security())->addLoginLog($oUserData->email, $oUserData->username, '*****', 'Logged in!'); $oUserModel->setLastActivity($oUserData->profileId); unset($oUserModel, $oUserData); }