Commit 55f62775 authored by KANTAPONG SONG-NGAM's avatar KANTAPONG SONG-NGAM

add new

parent 3016b0cf
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
DashSchema = new Schema({
income : {
type : Number,
required : true
},
due : {
type : Number,
required:true
}
})
module.exports = mongoose.model('dashboard',DashSchema)
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
PaymentSchema = new Schema({
id : {
type : Number,
required : true
},
username : {
type : String,
required : true
},
payment : {
type : Number,
required : true
},
sub_id : {
type : [String],
required : true
}
})
module.exports = mongoose.model('payments', PaymentSchema)
Schema = require('mongoose').Schema
ThingSchema = new Schema({
Name : {
type : String,
required : true
},
Data : {
type : [{
Value : {
type : Number,
min : 0
},
Time : {
type : Date
}
}]
},
userId : {
type : Schema.Types.ObjectId
}
})
module.exports = mongoose.model('Things', ThingSchema)
Schema = require('mongoose').Schema
bcrypt = require('bcrypt')
SALT_WORK_FACTOR = 10
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
UserSchema = new Schema({
id : {
type : Number,
required : true
},
username : {
type : String,
required : true
......@@ -10,33 +14,19 @@ UserSchema = new Schema({
password : {
type : String,
required : true
},
Email : {
type : String,
required : true
},
payment : {
type : Number,
required : true
},
sub_id : {
type : [String],
required : true
}
})
UserSchema.pre('save', function(next) {
user = this
if (!user.isModified('password'))
return next()
bcrypt.genSalt(SALT_WORK_FACTOR, function(err, salt) {
if (err) return next (err)
bcrypt.hash(user.password, salt, function(err, hash) {
if (err) return next (err)
user.password = hash
next()
})
})
})
UserSchema.methods.comparePassword = function(candidate, cb) {
bcrypt.compare(candidate, this.password, function(err, isMatch) {
if (err) return cb (err)
cb(null, isMatch)
})
}
module.exports = mongoose.model('Users', UserSchema)
module.exports = {
'secret': 'Student',
'database': 'mongodb://localhost/StdManageAPI'
}
\ No newline at end of file
mongoose = require('mongoose')
Things = require('./Things')
Users = require('./Users')
mongoose.connect('mongodb://localhost:27017/Students',{useNewUrlParser:true});
add_User = new Users({
username: 'test',
password: 'pass'
})
add_User.save(function(err) {
if (err) throw err
console.log('save USer completed.')
})
{
"name": "project",
"version": "1.0.0",
"lockfileVersion": 1
}
{
"name": "project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
This diff is collapsed.
This diff is collapsed.
......@@ -13,7 +13,7 @@
"body-parser": "^1.18.3",
"express": "^4.16.4",
"jsonwebtoken": "^8.3.0",
"mongoose": "^5.3.7",
"mongoose": "^5.3.11",
"morgan": "^1.9.1",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
......
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
DashSchema = new Schema({
income : {
type : Number,
required : true
}
})
module.exports = mongoose.model('Dashboard',DashSchema)
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
PaymentSchema = new Schema({
id : {
type : Number,
required : true
},
username : {
type : String,
required : true
},
payment : {
type : Number,
required : true
},
sub_id : {
type : [String],
required : true
}
})
module.exports = mongoose.model('payments', PaymentSchema)
......@@ -2,11 +2,12 @@ mongoose = require('mongoose')
Things = require('./Things')
Users = require('./Users')
mongoose.connect('mongodb://localhost:27017/TestAPI',{useNewUrlParser:true});
mongoose.connect('mongodb://localhost:27017/StdManageAPI',{useNewUrlParser:true});
testUser = new Users({
username: 'test',
password: 'pass'
username: 'Admin',
password: '1234',
admin:true
})
testUser.save(function(err) {
......
module.exports = {
'secret': 'KolenCompation',
'database': 'mongodb://localhost/Kolen'
'database': 'mongodb://localhost/StdManageAPI'
}
\ No newline at end of file
......@@ -36,8 +36,8 @@ app.get('/', function(req, res) {
app.get('/setup', function(req, res) {
demo = new User({
username: 'demouser',
password: 'password', // TODO: encrypt password with bcrypt
username: 'admin',
password: '1234', // TODO: encrypt password with bcrypt
admin: true
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment