Skip to content

Instantly share code, notes, and snippets.

@dirkk0
Last active December 23, 2015 03:58
Show Gist options
  • Select an option

  • Save dirkk0/6576740 to your computer and use it in GitHub Desktop.

Select an option

Save dirkk0/6576740 to your computer and use it in GitHub Desktop.
Get all users in pump.io

If you look at /routes/api.js, you see the endpoints that you can access already.

One of them is /api/user//followers

But in line 179 you see app.get("/api/users", smw, anyReadAuth, listUsers);

so it turns out that the user list is already available. listUsers is defined

To stick with the followers first, we see that line 128 looks for userFollowers which is defined in streams.js

Unfortunately the github search isn't very reliable so if you do a grep -r userFollowers you'll find web.js

To see what happens there you can try to change the title in line 386 but to see the change you need to restart the pump.

The res.render tells you that the template 'followers.utml' is called so to proceed messing with the code we change something there. Chances are that you don't see anything so you might want to inspect the source code to see your changes.

Also - now would be good time to create a second account and follow each other if you are on a fresh pump.

In 'followers.utml' we see that a partial 'user-content-followers.utml' which calls another partial 'people-stream' which calls 'major-person.utml'.

/api/user/dirkk0/followers

/dirkk0/followers

server http://screencast.com/t/63riSZcm client http://screencast.com/t/8u5OeNy2eQZ

So, we start with git reset --hard

and add in api.js -no, no

var userFollowers = contextEndpoint( function(req) { return {user: req.user, author: req.person}; }, streams.userFollowers );

there is the api.js function listUsers already. no need to do something here there. so we need to create something in web.js - like showFollowers we need a showUsers and

app.get("/:nickname/followers", app.session, principal, addMessages, reqUser, showFollowers);

Following this path above didn't work out well

adding a static page

if we were just to add static content, we need to look at showMain we could create in routes/web.js around 70 app.get("/something", app.session, principal, addMessages, showSomething);

and accordingly var showSomething = function(req, res, next) { req.log.info({msg: "Showing something page"}); res.render("something", {page: {title: "Something", url: req.originalUrl}}); }; and create a template /public/template/something.utml which looks a bit like /public/template/main.utml

if we call http://.../something, we see our new page after a restart.

then of course we need some menu entry do so you would add in public/template/nav-loggedin.utml

  • Something
  • around line 28

    also we add the section in public/javascript/pump/router.js around line 151

        "something": function() {
                Pump.body.setContent({contentView: Pump.SomethingContent,
                                      title: "Something"},
                                     function() {
                                         Pump.body.endLoad();
                                     });
            }
        },
    

    and in public/javascript/pump.js around 514 you would add "#something": {View: Pump.SomethingContent},

    and finally add the view in public/javascript/pump/view.js around 720

    Pump.SomethingContent = Pump.ContentView.extend({
        templateName: 'something'
    });
    

    I ended up with a hack - allusers.html:

        <% for(var i = 0; i < users.length; i++) { %>
          <li><a href="<%= users[i] %>"><%= users[i] %></a></li>
        <% } %>
    

    web.js var showAllusers = function(req, res, next) {

        var redis = require("redis"),
        client = redis.createClient();
    
        var users = [];
        client.keys("user:*", function (err, replies) {
            if (err) {  return console.error("error response - " + err); }
            replies.forEach(function (reply, i) {
            users.push(reply.split(':')[1])
        });
        // res.send(JSON.stringify(users));
    
        req.log.info({msg: "Showing All Users"});
        res.render("allusers", {page: {title: "allusers", url: req.originalUrl},
                                users: users});
    
      });
    };
    
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment