-
Notifications
You must be signed in to change notification settings - Fork 0
/
VrstanPublic.js
154 lines (124 loc) · 4.4 KB
/
VrstanPublic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* This File is Property of BitOneIncorporated.
Created: Sunday January 28 2018
Author: Ian A. Moncrieffe
Tel: 1876-778-6804
email: dev.bitone@outlook.com
*/
// Requirements
const express = require('express'),
path = require('path'),
ejs_layout = require('ejs-layouts'),
http = require('http'),
upload = require('express-fileupload'),
port = 4800,
bodyParser = require('body-parser'),
db = require('./DB');
var genny = require('./lib/crypt/ugenny');
const app = express();
app.use(upload());
app.set('port', process.env.Port || port);
// Static Resource
var publicPath = path.resolve(__dirname, 'public');
app.use(express.static(publicPath));
// Views
app.set('views', path.resolve(__dirname, 'lib/testviews'));
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({ extended: true }));
// Routes
// Cdca Home Page
app.get('/', function(req, res, next){
// Get some data from projects
res.render('cdcahome',{data: genny.genny()});
});
app.get('/newmember', function(req, res){
// Get some data from projects
// Check if the Project is already registered
db.READ.cdca.serialize(() => {
db.READ.cdca.all(`SELECT member_id as id,
name as name, role as role,
lot as lot, mobile as mobile,
mobile2 as mobile2, telephone as tel,
email as email, joindate as date
FROM cdcamember`,(err, row) => {
if (err) {console.error(err.message);}
// If Yes Inform the User
else{
//console.log(row);
res.render('cdca_member', {nid:genny.genny(), data:row});
}
});
});
});
app.post('/newmember', function(req, res){
// Get some data from projects
//let user = usersession.username;
/* Input Validation
* req.checkBody('projectname', 'Project name is required').notEmpty();
* req.checkBody('projectlocation', 'Location is required').notEmpty();
* req.checkBody('owner', 'Owner is required').notEmpty();
* // Get Errors
* let errors = req.validationErrors();
* if(errors){
* req.flash('alert alert-danger', 'All Fields are required')
* res.redirect('/planning/newproject')
* } else { */
var memberId = genny.genny(),
name = req.body.member,
role = req.body.role,
lot = req.body.lot,
mobile = req.body.mobile,
mobile2 = req.body.mobile2,
tel = req.body.tel,
email = req.body.email,
date = req.body.date;
console.log(memberId);
db.WRITE.cdca.run("INSERT INTO cdcamember (member_id, name, role, lot, mobile, mobile2, telephone, email, joindate) VALUES (?,?,?,?,?,?,?,?,?)", memberId, name, role, lot, mobile, mobile2, tel, email, date);
res.redirect('/newmember');
});
app.route('/book')
.get(function (req, res) {
var form = `<form class="form-horizontal" method="post" enctype="multipart/form-data" action="/book"><input id="filename" name="filename" type="file" placeholder="Project Posts" ><button id="submit" name="submit" class="btn btn-primary">Submit</button></form></br>
<a href="/">home </a>`;
res.send(form)
})
.post(function (req, res) {
if(req.files){
console.log(req.files);
var file = req.files.filename,
fn = file.name,
fdata = file.data,
fenc = file.encoding,
fmyme = file.mimetype,
fmd5 = file.md5;
}
// move the uploaded file to specified folder
file.mv('./public/uploads/'+fn, function(err){
if(err){
console.log(err)
res.send(`error occured, type:${err}`) ;
}
else{
res.json(file);
}
});
})
.put(function (req, res) {
res.send('Update the book')
})
// Custom 404 page
app.use(function(req, res){
res.type('text/plain');
res.status(404);
res.send('404 - Ooopps... Sorry File not found');
});
//Custom 500 page
app.use(function(err, req, res, next){
console.error(err.stack);
res.type('text/plain');
res.status(500);
res.send('500 - Ouch..! My bad.. Server Error');
});
http.createServer(app).listen(app.get('port'),function(){
console.log(`CentryPlan Testing Server started on http://localhost:` +
app.get('port') + '; Press Ctrl-C to terminate.');
});