Added node modules
This commit is contained in:
		
							
								
								
									
										126
									
								
								node_modules/connect/lib/middleware/session/cookie.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										126
									
								
								node_modules/connect/lib/middleware/session/cookie.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,126 @@ | ||||
|  | ||||
| /*! | ||||
|  * Connect - session - Cookie | ||||
|  * Copyright(c) 2010 Sencha Inc. | ||||
|  * Copyright(c) 2011 TJ Holowaychuk | ||||
|  * MIT Licensed | ||||
|  */ | ||||
|  | ||||
| /** | ||||
|  * Module dependencies. | ||||
|  */ | ||||
|  | ||||
| var utils = require('../../utils'); | ||||
|  | ||||
| /** | ||||
|  * Initialize a new `Cookie` with the given `options`. | ||||
|  * | ||||
|  * @param {Object} options | ||||
|  * @api private | ||||
|  */ | ||||
|  | ||||
| var Cookie = module.exports = function Cookie(options) { | ||||
|   this.path = '/'; | ||||
|   this.httpOnly = true; | ||||
|   this.maxAge = 14400000; | ||||
|   if (options) utils.merge(this, options); | ||||
|   this.originalMaxAge = undefined == this.originalMaxAge | ||||
|     ? this.maxAge | ||||
|     : this.originalMaxAge; | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Prototype. | ||||
|  */ | ||||
|  | ||||
| Cookie.prototype = { | ||||
|  | ||||
|   /** | ||||
|    * Set expires `date`. | ||||
|    * | ||||
|    * @param {Date} date | ||||
|    * @api public | ||||
|    */ | ||||
|    | ||||
|   set expires(date) { | ||||
|     this._expires = date; | ||||
|     this.originalMaxAge = this.maxAge; | ||||
|   }, | ||||
|  | ||||
|   /** | ||||
|    * Get expires `date`. | ||||
|    * | ||||
|    * @return {Date} | ||||
|    * @api public | ||||
|    */ | ||||
|  | ||||
|   get expires() { | ||||
|     return this._expires; | ||||
|   }, | ||||
|    | ||||
|   /** | ||||
|    * Set expires via max-age in `ms`. | ||||
|    * | ||||
|    * @param {Number} ms | ||||
|    * @api public | ||||
|    */ | ||||
|    | ||||
|   set maxAge(ms) { | ||||
|     this.expires = 'number' == typeof ms | ||||
|       ? new Date(Date.now() + ms) | ||||
|       : ms; | ||||
|   }, | ||||
|  | ||||
|   /** | ||||
|    * Get expires max-age in `ms`. | ||||
|    * | ||||
|    * @return {Number} | ||||
|    * @api public | ||||
|    */ | ||||
|  | ||||
|   get maxAge() { | ||||
|     return this.expires instanceof Date | ||||
|       ? this.expires.valueOf() - Date.now() | ||||
|       : this.expires; | ||||
|   }, | ||||
|  | ||||
|   /** | ||||
|    * Return cookie data object. | ||||
|    * | ||||
|    * @return {Object} | ||||
|    * @api private | ||||
|    */ | ||||
|  | ||||
|   get data() { | ||||
|     return { | ||||
|         originalMaxAge: this.originalMaxAge | ||||
|       , expires: this._expires | ||||
|       , secure: this.secure | ||||
|       , httpOnly: this.httpOnly | ||||
|       , domain: this.domain | ||||
|       , path: this.path | ||||
|     } | ||||
|   }, | ||||
|  | ||||
|   /** | ||||
|    * Return a serialized cookie string. | ||||
|    * | ||||
|    * @return {String} | ||||
|    * @api public | ||||
|    */ | ||||
|  | ||||
|   serialize: function(name, val){ | ||||
|     return utils.serializeCookie(name, val, this.data); | ||||
|   }, | ||||
|  | ||||
|   /** | ||||
|    * Return JSON representation of this cookie. | ||||
|    * | ||||
|    * @return {Object} | ||||
|    * @api private | ||||
|    */ | ||||
|    | ||||
|   toJSON: function(){ | ||||
|     return this.data; | ||||
|   } | ||||
| }; | ||||
							
								
								
									
										131
									
								
								node_modules/connect/lib/middleware/session/memory.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										131
									
								
								node_modules/connect/lib/middleware/session/memory.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,131 @@ | ||||
|  | ||||
| /*! | ||||
|  * Connect - session - MemoryStore | ||||
|  * Copyright(c) 2010 Sencha Inc. | ||||
|  * Copyright(c) 2011 TJ Holowaychuk | ||||
|  * MIT Licensed | ||||
|  */ | ||||
|  | ||||
| /** | ||||
|  * Module dependencies. | ||||
|  */ | ||||
|  | ||||
| var Store = require('./store') | ||||
|   , utils = require('../../utils') | ||||
|   , Session = require('./session'); | ||||
|  | ||||
| /** | ||||
|  * Initialize a new `MemoryStore`. | ||||
|  * | ||||
|  * @api public | ||||
|  */ | ||||
|  | ||||
| var MemoryStore = module.exports = function MemoryStore() { | ||||
|   this.sessions = {}; | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Inherit from `Store.prototype`. | ||||
|  */ | ||||
|  | ||||
| MemoryStore.prototype.__proto__ = Store.prototype; | ||||
|  | ||||
| /** | ||||
|  * Attempt to fetch session by the given `sid`. | ||||
|  * | ||||
|  * @param {String} sid | ||||
|  * @param {Function} fn | ||||
|  * @api public | ||||
|  */ | ||||
|  | ||||
| MemoryStore.prototype.get = function(sid, fn){ | ||||
|   var self = this; | ||||
|   process.nextTick(function(){ | ||||
|     var expires | ||||
|       , sess = self.sessions[sid]; | ||||
|     if (sess) { | ||||
|       sess = JSON.parse(sess); | ||||
|       expires = 'string' == typeof sess.cookie.expires | ||||
|         ? new Date(sess.cookie.expires) | ||||
|         : sess.cookie.expires; | ||||
|       if (!expires || new Date < expires) { | ||||
|         fn(null, sess); | ||||
|       } else { | ||||
|         self.destroy(sid, fn); | ||||
|       } | ||||
|     } else { | ||||
|       fn(); | ||||
|     } | ||||
|   }); | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Commit the given `sess` object associated with the given `sid`. | ||||
|  * | ||||
|  * @param {String} sid | ||||
|  * @param {Session} sess | ||||
|  * @param {Function} fn | ||||
|  * @api public | ||||
|  */ | ||||
|  | ||||
| MemoryStore.prototype.set = function(sid, sess, fn){ | ||||
|   var self = this; | ||||
|   process.nextTick(function(){ | ||||
|     self.sessions[sid] = JSON.stringify(sess); | ||||
|     fn && fn(); | ||||
|   }); | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Destroy the session associated with the given `sid`. | ||||
|  * | ||||
|  * @param {String} sid | ||||
|  * @api public | ||||
|  */ | ||||
|  | ||||
| MemoryStore.prototype.destroy = function(sid, fn){ | ||||
|   var self = this; | ||||
|   process.nextTick(function(){ | ||||
|     delete self.sessions[sid]; | ||||
|     fn && fn(); | ||||
|   }); | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Invoke the given callback `fn` with all active sessions. | ||||
|  * | ||||
|  * @param {Function} fn | ||||
|  * @api public | ||||
|  */ | ||||
|  | ||||
| MemoryStore.prototype.all = function(fn){ | ||||
|   var arr = [] | ||||
|     , keys = Object.keys(this.sessions); | ||||
|   for (var i = 0, len = keys.length; i < len; ++i) { | ||||
|     arr.push(this.sessions[keys[i]]); | ||||
|   } | ||||
|   fn(null, arr); | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Clear all sessions. | ||||
|  * | ||||
|  * @param {Function} fn | ||||
|  * @api public | ||||
|  */ | ||||
|  | ||||
| MemoryStore.prototype.clear = function(fn){ | ||||
|   this.sessions = {}; | ||||
|   fn && fn(); | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Fetch number of sessions. | ||||
|  * | ||||
|  * @param {Function} fn | ||||
|  * @api public | ||||
|  */ | ||||
|  | ||||
| MemoryStore.prototype.length = function(fn){ | ||||
|   fn(null, Object.keys(this.sessions).length); | ||||
| }; | ||||
							
								
								
									
										137
									
								
								node_modules/connect/lib/middleware/session/session.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										137
									
								
								node_modules/connect/lib/middleware/session/session.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,137 @@ | ||||
|  | ||||
| /*! | ||||
|  * Connect - session - Session | ||||
|  * Copyright(c) 2010 Sencha Inc. | ||||
|  * Copyright(c) 2011 TJ Holowaychuk | ||||
|  * MIT Licensed | ||||
|  */ | ||||
|  | ||||
| /** | ||||
|  * Module dependencies. | ||||
|  */ | ||||
|  | ||||
| var utils = require('../../utils') | ||||
|   , Cookie = require('./cookie'); | ||||
|  | ||||
| /** | ||||
|  * Create a new `Session` with the given request and `data`. | ||||
|  * | ||||
|  * @param {IncomingRequest} req | ||||
|  * @param {Object} data | ||||
|  * @api private | ||||
|  */ | ||||
|  | ||||
| var Session = module.exports = function Session(req, data) { | ||||
|   Object.defineProperty(this, 'req', { value: req }); | ||||
|   Object.defineProperty(this, 'id', { value: req.sessionID }); | ||||
|   if ('object' == typeof data) { | ||||
|     utils.merge(this, data); | ||||
|   } else { | ||||
|     this.lastAccess = Date.now(); | ||||
|   } | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Update `.lastAccess` timestamp, | ||||
|  * and reset `.cookie.maxAge` to prevent | ||||
|  * the cookie from expiring when the | ||||
|  * session is still active. | ||||
|  * | ||||
|  * @return {Session} for chaining | ||||
|  * @api public | ||||
|  */ | ||||
|  | ||||
| Session.prototype.touch = function(){ | ||||
|   return this | ||||
|     .resetLastAccess() | ||||
|     .resetMaxAge(); | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Update `.lastAccess` timestamp. | ||||
|  * | ||||
|  * @return {Session} for chaining | ||||
|  * @api public | ||||
|  */ | ||||
|  | ||||
| Session.prototype.resetLastAccess = function(){ | ||||
|   this.lastAccess = Date.now(); | ||||
|   return this; | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Reset `.maxAge` to `.originalMaxAge`. | ||||
|  * | ||||
|  * @return {Session} for chaining | ||||
|  * @api public | ||||
|  */ | ||||
|  | ||||
| Session.prototype.resetMaxAge = function(){ | ||||
|   this.cookie.maxAge = this.cookie.originalMaxAge; | ||||
|   return this; | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Save the session data with optional callback `fn(err)`. | ||||
|  * | ||||
|  * @param {Function} fn | ||||
|  * @return {Session} for chaining | ||||
|  * @api public | ||||
|  */ | ||||
|  | ||||
| Session.prototype.save = function(fn){ | ||||
|   this.req.sessionStore.set(this.id, this, fn || function(){}); | ||||
|   return this; | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Re-loads the session data _without_ altering | ||||
|  * the maxAge or lastAccess properties. Invokes the | ||||
|  * callback `fn(err)`, after which time if no exception | ||||
|  * has occurred the `req.session` property will be | ||||
|  * a new `Session` object, although representing the | ||||
|  * same session. | ||||
|  * | ||||
|  * @param {Function} fn | ||||
|  * @return {Session} for chaining | ||||
|  * @api public | ||||
|  */ | ||||
|  | ||||
| Session.prototype.reload = function(fn){ | ||||
|   var req = this.req | ||||
|     , store = this.req.sessionStore; | ||||
|   store.get(this.id, function(err, sess){ | ||||
|     if (err) return fn(err); | ||||
|     if (!sess) return fn(new Error('failed to load session')); | ||||
|     store.createSession(req, sess); | ||||
|     fn(); | ||||
|   }); | ||||
|   return this; | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Destroy `this` session. | ||||
|  * | ||||
|  * @param {Function} fn | ||||
|  * @return {Session} for chaining | ||||
|  * @api public | ||||
|  */ | ||||
|  | ||||
| Session.prototype.destroy = function(fn){ | ||||
|   delete this.req.session; | ||||
|   this.req.sessionStore.destroy(this.id, fn); | ||||
|   return this; | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Regenerate this request's session. | ||||
|  * | ||||
|  * @param {Function} fn | ||||
|  * @return {Session} for chaining | ||||
|  * @api public | ||||
|  */ | ||||
|  | ||||
| Session.prototype.regenerate = function(fn){ | ||||
|   this.req.sessionStore.regenerate(this.req, fn); | ||||
|   return this; | ||||
| }; | ||||
							
								
								
									
										87
									
								
								node_modules/connect/lib/middleware/session/store.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								node_modules/connect/lib/middleware/session/store.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,87 @@ | ||||
|  | ||||
| /*! | ||||
|  * Connect - session - Store | ||||
|  * Copyright(c) 2010 Sencha Inc. | ||||
|  * Copyright(c) 2011 TJ Holowaychuk | ||||
|  * MIT Licensed | ||||
|  */ | ||||
|  | ||||
| /** | ||||
|  * Module dependencies. | ||||
|  */ | ||||
|  | ||||
| var EventEmitter = require('events').EventEmitter | ||||
|   , Session = require('./session') | ||||
|   , Cookie = require('./cookie') | ||||
|   , utils = require('../../utils'); | ||||
|  | ||||
| /** | ||||
|  * Initialize abstract `Store`. | ||||
|  * | ||||
|  * @api private | ||||
|  */ | ||||
|  | ||||
| var Store = module.exports = function Store(options){}; | ||||
|  | ||||
| /** | ||||
|  * Inherit from `EventEmitter.prototype`. | ||||
|  */ | ||||
|  | ||||
| Store.prototype.__proto__ = EventEmitter.prototype; | ||||
|  | ||||
| /** | ||||
|  * Re-generate the given requests's session. | ||||
|  * | ||||
|  * @param {IncomingRequest} req | ||||
|  * @return {Function} fn | ||||
|  * @api public | ||||
|  */ | ||||
|  | ||||
| Store.prototype.regenerate = function(req, fn){ | ||||
|   var self = this; | ||||
|   this.destroy(req.sessionID, function(err){ | ||||
|     self.generate(req); | ||||
|     fn(err); | ||||
|   }); | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Load a `Session` instance via the given `sid` | ||||
|  * and invoke the callback `fn(err, sess)`. | ||||
|  * | ||||
|  * @param {String} sid | ||||
|  * @param {Function} fn | ||||
|  * @api public | ||||
|  */ | ||||
|  | ||||
| Store.prototype.load = function(sid, fn){ | ||||
|   var self = this; | ||||
|   this.get(sid, function(err, sess){ | ||||
|     if (err) return fn(err); | ||||
|     if (!sess) return fn(); | ||||
|     var req = { sessionID: sid, sessionStore: self }; | ||||
|     sess = self.createSession(req, sess, false); | ||||
|     fn(null, sess); | ||||
|   }); | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Create session from JSON `sess` data. | ||||
|  * | ||||
|  * @param {IncomingRequest} req | ||||
|  * @param {Object} sess | ||||
|  * @return {Session} | ||||
|  * @api private | ||||
|  */ | ||||
|  | ||||
| Store.prototype.createSession = function(req, sess, update){ | ||||
|   var expires = sess.cookie.expires | ||||
|     , orig = sess.cookie.originalMaxAge | ||||
|     , update = null == update ? true : false; | ||||
|   sess.cookie = new Cookie(sess.cookie); | ||||
|   if ('string' == typeof expires) sess.cookie.expires = new Date(expires); | ||||
|   sess.cookie.originalMaxAge = orig; | ||||
|   req.session = new Session(req, sess); | ||||
|   if (update) req.session.resetLastAccess(); | ||||
|   return req.session; | ||||
| }; | ||||
		Reference in New Issue
	
	Block a user