get() static public méthode

Get a cookie value
static public get ( string $key, string $default = null ) : mixed
$key string The name of the cookie
$default string The default value, which should be returned if the cookie has not been found
Résultat mixed The found value
 function init() {
     if(!union::getconfig('enabled')) {
         echo '<script type="text/javascript">alert("'.lang('推广联盟未开启,转让会员中心!').'")</script>';
         front::refresh(url::create('user/index'));
     }
     $user='';
     if(cookie::get('login_username') &&cookie::get('login_password')) {
         $user=new user();
         $user=$user->getrow(array('username'=>cookie::get('login_username')));
     }
     if(!is_array($user) &&front::$act != 'into'&&front::$act != 'login'&&front::$act != 'register'&&front::$act != 'login_js'&&front::$act != 'login_success'&&front::$act != 'getpass'&&front::$act != 'edit'){
     	front::redirect(url::create('user/login'));
     }else{
     	if (is_array($user) && cookie::get('login_password') == front::cookie_encode($user['password'])) {
     		$this->view->user = $user;
     		$this->view->usergroupid = $user['groupid'];
     		$obj = new usergroup();
     		$this->roles = $obj->getrow(array('groupid'=>$this->view->usergroupid));
     	}
     }
     $this->_user=new user;
     $this->view->form = $this->_user->get_form();
     $this->view->field = $this->_user->getFields();
     $this->view->primary_key=$this->_user->primary_key;
     $this->view->data = $this->view->user;
     $this->_union = new union();
     $this->view->uniondata = $this->_union->getrow(array('userid'=>$this->view->data['userid']));
     if(!$this->view->uniondata &&front::$act != 'register'&&front::$act != 'into') {
         echo '<script type="text/javascript">alert("'.lang('未申请账号,转入联盟申请页面!').'");window.location.href="'.url::create('union/register').'";</script>';
         //front::refresh(url::create('union/register'));
     }
     $this->_pagesize=config::get('manage_pagesize');
 }
Exemple #2
0
 /**
  * Methode : page de détail d'une user
  */
 public function show($idQuete = false)
 {
     if (!$idQuete || !is_numeric($idQuete)) {
         return parent::redirect_erreur('quetes');
     }
     cookie::set('UserFilesPath', url::base() . '../images/quetes/' . $idQuete);
     cookie::set('UserFilesAbsolutePath', DOCROOT . '../images/quetes/' . $idQuete);
     if (!cookie::get('UserFilesPath')) {
         return url::redirect('quetes/show/' . $idQuete);
     }
     if (!($quete = $this->quete->select(array('id_quete' => $idQuete), 1))) {
         return parent::redirect_erreur('quetes');
     }
     if (!($module = Map_Model::instance()->select(array('module_map' => 'quete'), false))) {
         return url::redirect('regions?msg=' . urlencode(Kohana::lang('quete.no_module')));
     }
     $this->script = array('js/lib/jquery.validate', 'js/lib/jquery.facebox', 'js/quetes');
     $this->css = array('form', 'quete', 'facebox');
     $this->template->titre = array(Kohana::lang('quete.all_quetes') => 'quetes', Kohana::lang('quete.show_title', ucfirst(mb_strtolower($quete->title))) => NULL);
     $this->template->button = TRUE;
     $this->template->navigation = parent::navigation($idQuete, 'id_quete', 'quetes');
     $this->template->contenu = new View('formulaire/form');
     $this->template->contenu->action = 'quetes/save';
     $this->template->contenu->id = $idQuete;
     $this->template->contenu->formulaire = new View('quetes/show');
     $this->template->contenu->formulaire->row = $quete;
     $this->template->contenu->formulaire->module = $module;
     $this->template->contenu->formulaire->bots = Map_Model::instance()->select(array('module_map' => 'fight'), false);
     $this->template->contenu->formulaire->quete = $this->quete->select(array('id_quete !=' => $idQuete));
 }
