Skip to content

Commit

Permalink
add utils fn
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-lin committed Dec 11, 2013
1 parent 9a2730d commit d9a3267
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var utils = require( '../utils' );
var mongoose = require( 'mongoose' );
var Todo = mongoose.model( 'Todo' );
var utils = require( 'connect' ).utils;

exports.index = function ( req, res, next ){
var user_id = req.cookies ?
Expand Down
28 changes: 28 additions & 0 deletions utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = {

ran_no : function ( min, max ){
return Math.floor( Math.random() * ( max - min + 1 )) + min;
},

uid : function ( len ){
var str = '';
var src = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var src_len = src.length;
var i = len;

for( ; i-- ; ){
str += src.charAt( this.ran_no( 0, src_len - 1 ));
}

return str;
},

forbidden : function ( res ){
var body = 'Forbidden';
res.statusCode = 403;

res.setHeader( 'Content-Type', 'text/plain' );
res.setHeader( 'Content-Length', body.length );
res.end( body );
}
};

0 comments on commit d9a3267

Please sign in to comment.