mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-12 16:57:39 -05:00
adding Admin server
This commit is contained in:
14
admin/server/models/group.js
Normal file
14
admin/server/models/group.js
Normal file
@@ -0,0 +1,14 @@
|
||||
var mongoose = require('mongoose');
|
||||
|
||||
|
||||
|
||||
var groupSchema = mongoose.Schema({
|
||||
shortName: String,
|
||||
groupName: String,
|
||||
groupId: String,
|
||||
position: Number,
|
||||
talkgroups: [Number]
|
||||
});
|
||||
|
||||
|
||||
module.exports = mongoose.model('Group', groupSchema);
|
||||
24
admin/server/models/permission.js
Normal file
24
admin/server/models/permission.js
Normal file
@@ -0,0 +1,24 @@
|
||||
// Defining a User Model in mongoose
|
||||
// Code modified from https://github.com/sahat/hackathon-starter
|
||||
|
||||
var mongoose = require("mongoose");
|
||||
|
||||
|
||||
|
||||
const PermissionSchema = new mongoose.Schema({
|
||||
userId: mongoose.Schema.Types.ObjectId,
|
||||
systemId: mongoose.Schema.Types.ObjectId,
|
||||
shortName: String,
|
||||
role: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
ver: {
|
||||
type: Number,
|
||||
default: 1.2
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
module.exports=mongoose.model("Permission", PermissionSchema)
|
||||
27
admin/server/models/system.js
Normal file
27
admin/server/models/system.js
Normal file
@@ -0,0 +1,27 @@
|
||||
var mongoose = require('mongoose');
|
||||
var bcrypt = require('bcrypt');
|
||||
|
||||
var systemSchema = mongoose.Schema({
|
||||
name: String,
|
||||
shortName: String,
|
||||
systemType: String,
|
||||
county: String,
|
||||
country: String,
|
||||
city: String,
|
||||
state: String,
|
||||
description: String,
|
||||
showScreenName: Boolean,
|
||||
planType: {type: Number, default: 0},
|
||||
userId: mongoose.Schema.Types.ObjectId,
|
||||
key: String
|
||||
});
|
||||
|
||||
systemSchema.methods.generateHash = function(password) {
|
||||
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
|
||||
};
|
||||
|
||||
systemSchema.methods.validPassword = function(password) {
|
||||
return bcrypt.compareSync(password, this.local.password);
|
||||
};
|
||||
|
||||
module.exports = mongoose.model('System', systemSchema);
|
||||
12
admin/server/models/system_stat.js
Normal file
12
admin/server/models/system_stat.js
Normal file
@@ -0,0 +1,12 @@
|
||||
var mongoose = require('mongoose');
|
||||
|
||||
var systemStatSchema = mongoose.Schema({
|
||||
callTotals: [Number],
|
||||
errorTotals: [Number],
|
||||
usageBytes: Number,
|
||||
usageMb: Number,
|
||||
shortName: String
|
||||
}, { collection: 'system_stats' });
|
||||
|
||||
|
||||
module.exports = mongoose.model('SystemStat', systemStatSchema);
|
||||
16
admin/server/models/talkgroup.js
Normal file
16
admin/server/models/talkgroup.js
Normal file
@@ -0,0 +1,16 @@
|
||||
var mongoose = require('mongoose');
|
||||
|
||||
var talkgroupSchema = mongoose.Schema({
|
||||
shortName: String,
|
||||
userId: String,
|
||||
num: Number,
|
||||
mode: String,
|
||||
alpha: String,
|
||||
description: String,
|
||||
tag: String,
|
||||
group: String,
|
||||
priority: Number
|
||||
});
|
||||
|
||||
|
||||
module.exports = mongoose.model('Talkgroup', talkgroupSchema);
|
||||
91
admin/server/models/user.js
Normal file
91
admin/server/models/user.js
Normal file
@@ -0,0 +1,91 @@
|
||||
// Defining a User Model in mongoose
|
||||
// Code modified from https://github.com/sahat/hackathon-starter
|
||||
const bcrypt = require("bcrypt");
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
|
||||
|
||||
const UserSchema = new mongoose.Schema({
|
||||
local: {
|
||||
name: String,
|
||||
email: String,
|
||||
password: String
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
unique: true,
|
||||
lowercase: true
|
||||
},
|
||||
password: String,
|
||||
screenName: {
|
||||
type: String,
|
||||
unique: true,
|
||||
lowercase: true
|
||||
},
|
||||
firstName: String,
|
||||
lastName: String,
|
||||
location: String,
|
||||
email: String,
|
||||
resetPasswordToken: String,
|
||||
resetPasswordTTL: Date,
|
||||
confirmEmail: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
customerId: {
|
||||
type: String,
|
||||
default: ""
|
||||
},
|
||||
confirmEmailToken: String,
|
||||
confirmEmailTTL: Date,
|
||||
admin: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
terms: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
ver: {
|
||||
type: Number,
|
||||
default: 1.1
|
||||
},
|
||||
sysCount: Number,
|
||||
lastLogin: { type : Date, default: Date.now }
|
||||
})
|
||||
|
||||
/**
|
||||
* Password hash middleware.
|
||||
*/
|
||||
UserSchema.pre("save", function(next) {
|
||||
var user = this
|
||||
if (!user.isModified("password")) return next()
|
||||
bcrypt.genSalt(8, (err, salt) => {
|
||||
if (err) return next(err)
|
||||
bcrypt.hash(user.password, salt, null, (err, hash) => {
|
||||
if (err) return next(err)
|
||||
user.password = hash;
|
||||
user.local.password = hash;
|
||||
next()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
/*
|
||||
Defining our own custom document instance method
|
||||
*/
|
||||
UserSchema.methods = {
|
||||
comparePassword: function(candidatePassword, cb) {
|
||||
bcrypt.compare(candidatePassword, this.local.password, (err, isMatch) => {
|
||||
if (err) return cb(err)
|
||||
cb(null, isMatch)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Statics
|
||||
*/
|
||||
UserSchema.statics = {}
|
||||
|
||||
module.exports = mongoose.model("User", UserSchema)
|
||||
Reference in New Issue
Block a user