public function execute() { if (Session::get_state() != Session::ST_LIFE) { self::set_client_command('refresh', array('url' => 'self')); self::set_result(FALSE); return; } if (strlen($this->message) > 65000) { throw new Command_exception('text length error', get_string('errors', 'text_length_error')); } $captcha_lib = Loader::get_library('captcha'); if (!$captcha_lib->check($this->captcha)) { throw new Command_exception('captcha error', get_string('errors', 'captcha_error')); } require_once BASEPATH . 'global/cache.php'; $query = array(); $query['%text'] = Security::sanitize_text($this->message); $query['%name'] = Security::sanitize_text($this->name); $query['%email'] = Security::sanitize_text($this->email); $query['%quote_id'] = intval($this->quote_id); $query['%page'] = Cache::generate_key(TRUE); $query['%avatar'] = abs(crc32($this->email)) % self::AVATAR_COUNT; foreach ($query as $key => $value) { if (!in_array($key, array('%quote_id', '%avatar')) and empty($value)) { throw new Command_exception('empty text error', get_string('errors', 'empty_field')); } } db::simple_query(self::Q_SET_COMMENT, $query, TRUE); Cache::reset($query['%page']); self::set_client_command('refresh', array('url' => 'self')); }
public function execute() { if (!in_array($this->reset_zone, array('all', 'pages', 'scripts', 'styles'))) { $this->reset_zone = 'all'; } Cache::reset('', $this->reset_zone); }
function testProfileReadingFunctions() { // find a user with 'newcss' set list($uid, $css) = Dal::query_one("SELECT user_id, field_value FROM user_profile_data WHERE field_type='ui' AND field_name='newcss' ORDER BY user_id LIMIT 1"); if (empty($uid)) { echo "Test not possible as nobody has the newcss field set. Try again on a more populated database.\n"; return; } // find another field, so we can test with more than one list($f2_name, $f2_value) = Dal::query_one("SELECT field_name, field_value FROM user_profile_data WHERE field_type='ui' AND user_id=? AND field_name <>'newcss' AND field_value IS NOT NULL LIMIT 1", $uid); echo "getting ui/newcss and {$f2_name} properties from user_profile_data for user_id {$uid}.\n"; $user = new User(); $user->load((int) $uid); // load just the newcss field echo "getting just the newcss property for user {$uid}\n"; $css2 = $user->get_profile_field('ui', 'newcss'); $this->assertEquals($css, $css2); // load just the second field echo "getting just the {$f2_name} property for user {$uid}\n"; $v = $user->get_profile_field('ui', $f2_name); $this->assertEquals($v, $f2_value); // load newcss and the second field, with get_profile_fields() echo "getting the newcss and {$f2_name} properties, with get_profile_fields()\n"; $data = $user->get_profile_fields('ui', array('newcss', 'graagh', $f2_name)); $this->assertEquals($css, $data['newcss']); $this->assertEquals(NULL, $data['graagh']); $this->assertEquals($f2_value, $data[$f2_name]); // try again, flushing the cache first Cache::reset(); echo "(without cache) getting the newcss and {$f2_name} properties, with get_profile_fields()\n"; $data = $user->get_profile_fields('ui', array('newcss', 'graagh', $f2_name)); $this->assertEquals($css, $data['newcss']); $this->assertEquals(NULL, $data['graagh']); $this->assertEquals($f2_value, $data[$f2_name]); // regression test (phil) 2007-04-01, for bug spotted by martin // 2007-03-23: make sure we don't crash if we request fields that // are all cached. echo "regression: make sure it doesn't crash if everything is in the cache\n"; $data = $user->get_profile_fields('ui', array('newcss')); $this->assertEquals($css, $data['newcss']); // try by loading the entire 'ui' section echo "getting entire ui section for user {$uid}\n"; $ui = User::load_profile_section($uid, "ui"); $this->assertEquals($css, $ui['newcss']['value']); $this->assertEquals($f2_value, $ui[$f2_name]['value']); }
public function testAddDeleteShadowUser() { // Dal::register_query_callback("explain_query"); global $network_info; echo "getting a user\n"; $user = Test::get_test_user(); $testusername = $user->first_name . " " . $user->last_name; echo "test user = {$testusername}\n"; $namespace = 'php_unit'; // testuser data $testdata = array('user_id' => "pa_" . $user->user_id, 'login_name' => 'testuser', 'email' => $namespace . $user->email, 'first_name' => $user->first_name, 'last_name' => $user->last_name); echo "TEST DATA:\n"; print_r($testdata); $shadow_user = new ShadowUser($namespace); echo "Test load this shadow user, this should fail\n"; $sh = $shadow_user->load($testdata['user_id']); $this->assertNull($sh); echo "Create a shadow user\n"; $shadow_user = ShadowUser::create($namespace, $testdata, $network_info); echo "SHADOW USER DATA:\n"; print_r($shadow_user); $this->assertNotNull($shadow_user); echo "Test updating the data\n"; $testdata2 = $testdata; $testdata2['email'] = $namespace . "add" . $user->email; $testdata2['login_name'] = "newlogin"; $testdata2['first_name'] = "newName"; print_r($testdata2); $su2 = new ShadowUser($namespace); // load this with new data $su2->load($testdata2); unset($su2); Cache::reset(); // now load it only via the original remote uid $su3 = new ShadowUser($namespace); $su3->load($testdata['user_id']); echo "UPDATED SHADOW USER DATA:\n"; print_r($su3); echo "Delete it\n"; ShadowUser::delete($shadow_user->user_id); // there should not be a shadow user of this id anymore $this->assertNull($shadow_user->load($testdata['user_id'])); }
static function create($namespace, $userinfo, $network_info) { Logger::log("ShadowUser::create " . serialize($userinfo), LOGGER_ACTION); // setup the needed info if (empty($userinfo['login_name'])) { $userinfo['display_login_name'] = $userinfo['first_name'] . '.' . $userinfo['last_name']; } else { $userinfo['display_login_name'] = $userinfo['login_name']; } // this is the real internal PA login_name // which should NOT be displayed // instead use the display_login_name $userinfo['login_name'] = $namespace . "." . $userinfo['user_id']; $userinfo['confirm_password'] = $userinfo['password'] = substr(md5($userinfo['email'] . rand()), 0, 12); // Test to see if the email was used before $res = Dal::query("SELECT user_id FROM users WHERE email=?", array($userinfo['email'])); if ($res->numrows() > 0) { // oops email has been used // use the prefix.email@address,tld format // to ensure we have an unique string for email $userinfo['email'] = $userinfo['user_id'] . "+" . $userinfo['email']; } $reg_user = new User_Registration(); if ($reg_user->register($userinfo, $network_info)) { // Success! $reg_user->newuser->set_last_login(); // also save the external user_id $reg_user->newuser->set_profile_field($namespace, 'user_id', $userinfo['user_id'], 0); $reg_user->newuser->set_profile_field($namespace, 'display_login_name', $userinfo['display_login_name'], 0); $reg_user->newuser->is_active = ACTIVE; $reg_user->newuser->save(); // load it as a shadow user Cache::reset(); $su = new ShadowUser($namespace); $su->load($userinfo['user_id']); // and make sure all info is actually stored $su->sync($userinfo); Logger::log("ShadowUser::create done " . serialize($userinfo), LOGGER_ACTION); return $su; } else { throw new PAException(BAD_PARAMETER, $reg_user->msg); return NULL; } }
static function create($namespace, $userinfo, $network_info) { // setup the needed info if (empty($userinfo['login_name'])) { $userinfo['display_login_name'] = $userinfo['first_name'] . '.' . $userinfo['last_name']; } else { $userinfo['display_login_name'] = $userinfo['login_name']; } // this is the real internal PA login_name // which should NOT be displayed // instead use the display_login_name $userinfo['login_name'] = $namespace . "." . $userinfo['user_id']; $userinfo['confirm_password'] = $userinfo['password'] = substr(md5($userinfo['email'] . rand()), 0, 12); $reg_user = new User_Registration(); if ($reg_user->register($userinfo, $network_info)) { // Success! $reg_user->newuser->set_last_login(); // also save the external user_id $reg_user->newuser->set_profile_field($namespace, 'user_id', $userinfo['user_id'], 0); $reg_user->newuser->set_profile_field($namespace, 'display_login_name', $userinfo['display_login_name'], 0); // load it as a shadow user Cache::reset(); $su = new ShadowUser($namespace); $su->load($userinfo['user_id']); return $su; } else { throw new PAException(BAD_PARAMETER, $reg_user->msg); return NULL; } }