Example #1
0
 /**
  * Handler::sign_in keep login tests
  */
 public function test_sign_in_keeper()
 {
     Auth\Handler::kill_instance('main');
     $example_user = clone static::$current_user;
     $auth = Auth\Handler::create();
     $auth->sign_in($example_user, false);
     $this->assertTrue($auth->user instanceof DB\Model);
     $this->assertEquals(static::$current_user->id, $auth->user->id);
     // test valid
     Auth\Handler::kill_instance('main');
     $auth = Auth\Handler::create();
     $this->assertTrue($auth->valid());
     // lets create an keeper login now
     $this->create_keeper_login();
     // lets test the login store event
     $this->assertEquals(null, $auth->login()->client_ip);
     $auth->session->destroy();
     CCEvent::mind('auth.store_login', function ($data) {
         $data['client_ip'] = '127.0.0.1';
         return $data;
     });
     Auth\Handler::kill_instance('main');
     $auth = Auth\Handler::create();
     $this->assertTrue($auth->valid());
     $this->assertEquals('127.0.0.1', $auth->login()->client_ip);
     // now lets modify some data to force restore failure
     // changing the the current client ip will force failure
     CCIn::instance(new CCIn_Instance(array(), array(), array(), array(), array('REMOTE_ADDR' => '192.168.1.42')));
     $this->keeper_login_false();
     // next lets modify the users password wich will force a failure
     $this->create_keeper_login();
     $this->keeper_login_true();
     static::$current_user->password = "******";
     static::$current_user->save();
     $this->keeper_login_false();
     // modifiy the restore_id
     $this->create_keeper_login();
     $this->keeper_login_true();
     CCCookie::set('ccauth-restore-id', '34');
     $this->keeper_login_false();
     // modifiy the restore_token
     $this->create_keeper_login();
     $this->keeper_login_true();
     CCCookie::set('ccauth-restore-token', 'wrong');
     $this->keeper_login_false();
     // delete the user
     $this->create_keeper_login();
     $this->keeper_login_true();
     static::$current_user->delete();
     $this->keeper_login_false();
     // create him again
     static::$current_user->save();
 }
Example #2
0
 /**
  * Check if a session with the given key already exists
  *
  * @param string		$id		The session id key.
  * @param array 		$data
  * @return bool
  */
 public function write($id, $data)
 {
     \CCCookie::set($id . $this->cookie_suffix, \CCCrypter::encode(json_encode($data), $this->crypt_salt));
 }
Example #3
0
 /**
  * Write the session to the driver
  *
  * @return void
  */
 public function write()
 {
     $this->_driver->write($this->id, $this->_data);
     // We also have to set the cookie again to keep it alive
     \CCCookie::set($this->cookie_name(), $this->id, \CCArr::get('lifetime', $this->_config, \CCDate::minutes(5)));
 }