Exemple #3
0
 /**
  * Methode : page de détail d'un article
  */
 public function show($idActualite = FALSE)
 {
     if (!$idActualite || !is_numeric($idActualite)) {
         return parent::redirect_erreur('articles');
     }
     cookie::set('UserFilesPath', url::base() . '../images/articles/' . $idActualite);
     cookie::set('UserFilesAbsolutePath', DOCROOT . '../images/articles/' . $idActualite);
     if (!cookie::get('UserFilesPath')) {
         return url::redirect('articles/show/' . $idActualite);
     }
     if (!($actualite = $this->acticles->select(array('id_article' => $idActualite), TRUE))) {
         return parent::redirect_erreur('articles');
     }
     $actualiteCategories = $this->acticles->selectListeCategories();
     $this->script = array('js/lib/jquery.validate', 'js/articles');
     $this->css = array('form', 'article');
     $this->template->titre = array(Kohana::lang('article.all_article') => 'articles', $actualite->title => NULL);
     $this->template->button = TRUE;
     $this->template->navigation = $this->acticles->navigation($idActualite, 'id_article', 'articles');
     $this->template->navigationURL = 'articles/show';
     $this->template->contenu = new View('formulaire/form');
     $this->template->contenu->action = 'articles/save';
     $this->template->contenu->id = $idActualite;
     $this->template->contenu->formulaire = new View('articles/show');
     $this->template->contenu->formulaire->row = $actualite;
     $this->template->contenu->formulaire->actualiteCategories = $actualiteCategories;
     $this->template->contenu->formulaire->regions = Region_Model::instance()->listing_parent();
 }
 function init() {
     $user='';
     $guest = front::get('guest');
     if($guest=='1'&&config::get('opguestadd')) {
         $user = '******';
     }else {
         if(cookie::get('login_username') &&cookie::get('login_password')) {
             $user=new user();
             $user=$user->getrow(array('username'=>cookie::get('login_username')));
         }
     }
     if(cookie::get('login_username') &&cookie::get('login_password')) {
         $guestuser=new user();
         $guestuser=$guestuser->getrow(array('username'=>cookie::get('login_username')));
     }
     $this->view->guestuser = $guestuser;
     if(!$user &&front::$act != 'login'&&front::$act != 'register')  front::redirect(url::create('user/login'));
     $this->view->user=$user;
     $this->_user=new user;
     $this->table=front::get('manage');
     if($this->table <>'archive'&&$this->table <>'orders') exit('PAGE NOT FOUND!');
     $this->_table=new $this->table;
     $this->_table->getFields();
     $this->view->form=$this->_table->get_form();
     $this->_pagesize=config::get('manage_pagesize');
     $this->view->manage=$this->table;
     $this->view->primary_key=$this->_table->primary_key;
     if(!front::get('page')) front::$get['page']=1;
     $manage='table_'.$this->table;
     $this->manage=new $manage;
 }
 static function required($perm_name, $item)
 {
     // Original code from the required function in modules/gallery/helpers/access.php.
     if (!access::can($perm_name, $item)) {
         if ($perm_name == "view") {
             // Treat as if the item didn't exist, don't leak any information.
             throw new Kohana_404_Exception();
         } else {
             access::forbidden();
         }
         // Begin rWatcher modifications.
         //   Throw a 404 error when a user attempts to access a protected item,
         //   unless the password has been provided, or the user is the item's owner.
     } elseif (module::get_var("albumpassword", "hideonly") == false) {
         $item_protected = ORM::factory("albumpassword_idcache")->where("item_id", "=", $item->id)->order_by("cache_id")->find_all();
         if (count($item_protected) > 0) {
             $existing_password = ORM::factory("items_albumpassword")->where("id", "=", $item_protected[0]->password_id)->find();
             if ($existing_password->loaded()) {
                 if (cookie::get("g3_albumpassword") != $existing_password->password && identity::active_user()->id != $item->owner_id && !identity::active_user()->admin) {
                     throw new Kohana_404_Exception();
                 }
             }
         }
     }
 }
 /**
  * Fetch a cookie value, using the Input library.
  *
  * @param   string   cookie name
  * @param   mixed    default value
  * @param   boolean  use XSS cleaning on the value
  * @return  string
  */
 public static function get($name = NULL, $default = NULL, $xss_clean = FALSE)
 {
     // Return an array of all the cookies if we don't have a name
     if ($name === NULL) {
         $cookies = array();
         foreach ($_COOKIE as $key => $value) {
             $cookies[$key] = cookie::get($key, $default, $xss_clean);
         }
         return $cookies;
     }
     if (!isset($_COOKIE[$name])) {
         return $default;
     }
     // Get the cookie value
     $cookie = $_COOKIE[$name];
     // Find the position of the split between salt and contents
     $split = strlen(cookie::salt($name, NULL));
     if (isset($cookie[$split]) and $cookie[$split] === '~') {
         // Separate the salt and the value
         list($hash, $value) = explode('~', $cookie, 2);
         if (cookie::salt($name, $value) === $hash) {
             if ($xss_clean === TRUE and Kohana::config('core.global_xss_filtering') === FALSE) {
                 return Input::instance()->xss_clean($value);
             }
             // Cookie signature is valid
             return $value;
         }
         // The cookie signature is invalid, delete it
         cookie::delete($name);
     }
     return $default;
 }
 function index_action() {
     if (front::post('submit')) {
         if (!front::post('ballot')) {
             front::alert(lang('Please_select_vote'));
             return false;
         }
         if (config::get('checkip')) {
             $time=cookie::get('vttime');
             if (time() -$time <config::get('timer') * 60) {
                 front::alert(lang('You_have_voted'));
                 return false;
             }
         }
         $bid=front::$post['bid'];
         if (is_array(front::$post['ballot'])) {
             $ids=implode(',',front::$post['ballot']);
         }
         else {
             $ids=front::$post['ballot'];
         }
         if(preg_match('/(select|union|and|\'|"|\))/i',$ids)){
         	exit('非法参数');
         }
         if(preg_match('/(select|union|and|\'|"|\))/i',$bid)){
         	exit('非法参数');
         }
         $where="id in($ids)";
         $data='num=num+1';
         $option=new option();
         $option->rec_update($data,$where);
         $this->_table->rec_update($data,$bid);
         cookie::set('vttime',time(),time() +3600 * 24);
         front::alert(lang('Successful_vote'));
     }
 }
 public function _before_index()
 {
     $model = D("MisSystemRecursion");
     $MisSystemCompanyDao = M("mis_system_company");
     $where = array();
     $where['status'] = 1;
     $companylist = $MisSystemCompanyDao->where($where)->select();
     $this->assign("companylist", $companylist);
     //构造结构树
     $param['url'] = "__URL__/index/jump/jump/parentid/#id#/id/#id#";
     $param['rel'] = "MisSystemCompanyZtree";
     $param['open'] = "true";
     $param['isParent'] = "true";
     if ($companylist) {
         $companyztree = $this->getTree($companylist, $param);
     }
     //高亮默认选中节点
     $parentid = $_REQUEST['parentid'];
     if (empty($parentid)) {
         $parentid = cookie::get("missystemcompanyid");
         cookie::delete("missystemcompanyid");
         if (empty($parentid)) {
             $parentid = $companylist[0]['id'];
         }
     }
     $this->assign('valid', $parentid);
     //赋值用于boolbar
     $this->assign('parentid', $parentid);
     $this->assign("companyztree", $companyztree);
 }
