1
0
Fork 0

basic database models

master
Ruben Meyer 4 years ago
parent 7c570c4f57
commit 2e8e8f35e7

@ -0,0 +1,89 @@
/*
* This file is part of the authRxbn eco-system.
*
* (c) Ruben Meyer <contact@rxbn.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
var mongoose = require('mongoose');
var models = {};
const Schema = mongoose.Schema;
const ObjectId = Schema.ObjectId;
// user
models.user = new Schema({
nickname: String, // Nickname
email: {
type: String,
validate: [
{ validator: function(value) {
let regex = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
return regex.test(value);
}
}
]
},
passhash: String, // hashed password (String + separator + Salt)
token: { // last remember me cookie
type: String,
default: ""
},
mfa: { // multi factor authentication
active: {type: Boolean, default: false},
type: {type: String, default: ""},
data: {type: String, default: ""} // tel number or secret token
},
settings: {type: Object, default: {}}, // custom settings (theme etc. pp.)
roles: {type: String, default: ""}, // user-defined roles and permissions
group: {type: Number, default: 0}, // group-id for group-defined roles and permissions
reg_date: {type: Date, default: Date.now}, // registration date
last_action: {type: Date, default: Date.now}, // last action (activity date)
});
// group
models.group = new Schema({
name: String, // recognizable application name; ex. "Administration"
created: {type: Date, default: Date.now},
roles: {type: String, default: ""} // roles; separated by commas "a,b,a.b,c.*,d.z.*"
});
// application | service
models.application = new Schema({
name: String, // recognizable application name; ex. "passRXBN - Password Manager"
access: String, // redirected uri; do not trust user input
secret: String, // application secret; authorize requests
description: String // service description on dashboard; markdown support
});
// activities
models.activity = new Schema({
userId: Schema.Types.ObjectId,
date: { type: Date, default: Date.now},
uri: { type: String, default: ""},
state: { type: Boolean, default: false }
});
// used authcodes
models.authCode = new Schema({
applicationId: Schema.Types.ObjectId,
userId: Schema.Types.ObjectId,
token: String, // generated token, only usable in combination with userId and applicationId
timestamp: { type: Date, default: Date.now }
});
module.exports = (con) => {
let mdls = {};
// initialize models
mdls.user = con.model('User', models.user);
mdls.group = con.model('Group', models.group);
mdls.application = con.model('Application', models.application);
mdls.activity = con.model('Activity', models.activity);
mdls.authCode = con.model('AuthCode', models.authCode);
// return models for further processing
return mdls;
};
Loading…
Cancel
Save