add mongodb access lib

This commit is contained in:
Jay
2017-06-02 22:53:34 +08:00
parent c69679dfe2
commit e0dcf3bd6c
6 changed files with 180 additions and 9 deletions
+7 -5
View File
@@ -4,6 +4,7 @@ const router = new Router();
// import tools
const crypto = require('../../libs/crypto.js');
const so = require('../../libs/storeObject');
const mongo = require('../../libs/mongo_model.js');
router
.post('/login', async(c, n) => {
@@ -28,12 +29,13 @@ router
}
let u = c.body.record[0];
let uuid = null;
while (true) {
uuid = crypto.random(10);
if (!so.chkKey(uuid)) { break; }
let token = new mongo.token({ object: u, expire: Date.now() });
token.save();
c.body.rt = {
token: {
id: token._id
}
}
so.set(uuid, u);
})
module.exports = router;