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(); }
<?php require_once 'core/init.php'; $options = ''; $title = 'Block'; $user = new User(); $GroupNo = $user->data()->GroupNo; if ($GroupNo == 3) { $user = new Admin(); } if ($GroupNo == 2) { $user = new Warden(); } if (!$user->isLoggedIn()) { Redirect::to('login.php'); } if (@$_POST['block_id']) { $validate = new Validate(); $validation = $validate->check($_POST, array('block_id' => array('required' => true, 'unique' => 'block'), 'num_of_rooms' => array('required' => true, 'min' => 1), 'gender_code' => array('required' => true))); if ($validation->passed()) { $block = new Block(); try { $block->add_block(array('block_id' => Input::get('block_id'), 'block_cap' => Input::get('num_of_rooms'), 'block_gen' => Input::get('gender_code'))); echo 'Block ' . Input::get('block_id') . ' added'; } catch (Exception $e) { die($e->getMessage()); } } else { echo 'Validation failed'; foreach ($validation->errors() as $error) { $displayerror .= $error . '<br>';
/** * Completes a login by assigning the user to the session key. * * @param \Warden\Model_User $user * * @return bool */ protected function complete_login(Model_User $user) { // Create and set new authentication token $user->authentication_token = Warden::forge()->generate_token(); try { if ($this->config['trackable'] === true) { $user->update_tracked_fields(); } else { if ($this->config['lockable']['in_use'] === true) { $strategy = $this->config['lockable']['lock_strategy']; if (!empty($strategy) && $strategy != 'none') { $user->{$strategy} = 0; } } $user->save(false); } \Session::set('authenticity_token', $user->authentication_token); \Session::instance()->rotate(); $this->set_user($user); $this->_run_event('after_authentication'); return true; } catch (\Exception $ex) { logger(\Fuel::L_ERROR, 'Warden authentication failed because an exception was thrown: ' . $ex->getMessage()); return false; } }
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; } }
/** * Validates a user password & ensures an encrypted password is set * * @see \Warden\Model_User::_event_before_save() */ private function _ensure_and_validate_password() { if (!empty($this->password)) { if (\Str::length($this->password) < 6) { throw new \Orm\ValidationFailed(__('warden.validation.password.too_short')); } elseif (!preg_match(self::REGEX_PASSWORD, $this->password)) { throw new \Orm\ValidationFailed(__('warden.validation.password.invalid')); } $this->encrypted_password = Warden::encrypt_password($this->password); } if (empty($this->encrypted_password)) { throw new \Orm\ValidationFailed(__('warden.validation.password.required')); } }
require_once 'core/init.php'; $options = ''; $title = 'Database'; $user = new User(); $rank = $user->data()->GroupNo; if (!$user->isLoggedIn()) { Redirect::to('login.php'); } Session::put('CPage', 'Database.php'); $options = getNavBar($rank); if ($rank == 3) { $user = new Admin(); } else { if ($rank == 2) { $user = new Warden(); } } if (Input::exists('get')) { if ($rank == 3) { if (Input::get('deleting')) { $user->delete_User(Input::get('deleting')); echo 'Done'; } if (Input::get('verify')) { $user->Verify_Student(Input::get('verify')); echo 'Done'; } } if ($rank == 2 || $rank == 3) { if (Input::get('profile')) {
/** * Logs a user in. * * @param string $username_or_email * @param string $password * @param bool $remember * * @return bool * * @throws \Warden\Failure If lockable enabled & attempts exceeded */ public function authenticate_user($username_or_email, $password, $remember) { if (($user = \Model_User::authenticate($username_or_email, false, false)) && Warden::has_password($user, $password)) { if ($user->is_confirmation_required()) { throw new Failure('unconfirmed', array(), $user); } elseif ($user->is_access_locked()) { throw new Failure('locked'); } if ($remember === true && $this->config['rememberable']['in_use'] === true) { // Set token data $user->remember_token = Warden::forge()->generate_token(); // Set the remember-me cookie \Cookie::set($this->config['rememberable']['key'], $user->remember_token, $this->config['rememberable']['ttl'], null, null, null, true); } return $this->complete_login($user); } if (!is_null($user) && $this->config['lockable']['in_use'] === true) { $user->update_attempts(1); } // Login failed return false; }
/** * Validates a user password & ensures an encrypted password is set * * @see \Warden\Model_User::_event_before_save() */ private function _ensure_and_validate_password() { if (\Config::get('warden.password.validate') !== true) { return; } $min_length = \Config::get('warden.password.min_length', 6); $max_length = \Config::get('warden.password.max_length', 32); if (!empty($this->password)) { if (\Str::length($this->password) < $min_length) { throw new \Orm\ValidationFailed(__('warden.validation.password.too_short', array('count' => $min_length))); } elseif (\Str::length($this->password) > $max_length) { throw new \Orm\ValidationFailed(__('warden.validation.password.too_long', array('count' => $max_length))); } $this->encrypted_password = Warden::encrypt_password($this->password); } if (empty($this->encrypted_password)) { throw new \Orm\ValidationFailed(__('warden.validation.password.required')); } }
public function action_logout() { Warden::logout(); Response::redirect('/welcome'); }