Exemple #9
0
	/**
	 * Tests cookie::set()
	 *
	 * @test
	 * @dataProvider provider_get
	 * @covers cookie::get
	 * @param mixed   $key      key to use
	 * @param mixed   $value    value to set
	 * @param boolean $expected Output for cookie::get()
	 */
	public function test_get($key, $value, $expected)
	{
		// Force $_COOKIE
		if ($key !== NULL)
			$_COOKIE[$key] = $value;

		$this->assertSame($expected, cookie::get($key));
	}
Exemple #10
0
 public function read($id)
 {
     $data = (string) cookie::get($this->cookie_name);
     if ($data == '') {
         return $data;
     }
     return base64_decode($data);
 }
Exemple #11
0
 /**
  * Log a user out and remove any auto-login cookies.
  *
  * @param   boolean  completely destroy the session
  * @return  boolean
  */
 public function logout($destroy)
 {
     if (cookie::get('authautologin')) {
         // Delete the autologin cookie to prevent re-login
         cookie::delete('authautologin');
     }
     return parent::logout($destroy);
 }
Exemple #12
0
 public function read($id)
 {
     $data = (string) cookie::get($this->cookie_name);
     if ($data == '') {
         return $data;
     }
     return empty($this->encrypt) ? base64_decode($data) : $this->encrypt->decode($data);
 }
