Browse Source

add session model

activeAddress
Ivan Socolsky 8 years ago
parent
commit
3ee12d3c0f
No known key found for this signature in database GPG Key ID: FAECE6A05FAA4F56
  1. 1
      lib/model/index.js
  2. 52
      lib/model/session.js

1
lib/model/index.js

@ -8,5 +8,6 @@ Model.Notification = require('./notification');
Model.Preferences = require('./preferences'); Model.Preferences = require('./preferences');
Model.Email = require('./email'); Model.Email = require('./email');
Model.TxNote = require('./txnote'); Model.TxNote = require('./txnote');
Model.Session = require('./session');
module.exports = Model; module.exports = Model;

52
lib/model/session.js

@ -0,0 +1,52 @@
var _ = require('lodash');
var Uuid = require('uuid');
var Defaults = require('../common/defaults');
function Session() {};
Session.create = function(opts) {
opts = opts || {};
var now = Math.floor(Date.now() / 1000);
var x = new Session();
x.id = Uuid.v4();
x.version = 1;
x.createdOn = now;
x.updatedOn = now;
x.copayerId = opts.copayerId;
x.walletId = opts.walletId;
return x;
};
Session.fromObj = function(obj) {
var x = new Session();
x.id = obj.id;
x.version = obj.version;
x.createdOn = obj.createdOn;
x.updatedOn = obj.updatedOn;
x.copayerId = obj.copayerId;
x.walletId = obj.walletId;
return x;
};
Session.prototype.toObject = function() {
return this;
};
Session.prototype.isValid = function() {
var now = Math.floor(Date.now() / 1000);
return (now - this.updatedOn) <= Defaults.SESSION_EXPIRATION;
};
Session.prototype.touch = function() {
var now = Math.floor(Date.now() / 1000);
this.updatedOn = now;
};
module.exports = Session;
Loading…
Cancel
Save