diff options
| author | Kyle K <kylek389@gmail.com> | 2012-07-02 01:35:05 -0500 | 
|---|---|---|
| committer | Kyle Kaminski <kyle@kkaminsk.com> | 2012-07-02 01:35:05 -0500 | 
| commit | 46230d8dd0709829859dc1feb92db17933000fcc (patch) | |
| tree | d99ca007fac8ccb2943f662b9e218d13248dfd4c /protoype | |
| parent | b001224bb95996fa59269a5c119c6a9f2047f288 (diff) | |
| download | fubar-46230d8dd0709829859dc1feb92db17933000fcc.tar.gz fubar-46230d8dd0709829859dc1feb92db17933000fcc.tar.bz2 fubar-46230d8dd0709829859dc1feb92db17933000fcc.zip  | |
tired man
Diffstat (limited to 'protoype')
| -rw-r--r-- | protoype/app.js | 53 | ||||
| -rw-r--r-- | protoype/views/index.jade | 6 | 
2 files changed, 43 insertions, 16 deletions
diff --git a/protoype/app.js b/protoype/app.js index 73b0aa8..6722eab 100644 --- a/protoype/app.js +++ b/protoype/app.js @@ -26,13 +26,13 @@ app.configure(function() {      app.use(express.compress());  /* gzip */      app.use(express.bodyParser()); /* creates req.body which req.param() uses */      app.use(express.cookieParser()); /* req.session can be populated with user defined vars */ -    app.use(express.session({ secret: "keyboard cat", store: new RedisStore })); +    app.use(express.session({ secret: "keyboard cat", store: new RedisStore() }));      app.use(app.router);      app.use(express.static(__dirname + '/public'));  });  app.post('/create', function(req, res) { -    db.users.save({tag: req.param('tag'), id: req.param('id'), active: false, vehicle: '', +    db.users.save({tag: req.param('tag'), id: req.param('id'), status: "offline", vehicle: '',                     avatar: 'images/avatars/default.png', sig: '', location: '', races: 0},      function(err, thing) {          if (err || !thing) @@ -50,10 +50,13 @@ app.post('/login', function(req, res) {              res.send('user does not exist\n', 403);          }          else { -            util.log('[login] retrived user: ' + util.inspect(thing)); +            /* util.log('[login] retrived user: ' + util.inspect(thing)); */              if (req.param('id') === thing[0].id) { /* insert md5 hashing here */ -                util.log('[login] successfully logged in'); -                thing[0].active = true; /* this, or have redis? */ +                util.log('[login] ' + thing[0].tag + ' authenticated'); +                db.users.update({tag: req.param('tag')}, {$set: {status: 'online'}}, function(err, updated) { +                    if (err || !updated) +                        util.log('[login] failed to set status to online'); +                });                  res.send('successfully logged in\n', 200);              }              else { @@ -64,16 +67,36 @@ app.post('/login', function(req, res) {      });  }); -app.post('/poll:id([a-z]+)', function(req, res) { -    db.users.save({tag: req.param('tag'), id: req.param('id'), active: false, vehicle: '', -                   avatar: 'images/avatars/default.png', sig: '', location: '', races: 0}, -    function(err, thing) { -        if (err || !thing) -            util.log('[create] error saving'); -        else -            util.log('[create] successfully saved'); -    }); -    res.redirect('/'); +app.get('/sys/:id([a-z]+)', function(req, res, next) { +    /* id contains routing token, req.query is a block/struct, key-val data structure containing GET params +     * id should be the main verb, action we want to do */ +    util.log('[sys] route id aka action: ' + req.params.id); +    if (req.params.id === 'do') { +        var data = ''; +        if (req.query.get != 'undefined') { +            util.log('[sys] get value: ' + req.query.get); +            if (req.query.get === 'activelist') { +                db.users.find({status: 'online'}, function(err, result) { +                    if (err || !result) +                        util.log('[sys] do?get=activelist failed or empty'); +                    else { +                        for (var i = 0; i < result.length; i++) { +                            console.log('name is: ' + result[i].tag); +                            data += result[i].tag + '\n'; +                        } +                        res.send(data); +                    } +                }); +            } +        } +        else if (req.query.fetch != 'undefined') { +            util.log('[sys] fetch value: ' + req.query.fetch); +            res.send(data); +        } +        else next(); +    } +    else +        next();  });  app.get('/', function(req, res) { diff --git a/protoype/views/index.jade b/protoype/views/index.jade index 57cde6f..cfbdb80 100644 --- a/protoype/views/index.jade +++ b/protoype/views/index.jade @@ -1,7 +1,11 @@  h1= title -p Welcome to #{title}. Users in the portal: +p Welcome to #{title}.  h3 User list:  ul    - each user in users      li= user.tag +    - if (user.status == 'online') +      span(style='color: green')= user.status +    - else +      span(style='color: red')= user.status  | 