Exemple #13
0
 function __construct()
 {
     // Check and see if this is being run from the command line
     define('IS_CLI', 'cli' == PHP_SAPI);
     parent::__construct();
     Footsteps::step();
     $this->template->title = ucwords(router::$method);
     $this->session = Session::instance();
     $this->template->robots = '';
     if (router::$controller != 'page') {
         if (!Auth::instance()->logged_in() and !cookie::get('qaargh_visited', false, true)) {
             $this->session->set_flash('notice', 'It looks like this is your first time here. Click "home" to find out more about Q-Aargh!');
             cookie::set(array('name' => 'qaargh_visited', 'value' => true, 'expire' => 31536000));
         }
     } else {
         cookie::set(array('name' => 'qaargh_visited', 'value' => true, 'expire' => 31536000));
     }
     try {
         $this->template->view = new View(strtolower(router::$controller . '/' . router::$method));
     } catch (Exception $e) {
         $this->template->view = new View('error/missing_view');
     }
     if (Auth::instance()->logged_in()) {
         $this->template->menu = new View('menu/logged_in');
     } else {
         $this->template->menu = new View('menu/logged_out');
     }
     // Handle built-in authorization
     if (array_key_exists(router::$method, $this->auth_required)) {
         // If it's in the array, you must at least be logged in.
         if (!Auth::instance()->logged_in()) {
             $this->session->set_flash('error', Kohana::lang('general.login_required'));
             url::redirect("/user/login");
         }
         $authorized = false;
         // If it's *, then being logged in is enough
         if ('*' == $this->auth_required[router::$method]) {
             $authorized = true;
         } else {
             if (is_array($this->auth_required[router::$method])) {
                 foreach ($this->auth_required[router::$method] as $right) {
                     if (Auth::instance()->logged_in($right)) {
                         $authorized = false;
                         break;
                     }
                 }
             } else {
                 if (Auth::instance()->logged_in($this->auth_required[router::$method])) {
                     $authorized = false;
                 }
             }
         }
         if (!$authorized) {
             $this->session->set_flash('error', Kohana::lang('general.insufficient_privileges'));
             url::redirect("/user");
         }
     }
 }
 /**
  * 显示购物车内容
  *
  * @return array
  *
  * @example 返回数据类型为:array(array(商品ID, 商品名称, 商品数量, 商品单价, array(其实信息)), array(...));
  */
 public function readCart()
 {
     // 从购物车cookie中读取数据
     $data = cookie::get($this->cartName);
     if (!$data) {
         return false;
     }
     return $data;
 }
Exemple #15
0
 /**
  * 构造函数
  */
 public function __construct()
 {
     $cookie = cookie::get(COOKIE_KEY);
     if (!$cookie) {
         redirect('./');
         return;
     }
     view::assign('setting', madmin::get_setting());
     view::assign('now', time());
 }
Exemple #16
0
 public function getReferral()
 {
     $chkCookie = cookie::exists(COOKIE_SPONSOR_NAME);
     if ($chkCookie) {
         $referral = cookie::get(COOKIE_SPONSOR_NAME);
     } else {
         $referral = NULL;
     }
     return $referral;
 }
 /**
  * 設置或讀取訂單信息
  * @param $ary
  * @return array
  */
 static function oInfo($ary = null)
 {
     if ($ary) {
         cookie::set('order', json_encode($ary));
     } else {
         $oinfo = cookie::get('order');
         $ary = json_decode($oinfo, true);
         !$ary && ($ary = array());
         return $ary;
     }
 }
 function init() {
     if(cookie::get('login_username') &&cookie::get('login_password')) {
         $user=new user();
         $user=$user->getrow(array('username'=>cookie::get('login_username')));
         if(is_array($user) &&cookie::get('login_password')==front::cookie_encode($user['password'])) {
             $this->view->user=$user;
             $this->view->usergroupid=$user['groupid'];
         }
     }
     else $this->view->usergroupid=0;
 }
Exemple #19
0
 public function before()
 {
     parent::before();
     if (($this->_current_user = cookie::get('authorized')) === NULL) {
         if ($this->request->controller !== 'login') {
             // Skip the current action
             $this->request->action = 'skip';
             // Load the login page via a sub-query
             $this->template->content = Request::factory($this->request->uri(array('controller' => 'login')))->execute();
         }
     }
 }
Exemple #20
0
 static function viewable($model)
 {
     // Hide password protected albums until the correct password is entered,
     // unless the current user is an admin, or the albums owner.
     $model = item_Core::viewable($model);
     // If the user is an admin, don't hide anything anything.
     //   If not, hide whatever is restricted by an album password
     //   that the current user is not the owner of.
     if (!identity::active_user()->admin) {
         $model->and_open()->join("items_albumpasswords", "items.id", "items_albumpasswords.album_id", "LEFT OUTER")->and_where("items_albumpasswords.album_id", "IS", NULL)->or_where("items_albumpasswords.password", "=", cookie::get("g3_albumpassword"))->or_where("items.owner_id", "=", identity::active_user()->id)->close();
     }
     return $model;
 }
