Exemplo n.º 1
0
 /**
  * test CCSession::set 
  */
 public function test_set()
 {
     CCSession::set('a', 'b');
     CCSession::set('a', 'c', 'file');
     $this->assertEquals('b', CCSession::manager()->get('a'));
     $this->assertEquals('c', CCSession::manager('file')->get('a'));
 }
Exemplo n.º 2
0
 /**
  * Get a manager instance
  *
  * @param array 				$params
  * @return Session\Manager
  */
 public function get_manager($params)
 {
     if (array_key_exists('m', $params)) {
         $manager = $params['m'];
     } else {
         $manager = reset($params);
     }
     if ($manager) {
         $this->info('Using session manager: ' . $manager);
     } else {
         $manager = null;
         $this->info('Using default session manager.');
     }
     return \CCSession::manager($manager);
 }
Exemplo n.º 3
0
 /**
  * Get the session instance on controller wake
  */
 public function wake()
 {
     $this->manager = \CCSession::manager(CCIn::get('manager'));
 }
Exemplo n.º 4
0
 /**
  * Auth instance constructor
  *
  * @param string 		$name
  * @param array 			$config
  * @return void
  */
 public function __construct($name, $config = null)
 {
     if (is_null($config)) {
         $config = \CCConfig::create('auth')->get($name);
         // check for an alias. If you set a string
         // in your config file we use the config
         // with the passed key.
         if (is_string($config)) {
             $config = \CCConfig::create('auth')->get($config);
         }
     }
     if (!is_array($config)) {
         throw new Exception("Auth\\Handler::create - Invalid auth handler (" . $name . ").");
     }
     // also don't forget to set the name manager name becaue we need him later.
     $this->name = $name;
     // assign defaults and create the configuration object
     $this->config = \CCDataObject::assign(\CCArr::merge(array('session_manager' => null, 'session_key' => 'user_id', 'user_key' => 'id', 'user_model' => "\\Auth\\User", 'identifiers' => array('email'), 'logins' => array('handler' => null, 'table' => 'auth_logins'), 'restore' => array('id_cookie' => 'ccauth-restore-id', 'token_cookie' => 'ccauth-restore-token', 'lifetime' => \CCDate::months(1))), $config));
     // set the session handler
     $this->session = \CCSession::manager($this->config->session_manager);
     $user_model = $this->config->user_model;
     // set a empty default user object to avoid
     // on a non object errors
     $this->user = new $user_model();
     // do we already have a user id means are we
     // logged in?
     if (!is_null($session_key = $this->session_user_id())) {
         if ($user = $user_model::find($this->config->user_key, $session_key)) {
             $this->user = $user;
             return $this->authenticated = true;
         }
     } else {
         $restore_id_cookie = $this->config->get('restore.id_cookie');
         $restore_token_cookie = $this->config->get('restore.token_cookie');
         if (CCCookie::has($restore_id_cookie) && CCCookie::has($restore_token_cookie)) {
             // get the restore cookies
             $restore_id = CCCookie::get($restore_id_cookie);
             $restore_token = CCCookie::get($restore_token_cookie);
             // get the restore login
             $login = $this->select_logins()->where('restore_id', $restore_id)->where('restore_token', $restore_token)->limit(1);
             // if no login found kill the cookies and return
             if (!($login = $login->run())) {
                 $this->kill_restore();
                 return $this->authenticated = false;
             }
             // Invalid user? kill the cookies and return
             if (!($user = $user_model::find($this->config->user_key, $restore_id))) {
                 $this->kill_restore();
                 return $this->authenticated = false;
             }
             // validate the restore key if invalid
             // once again kill the cookies and return
             if ($login->restore_token != $this->restore_key($user)) {
                 $this->kill_restore();
                 return $this->authenticated = false;
             }
             // If everything is fine sign the user in and
             // update the restore keys
             $this->sign_in($user, true);
             return $this->authenticated = true;
         }
     }
     return $this->authenticated = false;
 }
Exemplo n.º 5
0
 function fingerprint($name = null)
 {
     return CCSession::manager($name)->fingerprint;
 }
Exemplo n.º 6
0
 /**
  * test Session\Manager::gc 
  */
 public function test_gc()
 {
     $manager = Session\Manager::create();
     $manager->foo = "bar";
     $manager->write();
     $manager->read();
     $this->assertEquals("bar", $manager->foo);
     $manager->gc();
     $manager->read();
     $this->assertFalse(CCSession::manager()->has('bar'));
 }