Exemple #1
0
 /**
  * test CCSession::delete 
  */
 public function test_delete()
 {
     CCSession::set('a', 'b');
     CCSession::set('a', 'c', 'file');
     $this->assertTrue(CCSession::has('a'));
     $this->assertTrue(CCSession::has('a', 'file'));
     CCSession::delete('a');
     CCSession::delete('a', 'file');
     $this->assertFalse(CCSession::has('a'));
     $this->assertFalse(CCSession::has('a', 'file'));
 }
Exemple #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);
 }
Exemple #3
0
 /**
  * Application initialization.
  * do your inital stuff here like getting the current user object ect..
  * You can return a CCResponse wich will cancle all other actions 
  * if enebaled ( see. main.config -> send_app_wake_response )
  *
  * @return void | CCResponse
  */
 public static function wake()
 {
     /*
      * Start the session by adding the current uri
      */
     CCSession::set('uri', CCServer::uri());
     /*
      * try to authenticate the user
      */
     //static::$user =& CCAuth::handler()->user;
     /*
      * load the App configuration
      */
     static::$config = CCConfig::create('app');
 }
Exemple #4
0
 /**
  * Handler::create tests
  */
 public function test_create()
 {
     $auth = Auth\Handler::create();
     $this->assertTrue($auth->user instanceof CCModel);
     $this->assertFalse($auth->valid());
     $auth2 = Auth\Handler::create('other');
     $this->assertEquals($auth, Auth\Handler::create());
     $this->assertEquals($auth2, Auth\Handler::create('other'));
     $this->assertNotEquals($auth, $auth2);
     // create with existing one
     CCSession::set('user_id', static::$current_user->id);
     // kill the old instance
     Auth\Handler::kill_instance('main');
     // redo
     $auth = Auth\Handler::create();
     $this->assertTrue($auth->user instanceof CCModel);
     $this->assertTrue($auth->valid());
     // diffrent keys
     CCSession::set('user_email', static::$current_user->email);
     $auth = Auth\Handler::create('diffrent_selector_keys');
     $this->assertTrue($auth->user instanceof CCModel);
     $this->assertTrue($auth->valid());
     // another auth same session manager
     $auth = Auth\Handler::create('same_session_manager');
     $this->assertTrue($auth->user instanceof CCModel);
     $this->assertTrue($auth->valid());
     // another auth diffrent session manager
     $auth = Auth\Handler::create('diffrent_session_manager');
     $this->assertTrue($auth->user instanceof CCModel);
     $this->assertFalse($auth->valid());
     // using an config alias
     $auth = Auth\Handler::create('alias');
     $this->assertTrue($auth->user instanceof CCModel);
     $this->assertTrue($auth->valid());
     // overwrite config
     $auth = Auth\Handler::create('main', array('session_manager' => 'array'));
     $this->assertTrue($auth->user instanceof CCModel);
     $this->assertFalse($auth->valid());
     // test user_id but user dont exists
     Auth\Handler::kill_instance('main');
     $auth = Auth\Handler::create('main');
     $auth->session->set('user_id', 21);
     Auth\Handler::kill_instance('main');
     $auth = Auth\Handler::create('main');
     $this->assertTrue($auth->user instanceof CCModel);
     $this->assertFalse($auth->valid());
 }
 /**
  * Sign out action
  */
 public function action_sign_out()
 {
     if (!CCSession::valid_fingerprint()) {
         return CCRedirect::to('/');
     }
     CCAuth::sign_out();
     return CCRedirect::to('/');
 }
 /**
  * Get the session instance on controller wake
  */
 public function wake()
 {
     $this->manager = \CCSession::manager(CCIn::get('manager'));
 }
Exemple #7
0
 /**
  * Prepares a file with the parameters
  *
  * @param string 		$file
  * @return $file
  */
 public static function file($file)
 {
     $params = array_merge(static::$params, array('time' => time(), 'fingerprint' => \CCSession::fingerprint(), 'random' => CCStr::random()));
     foreach ($params as $param => $value) {
         $file = str_replace(':' . $param, $value, $file);
     }
     return $file;
 }
Exemple #8
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;
 }
Exemple #9
0
 /**
  * Flash an alert
  * This will add the alert to session so it gets displayed on the next request.
  *
  * @param string 			$type
  * @param string|array 		$message
  * @return void
  */
 public static function flash($type, $message)
 {
     \CCSession::add('ui.alerts.' . $type, static::prepare($type, $message));
 }
Exemple #10
0
 function fingerprint($name = null)
 {
     return CCSession::manager($name)->fingerprint;
 }
Exemple #11
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'));
 }