public function before() { $this->id = isset($this->uri[1]) ? $this->uri[1] : false; $this->user = UserModel::findById(new \MongoId($this->id)); if (!$this->user) { header('Location: /'); exit; } $this->set('u', $this->user); }
public function check() { $this->cookie = 'u' . crc32($this->cookie . '.' . COOKIE_DOMAIN); $cookie = isset($_COOKIE[$this->cookie]) ? $_COOKIE[$this->cookie] : ''; if (!$cookie) { return; } $data = $this->decrypt($cookie); list($id, $token) = explode(':', $data); if (!$id || !$token) { return; } $user = User::findById(new MongoId($id)); if (!$user) { return; } if ($user->token !== $token) { return; } // Populate User Data $this->id = $user->id; $this->user = $user; }