Exemple #21
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  string|null  $guard
  * @return mixed
  */
 public function handle($request, Closure $next, $guard = null)
 {
     $path = $request->getPathInfo();
     $uid = cookie::get('uid');
     $redirectPath = cookie::get('redirectPath') ? cookie::get('redirectPath') : '/';
     if (in_array($path, array('/login', '/register', '/loginDo', '/registerDo')) && !empty($uid)) {
         return redirect($redirectPath);
     }
     $pathArray = array('/send', '/sendDo', '/success');
     if (in_array($path, $pathArray) && empty($uid)) {
         return redirect("login");
     }
     return $next($request);
 }
 static function site_menu($menu, $theme)
 {
     // Add menu options for Adding / Removing / Using passwords to the menu.
     // If this page doesn't belong to an item, don't display the menu.
     if (!$theme->item()) {
         return;
     }
     $item = $theme->item();
     // If there isn't currently a password stored in the cookie,
     //   then display the enter password link.
     if (cookie::get("g3_albumpassword") == "") {
         $menu->append(Menu::factory("dialog")->id("albumpassword_login")->css_id("g-album-password-login")->url(url::site("albumpassword/login"))->label(t("Unlock albums")));
     } else {
         // If a password has been entered already
         // display the log out link, and links to the protected albums
         $menu->append(Menu::factory("submenu")->id("albumpassword_protected")->css_id("g-album-password-protected")->label(t("Protected albums")));
         $menu->get("albumpassword_protected")->append(Menu::factory("link")->id("albumpassword_logout")->css_id("g-album-password-logout")->url(url::site("albumpassword/logout"))->label(t("Clear password")));
         $existing_password = "";
         if (cookie::get("g3_albumpassword_id") != "") {
             $existing_password = ORM::factory("items_albumpassword")->where("password", "=", cookie::get("g3_albumpassword"))->where("id", "=", cookie::get("g3_albumpassword_id"))->find_all();
         } else {
             $existing_password = ORM::factory("items_albumpassword")->where("password", "=", cookie::get("g3_albumpassword"))->find_all();
         }
         if (count($existing_password) > 0) {
             $counter = 0;
             while ($counter < count($existing_password)) {
                 $item_album = ORM::factory("item")->where("id", "=", $existing_password[$counter]->album_id)->find();
                 $menu->get("albumpassword_protected")->append(Menu::factory("link")->id("albumpassword_album" . $counter)->label(html::purify($item_album->title))->css_id("g-album-password-album" . $counter)->url(url::abs_site("{$item_album->type}s/{$item_album->id}")));
                 $counter++;
             }
         }
     }
     // If this is an album without a password, display a link for assigning one.
     // If this is an album with a password, display a link to remove it.
     if ($item->is_album()) {
         if (access::can("view", $item) && access::can("edit", $item)) {
             $existing_password = ORM::factory("items_albumpassword")->where("album_id", "=", $item->id)->find_all();
             if (count($existing_password) > 0) {
                 $menu->get("options_menu")->append(Menu::factory("link")->id("albumpassword_remove")->label(t("Remove password"))->css_id("g-album-password-remove")->url(url::site("albumpassword/remove/" . $item->id)));
             } elseif ($item->id != 1) {
                 $passworded_subitems = ORM::factory("item", $item->id)->and_open()->join("albumpassword_idcaches", "items.id", "albumpassword_idcaches.item_id", "LEFT OUTER")->where("albumpassword_idcaches.item_id", "IS NOT", NULL)->close()->descendants();
                 $existing_cacheditem = ORM::factory("albumpassword_idcache")->where("item_id", "=", $item->id)->order_by("cache_id")->find_all();
                 if (count($existing_cacheditem) == 0 && count($passworded_subitems) == 0) {
                     $menu->get("options_menu")->append(Menu::factory("dialog")->id("albumpassword_assign")->label(t("Assign password"))->css_id("g-album-password-assign")->url(url::site("albumpassword/assign/" . $item->id)));
                 }
             }
         }
     }
 }
