ensl_gathers/db/models/session.js
2015-08-18 10:56:35 +01:00

18 lines
432 B
JavaScript

"use strict";
var mongoose = require("mongoose");
var Schema = mongoose.Schema;
var crypto = require('crypto');
var keyGenerator = () => {
return crypto.randomBytes(20).toString('hex');
};
var sessionSchema = new Schema({
userId: { type: Number, required: true },
key: { type: String, required: true, default: keyGenerator }
});
sessionSchema.index({ userId: 1 });
module.exports = mongoose.model("Session", sessionSchema);