2017-06-02 14:53:34 +00:00
|
|
|
const mongoose = require('mongoose');
|
|
|
|
|
|
|
|
const tokenSchema = mongoose.Schema({
|
|
|
|
object: Object,
|
|
|
|
expire: {
|
|
|
|
type: Number,
|
|
|
|
default: Date.now
|
|
|
|
}
|
|
|
|
});
|
2017-06-03 13:20:34 +00:00
|
|
|
tokenSchema.statics.clearExpire = function(cb) {
|
|
|
|
console.log(Date.now())
|
|
|
|
return this.remove({ expire: { $lte: Date.now() } }, cb);
|
|
|
|
}
|
|
|
|
tokenSchema.statics.renewToken = function(id, expire, cb) {
|
|
|
|
return this.update({ _id: mongoose.Schema.Types.ObjectId(id) }, { $set: { expire: Date.now() + 86400000 } }, cb);
|
|
|
|
}
|
2017-06-02 14:53:34 +00:00
|
|
|
|
|
|
|
const token = mongoose.model('token', tokenSchema, 'token');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
token
|
|
|
|
}
|