Exemple #23
0
 /**
  * 登录
  */
 public function login()
 {
     $cookie = cookie::get(COOKIE_KEY);
     if ($cookie) {
         redirect(url('admin', 'index'));
         return;
     }
     $username = $this->post('username');
     $password = $this->post('password');
     if ($username === 'ruanzhijun' && $password === 'ruanzhijun') {
         cookie::set(COOKIE_KEY, 1);
         redirect(url('admin', 'index'));
         return;
     }
 }
Exemple #24
0
 function check_admin() {
     if (cookie::get('login_username')&&cookie::get('login_password')) {
         $user=new user();
         $user=$user->getrow(array('username'=>cookie::get('login_username')));
         $roles = session::get('roles');
         if ($roles && is_array($user)&&cookie::get('login_password')==front::cookie_encode($user['password'])) {
             $this->view->user=$user;
             front::$user=$user;
         }else{
         	$user=null;
         }
     }
     if (!isset($user)||!is_array($user)) {
         front::redirect(url::create('admin/login'));
     }
 }
Exemple #25
0
 /**
  * Loads the session data from the database.
  *
  * @return  string
  */
 public function _read()
 {
     if ($id = cookie::get($this->_name)) {
         $result = DB::query(Database::SELECT, 'SELECT data FROM ' . $this->_table . ' WHERE session_id = :id LIMIT 1')->set(':id', $id)->execute($this->_db);
         if ($result->count()) {
             // Set the current session id
             $this->_session_id = $this->_update_id = $id;
             echo Kohana::debug('loaded data');
             // Return the data string
             return $result->get('data');
         }
     }
     // Create a new session id
     $this->_regenerate();
     return NULL;
 }
Exemple #26
0
 function index()
 {
     Cookie::get('feifa_home') == 'passageway_home' ? $condition['qx'] = Cookie::get('feifa_home') == 'passageway_home' : 0;
     Cookie::get('user_name') ? $condition['userName'] = Cookie::get('user_name') : 0;
     cookie::get('user_id') ? $condition['userId'] = Cookie::get('user_id') : 0;
     $condition['goods_id'] = intval($_POST['goods_id']);
     $condition['buy_num'] = intval($_POST['buy_num']);
     $result = $this->cartModel->getCartIndexData($condition);
     if ($result['loginStatus'] == 1) {
         if ($result['addStatus'] == 1) {
             $this->redirect('cart');
         } else {
             $this->error(C('ERROR_OPERATION_FAILURE'));
         }
     } else {
         $this->error(C('ERROR_NOT_LOGIN_NOT_BUY'));
     }
 }
Exemple #27
0
 public function getReferer()
 {
     $chkCookie = cookie::exists(COOKIE_SPONSOR_NAME);
     if ($chkCookie) {
         $refID = cookie::get(COOKIE_SPONSOR_NAME);
         $validRef = $this->db->count("user_accounts", "agent_id = '{$refID}'");
         if ($validRef != 0) {
             $return = $refID;
         } else {
             cookie::delete(COOKIE_SPONSOR_NAME);
             $return = FALSE;
         }
         return cookie::get(COOKIE_SPONSOR_NAME);
     } else {
         $return = FALSE;
     }
     return $return;
 }
Exemple #28
0
 public function index()
 {
     $login_config = Kohana::config('login');
     if ($login_config['login_by_email'] == 'YES') {
         $this->login_by_email();
         return;
     }
     if ($this->auth->logged_in()) {
         $this->template->title = 'Already Logged In';
         $this->template->content = new View('login/login_message');
         $this->template->content->message = 'You are already logged in.<br />';
         $this->template->content->link_to_home = 'YES';
         $this->template->content->link_to_logout = 'YES';
         return;
     }
     $this->build_template('login_by_username');
     if (request::method() == 'post') {
         if ($this->auth->login(array('username' => $_POST['UserName']), $_POST['Password'], isset($_POST['remember_me']))) {
             // I don't trust the results!! There is something funny going on where the
             // number of rows in a query is not being reported correctly - an invalid username returns
             // a valid login with the first real user.
             // THIS IS A DOUBLE CHECK. IF THE USERNAME DOESN'T MATCH, FORCE A LOG OFF.
             if ($_POST['UserName'] == $_SESSION['auth_user']->username) {
                 $user = new User_Model($_SESSION['auth_user']->id);
                 $user->__set('forgotten_password_key', NULL);
                 $user->save();
                 $url = arr::remove('requested_page', $_SESSION);
                 // Ensure that the session is being saved to the Cookie properly
                 $this->session->write_close();
                 if (!cookie::get('kohanasession')) {
                     $this->session->set_flash('flash_error', "Indicia could not log you in because cookies are not enabled on your browser. Please enable cookies then try again.");
                 } else {
                     url::redirect($url);
                     return;
                 }
             } else {
                 $this->auth->logout(TRUE);
             }
         } else {
             $this->session->set_flash('flash_error', "<strong>Login failed.</strong><br/> Either your username or password was incorrect or your login does not have enough privileges to access this Indicia warehouse.");
         }
     }
 }
