Example #1
0
 function index_get()
 {
     $requested_data = $this->get("filter");
     $filters = $requested_data['filters'];
     $limit = $this->get('limit') ? $this->get('limit') : 50;
     $offset = $this->get('offset') ? $this->get('offset') : null;
     $users = new User(null, $this->entity);
     $users->limit($limit, $offset);
     if (isset($filters)) {
         foreach ($filters as $f) {
             $users->where($f['field'], $f['value']);
         }
     }
     $users->get_iterated();
     foreach ($users as $user) {
         $data[] = array('id' => intval($user->id), 'username' => $user->username, 'password' => $user->password, 'status' => boolval($user->status), 'created_at' => $user->created_at, 'updated_at' => $user->updated_at);
     }
     $users->flush_cache();
     if (isset($filters)) {
         foreach ($filters as $f) {
             $users->where($f['field'], $f['value']);
         }
     }
     $users->get_iterated();
     if ($users->result_count() > 0) {
         $this->response(array('results' => $data, 'count' => $users->result_count()), 200);
     } else {
         $this->response(array('results' => $data, 'count' => $users->result_count()), 200);
     }
 }
 /**
  * @dataProvider commandInterpreterCases
  */
 public function testCommandInterpreter($input, $expectedType, $comment = '')
 {
     $inter = new CommandInterpreter();
     $user = new User();
     // fake user
     $user->limit(1);
     $user->find();
     $cmd = $inter->handle_command($user, $input);
     $type = $cmd ? get_class($cmd) : null;
     $this->assertEquals(strtolower($expectedType), strtolower($type), $comment);
 }
Example #3
0
 /**
  * Render
  */
 public function render()
 {
     $users = new User();
     $users->order('Рейтинг', 'desc');
     $users->limit($this->options->limit);
     if ($result = $users->findAll()) {
         $tpl = new Template('User/templates/widgets/top');
         $tpl->users = $result;
         $this->code = $tpl->render();
     }
     return parent::render();
 }
Example #4
0
function testAllUsers($filter)
{
    $found = false;
    $offset = 0;
    $limit = 1000;
    do {
        $user = new User();
        $user->orderBy('created');
        $user->limit($offset, $limit);
        $found = $user->find();
        if ($found) {
            while ($user->fetch()) {
                try {
                    testUser($filter, $user);
                } catch (Exception $e) {
                    printfnq("ERROR testing user %s\n: %s", $user->nickname, $e->getMessage());
                }
            }
            $offset += $found;
        }
    } while ($found > 0);
}
 /**
  * 注册公共函数
  * 由一些条件的判断完成最终注册
  * @param $platform_userid 用户id唯一
  * @param $platform_type 类型:sina、qq
  * @param null $nickname 昵称
  * @param null $description 描述
  * @param null $location 当前所在地
  * @param int $gender 性别
  */
 function regist_common($platform_userid, $platform_type, $nickname = null, $profile_image_url = null, $description = null, $gender = 0, $location = null)
 {
     $head = null;
     //拼接userid头
     switch ($platform_type) {
         case 2:
             $head = "qq";
             break;
         case 1:
             $head = 'sina';
             break;
     }
     $user = new User();
     $sql = "platform_type='{$platform_type}' AND platform_userid='{$platform_userid}'";
     $user->whereAdd($sql);
     $user->limit(1);
     $user->find();
     if ($user->fetch()) {
         $this->showUserResult($user, 1);
         return;
     }
     $originalUsername = $head . $platform_userid;
     $username = $this->nicknameFromName($originalUsername);
     $email = $this->trimmed("email");
     $homepage = $this->trimmed("homepage");
     $password = $this->password;
     if (!User::allowed_nickname($nickname)) {
         // TRANS: Client error displayed when trying to create a new user with an invalid username.
         $this->clientError(_('username bad'), 400);
         return;
     }
     $user_check = User::staticGet('nickname', $username);
     if ($user_check) {
         $this->clientError('username exists', 400);
         return;
     }
     $user = User::register(array('nickname' => $username, 'password' => $password, 'email' => $email, 'fullname' => $nickname, 'homepage' => $homepage, 'bio' => $description, 'location' => $location, 'code' => $code, 'gender' => $gender, 'platform_userid' => $platform_userid, 'platform_type' => $platform_type));
     if (!$user) {
         // TRANS: Form validation error displayed when trying to register with an invalid username or password.
         $this->clientError(_('Invalid username or password.', 400, 'json'));
         return;
     }
     // success!
     if (!common_set_user($user)) {
         // TRANS: Server error displayed when saving fails during user registration.
         $this->serverError(_('Error setting user.', '500', 'json'));
         return;
     }
     // this is a real login
     common_real_login(true);
     if ($this->boolean('rememberme')) {
         common_debug('Adding rememberme cookie for ' . $nickname);
         common_rememberme($user);
     }
     // Re-init language env in case it changed (not yet, but soon)
     common_init_language();
     Event::handle('EndRegistrationTry', array($this));
     if (!empty($profile_image_url)) {
         try {
             $user->getProfile()->setOriginalAvatarUrl($profile_image_url);
             common_broadcast_profile($user->getProfile());
         } catch (Exception $exc) {
         }
     }
     $this->showUserResult($user, 0);
 }
