public static function load($blog_id = null, $user_id = null, $include_count = true, $offset = 0, $limit = BLOG_DISPLAY_LIMIT) { $filters = array(); $current_user = \Warden::current_user(); $result = array('data' => array(), 'count' => 0); if (empty($blog_id)) { if (empty($user_id)) { $filters['public_flag'] = true; //only load public blogs if not loading a specific user's blog if (!$current_user || !\Access::can('publicize_any_blog', $current_user)) { $filters['publish_flag'] = true; //only load published blogs if the user is not privileged to publicize any blog } } else { if (!$current_user || $user_id != $current_user->id) { $filters['publish_flag'] = true; //only load published blogs if the user is loading a blog that's not their own } $filters['user_id'] = $user_id; //load blogs for the specified user only } $result['data'] = static::get_where($filters, $offset, $limit); } else { $result['data'] = static::get_where(array('id' => $blog_id, 0, 1)); } if (!empty($result['data'])) { $result['count'] = $include_count ? static::get_count($filters) : count($result['data']); } return $result; }
public function before() { parent::before(); // Assign current_user to the instance so controllers can use it $this->user = Warden::check() ? Warden::current_user() : null; if (!$this->user) { $this->response(array('status' => 0, 'error' => 'Not Authorized'), 401); } }
public function before() { parent::before(); // setup login and logout callbacks Warden::after_authentication(function ($user) { Session::set('warden.user.username', $user->username); //add username to the session so it can be used for chat }); Warden::before_logout(function ($user) { Session::delete('warden.user.username'); //delete username from the session when we logout }); // Assign current_user to the instance so controllers can use it $this->user = Warden::check() ? Warden::current_user() : null; // Set a global variable so views can use it View::set_global('current_user', $this->user); $this->client_scripts_included = array(); $this->template->scripts = array(); $this->template->css = array(); $this->template->metatags = array(); $this->include_client_scripts(); }
public static function unassign_role($role_id, $user = null) { if (empty($user)) { $user = \Warden::current_user(); } else { if (!is_object($user)) { $user = \Warden\Model_User::find($user); } } if (!$user || !is_object($user)) { throw new \Exception("Cannot assign role to a user that doesn't exist"); } try { if (isset($user->roles[$role_id])) { unset($user->roles[$role_id]); $user->save(); } } catch (\Exception $e) { throw $e; } }