Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed session handler

  • Loading branch information...
commit 35426a662381f9b4acf2d729de70715088363ab3 1 parent 17dc7e1
@rayui authored
Showing with 16 additions and 17 deletions.
  1. +5 −6 js/modules/server.js
  2. +11 −11 js/modules/sessions.js
View
11 js/modules/server.js
@@ -106,12 +106,13 @@ var Server = function(_settings){
//get or create a session
if (!sessionId) {
- sessionId = ss.createSession(new Date().getTime());
+ sessionId = sessionHandler.createSession();
req.session.sessionId = sessionId;
}
- if (!ss.getSession(sessionId)[route.model]) {
- m = ss.createModel(req.session.sessionId, route.model);
+ //get or create the model for this route
+ if (!sessionHandler.getSession(sessionId)[route.model]) {
+ m = sessionHandler.createModel(req.session.sessionId, route.model);
m.on('db:query', function(query, fields, _callback) {
that.emit('db:query', m.schema.name, query, fields, _callback);
});
@@ -120,8 +121,6 @@ var Server = function(_settings){
headers['Content-Type'] === 'application/json' ? m.ready(sendJSON) : m.ready(sendHTML);
m[req.method.toString().toLowerCase()](req.body);
- console.log(sessionId);
-
break;
}
};
@@ -131,7 +130,7 @@ var Server = function(_settings){
//create express server and configure
var app = express.createServer();
- var ss = new sessions.Server(settings.sessions);
+ var sessionHandler = new sessions.Handler(settings.sessions);
app.configure(function(){
app.use(express.bodyParser());
View
22 js/modules/sessions.js
@@ -10,7 +10,7 @@ var _ = require('underscore')._,
var sessions = [];
//set up server model
-var Server = function(_settings){
+var Handler = function(_settings){
events.EventEmitter.call(this);
@@ -21,19 +21,19 @@ var Server = function(_settings){
};
-Server.super = events.EventEmitter;
-Server.prototype = Object.create(events.EventEmitter.prototype, {
+Handler.super = events.EventEmitter;
+Handler.prototype = Object.create(events.EventEmitter.prototype, {
constructor: {
- value: Server,
+ value: Handler,
enumerable: false
}
});
-Server.prototype.createSession = function() {
+Handler.prototype.createSession = function() {
//creates new session object in sessions
//returns object
- var md5sum = new crypto.createHash('sha1');
- md5sum.update(arguments.toString());
+ var md5sum = new crypto.createHash('md5');
+ md5sum.update(new Date().getTime().toString());
var sessionId = md5sum.digest('base64');
sessions[sessionId] = {models:{}};
@@ -41,21 +41,21 @@ Server.prototype.createSession = function() {
return sessionId;
};
-Server.prototype.getSession = function(sessionId) {
+Handler.prototype.getSession = function(sessionId) {
//if session with key md5 exists return it
//else return undefined
return sessions[sessionId];
};
-Server.prototype.createModel = function(sessionId, modelName) {
+Handler.prototype.createModel = function(sessionId, modelName) {
var that = this;
var m = sessions[sessionId]['models'][modelName] = new model.Model(modelName);
return m;
};
-Server.prototype.query = function(m) {
+Handler.prototype.query = function(m) {
var that = this;
};
-exports.Server = Server;
+exports.Handler = Handler;
Please sign in to comment.
Something went wrong with that request. Please try again.