Example #6
0
    /**
     * Add Relationships
     */
    function add_relationships()
    {
        echo '<h1>Add Relationships</h1>';
        echo '<p>Here we get an existing User object.</p>';
        echo '<code>
		// Get first User<br />
		$u = new User();<br />
		$u->limit(1)->get();</code>';
        // Get first User
        $u = new User();
        $u->limit(1)->get();
        echo '<hr />';
        echo '<p>Here we get an existing Group object.</p>';
        echo '<code>
		// Get first Group<br />
		$g = new Group();<br />
		$g->limit(1)->get();</code>';
        // Get first Group
        $g = new Group();
        $g->limit(1)->get();
        echo '<hr />';
        echo '<p>Now we\'ll relate User 1 to Group 1.</p>';
        echo '<code>
		// Relate User 1 to Group 1<br />
		$u->save($g);</code>';
        // Relation User 1 to Group 1
        $u->save($g);
        echo '<hr />';
        echo '<p>Get User 2 and 3 and relate them to Group 2.</p>';
        echo '<code>
		// Get Users 2 and 3<br />
		$u = new User();
		$u->limit(2, 1)->get();<br />
		<br />
		// Get Group 2<br />
		$g = new Group();
		$g->where(\'id\', 2)->get();</code>';
        // Get Users 2 and 3
        $u = new User();
        $u->limit(2, 1)->get();
        // Get Group 2
        $g = new Group();
        $g->where('id', 2)->get();
        echo '<br />';
        echo '<p>Now we\'ll relate Users 2 and 3 to Group 2.</p>';
        echo '<code>
		// Relate Users 2 and 3 to Group 2<br />
		$g->save($u->all);</code>';
        // Relate Users 2 and 3 to Group 2<br />
        $g->save($u->all);
        echo '<hr />';
        echo '<p>Alright, now lets look at the objects to view the relationships.</p>';
        echo '<code>
		// Get first User<br />
		$u = new User();
		$u->limit(1)->get();<br />
		<br />
		// Get related group<br />
		$u->group->get();<br />
		<br />
		echo "&lt;p&gt;" . $u->username . "  belongs to Group " . $u->group->id . ", which is the " . $u->group->name . " group.&lt;/p&gt;";<br />
		<br />
		// Get User 2<br />
		$u = new User();
		$u->where(\'username\', \'Jayne Doe\')->get();<br />
		<br />
		// Get related group<br />
		$u->group->get();<br />
		<br />
		echo "&lt;p&gt;" . $u->username . " belongs to Group " . $u->group->id . ", which is " . $u->group->name . " group.&lt;/p&gt;";<br />
		<br />
		echo "&lt;p&gt;Lets see what other users relate to the " . $u->group->name . " group.&lt;/p&gt;";<br />
		<br />
		foreach ($u->group->user->get()->all as $user)<br />
		{<br />
		&nbsp;&nbsp;&nbsp;&nbsp;if ($user->id != $u->id)<br />
		&nbsp;&nbsp;&nbsp;&nbsp;{<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo "&lt;p&gt;" . $user->username . " also belongs to the " . $u->group->name ." group.&lt;/p&gt;";<br />
		&nbsp;&nbsp;&nbsp;&nbsp;}<br />
		}<br />
		</code>';
        // Get frst User
        $u = new User();
        $u->limit(1)->get();
        // Get related group
        $u->group->get();
        echo '<p>' . $u->username . '  belongs to Group ' . $u->group->id . ', which is the ' . $u->group->name . ' group.</p>';
        // Get User 2
        $u = new User();
        $u->where('username', 'Jayne Doe')->get();
        // Get related group
        $u->group->get();
        echo '<p>' . $u->username . ' belongs to Group ' . $u->group->id . ', which is the ' . $u->group->name . ' group.</p>';
        echo '<p>Lets see what other users relate to the ' . $u->group->name . ' group.</p>';
        foreach ($u->group->user->get()->all as $user) {
            if ($user->id != $u->id) {
                echo '<p>&nbsp;&nbsp;&nbsp;&nbsp;' . $user->username . ' also belongs to the ' . $u->group->name . ' group.</p>';
            }
        }
        echo '<hr />';
        echo '<p>The total counts:</p>';
        echo ucfirst(plural($u)) . ': ' . $u->count() . '<br />';
        echo ucfirst(plural($g)) . ': ' . $g->count() . '<br />';
        echo 'The ' . $g->name . ' ' . $g . ' has ' . $g->user->count() . ' ' . plural($g->user) . '.<br />';
        echo '<hr />';
        echo '<p><a href="' . site_url('examples') . '">Back to Examples</a></p>';
    }
Example #7
0
 function getUsers($y, $m, $d, $i)
 {
     $u = User::cacheGet("sitemap:user:{$y}:{$m}:{$d}:{$i}");
     if ($u === false) {
         $user = new User();
         $begindt = sprintf('%04d-%02d-%02d 00:00:00', $y, $m, $d);
         // XXX: estimates 1d == 24h, which screws up days
         // with leap seconds (1d == 24h + 1s). Thankfully they're
         // few and far between.
         $theend = strtotime($begindt) + 24 * 60 * 60;
         $enddt = common_sql_date($theend);
         $user->selectAdd();
         $user->selectAdd('nickname');
         $user->whereAdd("created >= '{$begindt}'");
         $user->whereAdd("created <  '{$enddt}'");
         $user->orderBy('created');
         $offset = ($i - 1) * SitemapPlugin::USERS_PER_MAP;
         $limit = SitemapPlugin::USERS_PER_MAP;
         $user->limit($offset, $limit);
         $user->find();
         while ($user->fetch()) {
             $u[] = $user->nickname;
         }
         $c = Cache::instance();
         if (!empty($c)) {
             $c->set(Cache::key("sitemap:user:{$y}:{$m}:{$d}:{$i}"), $u, Cache::COMPRESSED, time() > $theend ? time() + 90 * 24 * 60 * 60 : time() + 5 * 60);
         }
     }
     return $u;
 }
Example #8
0
 function prepare($args)
 {
     parent::prepare($args);
     $this->groups = array();
     $this->users = array();
     $q = $this->arg('q');
     $limit = $this->arg('limit');
     if ($limit > 200) {
         $limit = 200;
     }
     //prevent DOS attacks
     if (substr($q, 0, 1) == '@') {
         //user search
         $q = substr($q, 1);
         $user = new User();
         $user->limit($limit);
         $user->whereAdd('nickname like \'' . trim($user->escape($q), '\'') . '%\'');
         if ($user->find()) {
             while ($user->fetch()) {
                 $this->users[] = clone $user;
             }
         }
     }
     if (substr($q, 0, 1) == '!') {
         //group search
         $q = substr($q, 1);
         $group = new User_group();
         $group->limit($limit);
         $group->whereAdd('nickname like \'' . trim($group->escape($q), '\'') . '%\'');
         if ($group->find()) {
             while ($group->fetch()) {
                 $this->groups[] = clone $group;
             }
         }
     }
     return true;
 }
Example #9
0
 function showContent()
 {
     // XXX: Note I'm doing it this two-stage way because a raw query
     // with a JOIN was *not* working. --Zach
     $featured_nicks = common_config('nickname', 'featured');
     if (count($featured_nicks) > 0) {
         $quoted = array();
         foreach ($featured_nicks as $nick) {
             $quoted[] = "'{$nick}'";
         }
         $user = new User();
         $user->whereAdd(sprintf('nickname IN (%s)', implode(',', $quoted)));
         $user->limit(($this->page - 1) * PROFILES_PER_PAGE, PROFILES_PER_PAGE + 1);
         $user->orderBy(common_database_tablename('user') . '.nickname ASC');
         $user->find();
         $profile_ids = array();
         while ($user->fetch()) {
             $profile_ids[] = $user->id;
         }
         $profile = new Profile();
         $profile->whereAdd(sprintf('profile.id IN (%s)', implode(',', $profile_ids)));
         $profile->orderBy('nickname ASC');
         $cnt = $profile->find();
         if ($cnt > 0) {
             $featured = new ProfileList($profile, $this);
             $featured->show();
         }
         $profile->free();
         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE, $this->page, 'featured');
     }
 }
Example #10
0
 function prepare($args)
 {
     // If we die, show short error messages.
     StatusNet::setApi(true);
     parent::prepare($args);
     $cur = common_current_user();
     if (!$cur) {
         throw new ClientException('Access forbidden', true);
     }
     $this->groups = array();
     $this->users = array();
     $q = $this->arg('q');
     $limit = $this->arg('limit');
     if ($limit > 200) {
         $limit = 200;
     }
     //prevent DOS attacks
     if (substr($q, 0, 1) == '@') {
         //user search
         $q = substr($q, 1);
         $user = new User();
         $user->limit($limit);
         $user->whereAdd('nickname like \'' . trim($user->escape($q), '\'') . '%\'');
         if ($user->find()) {
             while ($user->fetch()) {
                 $this->users[] = clone $user;
             }
         }
     }
     if (substr($q, 0, 1) == '!') {
         //group search
         $q = substr($q, 1);
         $group = new User_group();
         $group->limit($limit);
         $group->whereAdd('nickname like \'' . trim($group->escape($q), '\'') . '%\'');
         if ($group->find()) {
             while ($group->fetch()) {
                 $this->groups[] = clone $group;
             }
         }
     }
     return true;
 }
 /** @test **/
 function it_deletes_the_rows_given_a_collection_of_ids_returned_by_laravel_collection_lists()
 {
     factory(User::class)->times(10)->create();
     $ids = User::limit(6)->get()->lists('id');
     $repository = new UserRepository($this->newContainerMock(new User()));
     $repository->destroy($ids);
     $this->assertCount(4, User::all());
 }