/**
  * @param array $record         
  * @return array
  */
 public function __invoke(array $record)
 {
     // Real IP
     if (!empty($this->serverData['HTTP_CLIENT_IP'])) {
         // check ip from share internet
         $ipAddress = $this->serverData['HTTP_CLIENT_IP'];
     } elseif (!empty($this->serverData['HTTP_X_FORWARDED_FOR'])) {
         // to check ip is pass from proxy
         $ipAddress = $this->serverData['HTTP_X_FORWARDED_FOR'];
     } elseif (!empty($this->serverData['REMOTE_ADDR'])) {
         $ipAddress = $this->serverData['REMOTE_ADDR'];
     } else {
         $ipAddress = null;
     }
     $record['extra'] = array_merge($record['extra'], array('realIp' => $ipAddress));
     $session = Session::instance();
     if (!empty($session)) {
         $record['extra'] = array_merge($record['extra'], array('sessionId' => $session->getSessionId()));
         $credentials = $session->getCredentials()->getData();
         if (!empty($credentials)) {
             $record['extra'] = array_merge($record['extra'], array('credentials' => $credentials));
         }
     }
     return $record;
 }
Esempio n. 2
0
 /**
  * Returns the user record associated with a remember me cookie
  *
  * @return array
  * @throws \Exception
  */
 protected function getRememberMe()
 {
     $cookie = Session::instance()->getRememberMeCookie();
     $rawData = $cookie->getValue();
     $user = null;
     if (empty($rawData)) {
         goto end;
     }
     if (strlen($rawData) < 64) {
         goto cleanup;
     }
     $data = unserialize(Crypto::decrypt($rawData));
     if (!$data) {
         goto cleanup;
     }
     if (!isset($data['expires']) or !isset($data['userId'])) {
         goto cleanup;
     }
     $expires = Date::getDateTime($data['expires']);
     if ($expires <= Date::getDateTime()) {
         goto cleanup;
     }
     $user = UserService::instance()->getUserById(intval($data['userId']));
     goto end;
     cleanup:
     $cookie->clearCookie();
     end:
     return $user;
 }
Esempio n. 3
0
 /**
  * Flag a user session for update
  * @param int $userId
  */
 public function flagUserForUpdate($userId)
 {
     $user = UserService::instance()->getUserById($userId);
     $credentials = $this->getUserCredentials($user, 'session');
     if (Session::instance() != null && Session::getCredentials()->getUserId() == $userId) {
         // Update the current session if the userId is the same as the credential user id
         Session::updateCredentials($credentials);
         // Init / create the current users chat session
         ChatIntegrationService::instance()->setChatSession($credentials, Session::getSessionId());
     } else {
         // Otherwise set a session variable which is picked up by the remember me service to update the session
         $cache = Application::instance()->getCacheDriver();
         $cache->save(sprintf('refreshusersession-%s', $userId), time(), intval(ini_get('session.gc_maxlifetime')));
     }
     ChatIntegrationService::instance()->refreshChatUserSession($credentials);
 }
Esempio n. 4
0
 /**
  * Returns the remember me record for the current cookie
  *
  * @return array
  */
 protected function getRememberMe()
 {
     $rememberMeService = RememberMeService::instance();
     $cookie = Session::instance()->getRememberMeCookie();
     $token = $cookie->getValue();
     $rememberMe = null;
     // throw back to when I used a json string in the rememberme cookie
     // this is here so no-ones remember me cookie failed after upgrade.
     if (!empty($token) && $token[0] == "{") {
         $cookieData = @json_decode($token, true);
         if (!empty($cookieData) && isset($cookieData['token'])) {
             $token = $cookieData['token'];
         }
     }
     // If the token is not empty query the DB for the remember me record
     if (!empty($token)) {
         $rememberMe = $rememberMeService->getRememberMe($token, 'rememberme');
     }
     return $rememberMe;
 }