Exemple #29
0
 public static function save_update_current()
 {
     if (true || !user::logged('admin')) {
         $session = Session::instance();
         $visitor = ORM::factory('Visitor', $session->get('active_visitor'));
         $base = request::detect_uri();
         $queries = isset($_GET) && !empty($_GET) ? '?' . http_build_query($_GET) : '';
         $uri = request::detect_uri() . $queries;
         //substr($base, 1, strlen($base))
         if ($visitor->loaded() && $uri == $visitor->page) {
             // This is just a reload of the current page.
             return;
         }
         if (!$visitor->loaded()) {
             $numvisits = cookie::get('numvisits');
             if (!$numvisits) {
                 $numvisits = 0;
             }
             cookie::set('numvisits', $numvisits + 1);
             $visitor->numvisits = $numvisits + 1;
             $visitor->start = time();
             $visitor->referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
             $visitor->ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
             $visitor->geolocation = 'todo';
         }
         if (empty($visitor->client)) {
             $visitor->client = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
         }
         $visitor->page = $uri;
         if (user::logged()) {
             $visitor->user_id = user::get()->id;
         }
         $history = json_decode($visitor->history);
         if (!is_array($history)) {
             $history = array();
         }
         $history[] = $uri;
         $visitor->history = json_encode($history);
         $visitor->time = time();
         $visitor->save();
         $session->set('active_visitor', $visitor->id);
     }
 }
 static function viewable($model)
 {
     // Hide password protected albums until the correct password is entered,
     // unless the current user is an admin, or the albums owner.
     $model = item_Core::viewable($model);
     // If the user is an admin, don't hide anything anything.
     //   If not, hide whatever is restricted by an album password
     //   that the current user is not the owner of.
     if (!identity::active_user()->admin) {
         // Display items that are not in idcaches.
         $model->and_open()->join("albumpassword_idcaches", "items.id", "albumpassword_idcaches.item_id", "LEFT OUTER")->and_where("albumpassword_idcaches.item_id", "IS", NULL);
         // If in hide only mode, check and see if the current item is protected.
         //   If it is, log the user in with the password to view it.
         if (module::get_var("albumpassword", "hideonly") == true) {
             $existing_cacheditem = ORM::factory("albumpassword_idcache")->where("item_id", "=", $model->id)->order_by("cache_id")->find_all();
             if (count($existing_cacheditem) > 0) {
                 $existing_cacheditem_password = ORM::factory("items_albumpassword")->where("id", "=", $existing_cacheditem[0]->password_id)->find_all();
                 if (cookie::get("g3_albumpassword") != $existing_cacheditem_password[0]->password) {
                     cookie::set("g3_albumpassword", $existing_cacheditem_password[0]->password);
                     cookie::set("g3_albumpassword_id", $existing_cacheditem_password[0]->id);
                     $model->or_where("albumpassword_idcaches.password_id", "=", $existing_cacheditem_password[0]->id);
                 }
             }
         }
         // ... Unless their password id corresponds with a valid password.
         $existing_password = ORM::factory("items_albumpassword")->where("password", "=", cookie::get("g3_albumpassword"))->find_all();
         if (count($existing_password) > 0) {
             foreach ($existing_password as $one_password) {
                 if (cookie::get("g3_albumpassword_id") != "") {
                     if (cookie::get("g3_albumpassword_id") == $one_password->id) {
                         $model->or_where("albumpassword_idcaches.password_id", "=", $one_password->id);
                     }
                 } else {
                     $model->or_where("albumpassword_idcaches.password_id", "=", $one_password->id);
                 }
             }
         }
         // Or the current user is the owner of the item.
         $model->or_where("items.owner_id", "=", identity::active_user()->id)->close();
     }
     return $model;
 }