olinapps

Module for Olinapps.com and other Olin College functionality.

npm install olinapps
14 downloads in the last week
28 downloads in the last month

node-olinapps

npm install olinapps

In the top of your file:

var olinapps = require('olinapps');

In your express app, right after your app.configure:

/**
 * Authentication
 */

app.post('/login', olinapps.login);
app.all('/logout', olinapps.logout);
app.all('/*', olinapps.middleware);
app.all('/api/*', olinapps.loginRequiredJSON); // (optional) login required, no redirect, returns 401
app.all('/*', olinapps.loginRequired);

Remove the loginRequired line if logging in is optional. Then in any route:

app.get('/', function (req, res) {
  var user = olinapps.user(req);
  console.log(user);
  // ...
})

Yields:

{ id: 'timothy.ryan',
  created: 1354933883,
  domain: 'students.olin.edu',
  username: 'timothy.ryan',
  email: 'timothy.ryan@students.olin.edu' }

Directory & Mailing Lists

You can request information from the Olin Directory or Mailing List APIs.

app.get('/me', function (req, res) {
  olinapps.directory.me(req, function (err, json) {
    res.json(json);
  });
});

app.get('/people', function (req, res) {
  olinapps.directory.people(req, function (err, json) {
    res.json(json);
  });
});

app.get('/list', function (req, res) {
  olinapps.lists.search(req, 'helpme', 'ride to eliot', function (err, messages) {
    res.json(messages);
  });
});

API

Session:

olinapps.user(req);
olinapps.sessionid(req);

Middleware:

olinapps.login
olinapps.logout
olinapps.middleware
olinapps.loginRequired
olinapps.loginRequiredJSON

APIs:

olinapps.directory.me(req, callback)
olinapps.directory.people(req, callback)

olinapps.lists.search(req, list_name, keywords, callback)

Example

See the source for quotes.olinapps.com for an example.

npm loves you