consolidate all repos to one for archive
This commit is contained in:
13
projektna_naloga/web_server/models/dailyDataModel.js
Normal file
13
projektna_naloga/web_server/models/dailyDataModel.js
Normal file
@@ -0,0 +1,13 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const dailyDataSchema = new Schema({
|
||||
'location_id': Number,
|
||||
'date': Date,
|
||||
'car_count': Number,
|
||||
'year': Number,
|
||||
'month': Number,
|
||||
'day': Number
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('dailyData', dailyDataSchema);
|
14
projektna_naloga/web_server/models/hourlyDataModel.js
Normal file
14
projektna_naloga/web_server/models/hourlyDataModel.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const hourlyDataSchema = new Schema({
|
||||
'location_id': Number,
|
||||
'date': Date,
|
||||
'car_count': Number,
|
||||
'hour': Number,
|
||||
'day': Number,
|
||||
'month': Number,
|
||||
'year': Number
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('hourlyData', hourlyDataSchema);
|
12
projektna_naloga/web_server/models/rawCameraDataModel.js
Normal file
12
projektna_naloga/web_server/models/rawCameraDataModel.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const rawCameraDataSchema = new Schema({
|
||||
'location_id': Number,
|
||||
'camera_id': Number,
|
||||
'date': Date,
|
||||
'car_count': Number,
|
||||
'hour': Number
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('rawCameraData', rawCameraDataSchema);
|
45
projektna_naloga/web_server/models/userModel.js
Normal file
45
projektna_naloga/web_server/models/userModel.js
Normal file
@@ -0,0 +1,45 @@
|
||||
const mongoose = require('mongoose');
|
||||
const bcrypt = require('bcrypt');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const userSchema = new Schema({
|
||||
'username': String,
|
||||
'password': String,
|
||||
'email': String,
|
||||
'locations': Array
|
||||
});
|
||||
|
||||
userSchema.pre('save', function (next) {
|
||||
const user = this;
|
||||
bcrypt.hash(user.password, 10, function (err, hash) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
user.password = hash;
|
||||
next();
|
||||
});
|
||||
});
|
||||
|
||||
userSchema.statics.authenticate = function (username, password, callback) {
|
||||
User.findOne({ username: username })
|
||||
.exec(function (err, user) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
} else if (!user) {
|
||||
const err = new Error("User not found.");
|
||||
err.status = 401;
|
||||
return callback(err);
|
||||
}
|
||||
bcrypt.compare(password, user.password, function (err, result) {
|
||||
if (result === true) {
|
||||
return callback(null, user);
|
||||
} else {
|
||||
return callback();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
const User = mongoose.model('user', userSchema);
|
||||
module.exports = User;
|
Reference in New Issue
Block a user