mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-03 03:55:26 +03:00
3ff9146d9e
- remove sessions - remove all references to csrf - create a shared base model for the 2 types of token
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
var ghostBookshelf = require('./base'),
|
|
|
|
Basetoken;
|
|
|
|
Basetoken = ghostBookshelf.Model.extend({
|
|
|
|
user: function () {
|
|
return this.belongsTo('User');
|
|
},
|
|
|
|
client: function () {
|
|
return this.belongsTo('Client');
|
|
},
|
|
|
|
// override for base function since we don't have
|
|
// a created_by field for sessions
|
|
creating: function (newObj, attr, options) {
|
|
/*jshint unused:false*/
|
|
},
|
|
|
|
// override for base function since we don't have
|
|
// a updated_by field for sessions
|
|
saving: function (newObj, attr, options) {
|
|
/*jshint unused:false*/
|
|
// Remove any properties which don't belong on the model
|
|
this.attributes = this.pick(this.permittedAttributes());
|
|
}
|
|
|
|
}, {
|
|
destroyAllExpired: function (options) {
|
|
options = this.filterOptions(options, 'destroyAll');
|
|
return ghostBookshelf.Collection.forge([], {model: this})
|
|
.query('where', 'expires', '<', Date.now())
|
|
.fetch()
|
|
.then(function (collection) {
|
|
collection.invokeThen('destroy', options);
|
|
});
|
|
}
|
|
});
|
|
|
|
module.exports = Basetoken; |