Ejemplo n.º 1
0
 /**
  * Check Remember Me
  *
  * This method checks whether RememberMe cookie exists
  * If it does, get the user credentials and make it global for easy use
  * If not, just route the login page
  *
  * @param  ServerRequestInterface $req  PSR-7 Request
  * @param  ResponseInterface      $res  PSR-7 Response
  *
  * @return callable
  */
 protected function checkRememberMe(Request $req, Response $res)
 {
     dd(Cookies::get('hihi'));
     die;
     $cookie = $this->app->cookies->get($this->c['myConfig']->get('auth.remember'));
     if ($cookie && !$this->app->auth) {
         $credentials = explode('___', $cookie);
         // If the cookie isn't valid
         if (empty(trim($cookie)) || count($credentials) !== 2) {
             return $res->withHeader('Location', $this->app->router->pathFor('login'));
         }
         $identifier = $credentials[0];
         $hashLib = $this->c->get('hash');
         $token = $hashLib->hash($credentials[1]);
         $user = User::where('remember_identifier', $identifier)->first();
         if ($user) {
             if ($hashLib->hashCheck($token, $user->remember_token)) {
                 // Finally, user can login
                 $_SESSION[$this->c['myConfig']->get('auth.session')] = $user->user_id;
                 $this->app->auth = $user;
             } else {
                 $user->removeRememberCredentials();
             }
         }
         // Endif user is found in DB
     }
     // Endif the cookie is there
 }
Ejemplo n.º 2
0
 /**
  * @return bool
  */
 public function validateSession()
 {
     $session_token = $this->_cookies->get("session_token");
     if (!is_null($session_token)) {
         $remember_token = $this->generateRememberToken($session_token);
         $retrieveUser = $this->_options->get("retrieveUser");
         if (is_callable($retrieveUser)) {
             $user = $retrieveUser($remember_token);
             if ($user instanceof AuthUserInterface) {
                 $this->_user = $user;
                 $this->_authenticated = true;
                 return true;
             }
         } else {
             throw new \RuntimeException("The option 'retrieveUser' must be callable.");
         }
     }
     return false;
 }
Ejemplo n.º 3
0
 /**
  * Used by slim to render out cookies. Never retrieve response cookies within the application!
  */
 public function getResponseCookie($key)
 {
     if (!($cookie = parent::get($key))) {
         return null;
     }
     $value = array_key_exists('value', $cookie) ? $cookie['value'] : null;
     if ($value) {
         $value = $this->json->encode($value);
         if (!in_array($key, $this->unencryptedCookies)) {
             $value = $this->encryption->encrypt($value);
         }
     }
     $cookie['value'] = $value;
     return $cookie;
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function get($name, $default = null)
 {
     $name = $this->getFullName($name);
     return parent::get($name, $default);
 }