lib/models/tokens.js
function create(body, cb) {
  var validates = Schema(body);

  if(!validates) {
    return cb(new exceptions.BadRequest());
  }

  body.expires_at = stampify(conf.session_maxage);

  var q = qb.insert(body);
  db.getClient(function(err, client, done) {
    client.query(q[0], q[1], function(err, r) {
      if(err) {
        if(err.code == 23505) {
          err = new exceptions.AlreadyExists();
        }
        cb(err);
        done(err);
      } else {
        cb(null, r.rows[0]);
        done();
      }
    });
  });
}
function create(body, cb) {
  var validates = Schema(body);

  if(!validates) {
    return cb(new exceptions.BadRequest());
  }

  body.expires_at = stampify(conf.session_maxage);

  var q = qb.insert(body);
  db.getClient(function(err, client, done) {
    client.query(q[0], q[1], function(err, r) {
      if(err) {
        if(err.code == 23505) {
          err = new exceptions.AlreadyExists();
        }
        cb(err);
        done(err);
      } else {
        cb(null, r.rows[0]);
        done();
      }
    });
  });
}
function create ( body , cb ) { var validates = Schema ( body ) ; if ( ! validates ) { return cb ( new exceptions . BadRequest ( ) ) ; } body . expires_at = stampify ( conf . session_maxage ) ; var q = qb . insert ( body ) ; db . getClient ( function ( err , client , done ) { client . query ( q [ 0 ] , q [ 1 ] , function ( err , r ) { if ( err ) { if ( err . code == 23505 ) { err = new exceptions . AlreadyExists ( ) ; } cb ( err ) ; done ( err ) ; } else { cb ( null , r . rows [ 0 ] ) ; done ( ) ; } } ) ; } ) ; }
Creates a new token.

`cb` is passed with the newly created token or:

* exceptions.BadRequest: if `body` does not satisfy the schema
* exceptions.AlreadyExists: if a token with the same `token` already exists

@param {Object} body
@param {Function} cb
Creates a new token .