Genesis commit

This commit is contained in:
Kgothatso
2019-11-23 23:08:03 +02:00
parent 479b59cf51
commit a590b8ff3f
52 changed files with 15901 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
module.exports = function (sequelize, DataTypes, options) {
const model = sequelize.define("authenticationMethod", {
id: {
type: DataTypes.STRING,
defaultValue: function() {
return options.generateUniqueId()
},
primaryKey: true,
unique: true
},
method: {
type: DataTypes.ENUM,
values: ['hd-auth', 'password', 'google-oauth']
},
order: {
type: DataTypes.INTEGER,
defaultValue: function() {
return 0;
}
}
}, {
comment: "The supported authentication methods for a user of the system."
});
model.associate = (db) => {
model.User = model.belongsTo(db.User);
}
return model;
};

View File

@@ -0,0 +1,25 @@
module.exports = function (sequelize, DataTypes, options) {
const model = sequelize.define("extendedPublicKey", {
id: {
type: DataTypes.STRING,
defaultValue: function() {
return options.generateUniqueId()
},
primaryKey: true,
unique: true
},
xpub: {
type: DataTypes.STRING,
allowNull: false,
unique: true
}
}, {
comment: "Extended Public Key belonging to the users of the system"
});
model.associate = (db) => {
model.User = model.belongsTo(db.User);
}
return model;
};

View File

@@ -0,0 +1,36 @@
const bcrypt = require('bcrypt');
module.exports = function (sequelize, DataTypes, options) {
const model = sequelize.define("password", {
id: {
type: DataTypes.STRING,
defaultValue: function() {
return options.generateUniqueId()
},
primaryKey: true,
unique: true
},
password: {
type: DataTypes.STRING,
// primaryKey: true,
unique: true,
allowNull: false,
set(val) {
var hashedPassword = options != null && val != null && val.length > 0 ?
bcrypt.hashSync(val, bcrypt.genSaltSync(11)) :
null
;
this.setDataValue('password', hashedPassword);
}
// should have an accessor method the redacts this failed...
}
}, {
comment: "hashed password"
});
model.associate = (db) => {
model.User = model.belongsTo(db.User);
}
return model;
};

View File

@@ -0,0 +1,19 @@
module.exports = function (sequelize, DataTypes, options) {
var model = sequelize.define("session", {
sid: {
type: DataTypes.STRING,
primaryKey: true,
unique: true,
},
expires: DataTypes.DATE,
data: DataTypes.STRING(50000)
}, {
comment: "Each session in the system will be stored in this table..."
});
model.associate = (db) => {
model.User = model.belongsTo(db.User);
}
return model;
};

View File

@@ -0,0 +1,28 @@
module.exports = function (sequelize, DataTypes, options) {
const model = sequelize.define("user", {
id: {
type: DataTypes.STRING,
defaultValue: function() {
return options.generateUniqueId()
},
primaryKey: true,
unique: true
},
displayName: {
type: DataTypes.STRING,
// allowNull: false
}
}, {
comment: "The individual users of the system..."
});
model.associate = (db) => {
model.Sessions = model.hasMany(db.Session);
model.ExtendedPublicKeys = model.hasMany(db.ExtendedPublicKey);
model.Passwords = model.hasMany(db.Password);
model.AuthenticationMethods = model.hasMany(db.AuthenticationMethod);
}
return model;
};