Пример #1
0
 /**
  * sets identifying cookie to user and saves it to DB table `user`
  */
 public function setUserCookie()
 {
     $userCookie = $this->httpRequest->getCookie('rabbit_user');
     if ($userCookie === NULL) {
         $hash = md5(time());
         //saves cookie to user for 1 month since now
         $this->httpResponse->setCookie('rabbit_user', $hash, \Nette\Utils\DateTime::from('now')->modifyClone('+1 month'));
         //saves to DB
         $this->userRepository->insert(['hash' => $hash]);
     }
 }
Пример #2
0
 /**
  * Sends a cookie.
  * 
  * @param type $name
  * @param type $value
  * @param type $time       if time argument is not given, uses time given in options
  * @param type $path
  * @param type $domain
  * @param type $secure
  * @param type $httpOnly
  */
 public function set($name, $value, $time = null, $path = null, $domain = null, $secure = null, $httpOnly = null)
 {
     if ($time === null) {
         $time = $this->_options['time'];
     }
     if ($path === null) {
         $path = $this->_options['path'];
     }
     if ($domain === null) {
         $domain = $this->_options['domain'];
     }
     if ($secure === null) {
         $secure = $this->_options['secure'];
     }
     if ($httpOnly === null) {
         $httpOnly = $this->_options['httpOnly'];
     }
     $this->_response->setCookie($name, $value, $time, $path, $domain, $secure, $httpOnly);
 }
 /**
  * Saves the JWT Access Token into HTTP cookie.
  */
 private function saveJWTCookie()
 {
     if (empty($this->jwtData)) {
         $this->response->deleteCookie(self::COOKIE_NAME);
         return;
     }
     if ($this->generateIat) {
         $this->jwtData['iat'] = DateTime::from('NOW')->format('U');
     }
     // Unset JTI if there was any
     unset($this->jwtData['jti']);
     if ($this->generateJti) {
         // Generate new JTI
         $this->jwtData['jti'] = hash('sha256', serialize($this->jwtData) . Random::generate(10));
     }
     // Encode the JWT and set the cookie
     $jwt = $this->jwtService->encode($this->jwtData, $this->privateKey, $this->algorithm);
     $this->response->setCookie(self::COOKIE_NAME, $jwt, $this->expirationTime);
     $this->cookieSaved = true;
     // Set cookie saved flag to true, so loadJWTCookie() doesn't rewrite our data
 }
Пример #4
0
 /**
  * Set cookie with social login service
  * @param $socialServiceName Social service name for
  */
 protected function setSocialLoginCookie($socialServiceName)
 {
     $this->httpResponse->setCookie($this->cookieName, $socialServiceName, 0);
 }