-
Notifications
You must be signed in to change notification settings - Fork 0
/
old js.txt
80 lines (68 loc) · 2.05 KB
/
old js.txt
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
var express = require('express')
var bodyParser = require('body-parser')
var mongoose = require('mongoose')
var multer = require('multer')
var storage = multer.diskStorage({
destination: function(req, file, cb) {
cb(null, './uploads');
},
filename: function (req, file, cb) {
cb(null , file.originalname);
}
});
var upload = multer({ storage:storage })
const app = express()
app.use(bodyParser.json())
app.use(express.urlencoded({extended:false}));
app.use(express.static('public'))
app.use(bodyParser.urlencoded({ extended: true }))
mongoose.connect('mongodb://Localhost:27017/Regis',{
useNewUrlParser: true,
useUnifiedTopology: true
});
var db = mongoose.connection;
db.on('error',()=>console.log("Error in connecting to Mongo"));
db.once('open',()=>console.log("Connected to database"));
app.post("/signup", upload.single('avatar') ,(req, res, cb) => {
// console.log(req.file);
console.log(req.body.number);
var firstName = req.body.first;
var lastName = req.body.last;
var username = req.body.username;
var password = req.body.password;
var number = req.body.number;
var data = {
"firstname": firstName,
"lastname": lastName,
"username": username,
"password": password,
"number": number
}
console.log(data);
db.collection('Users').insertOne(data,(err,collection)=>{
if(err) {
throw err;
}
console.log("Record inserted successfully");
});
return res.redirect('finish.html')
})
app.get('/regis',(req, res)=>{
console.log("Going to regis page");
res.redirect('regis.html');
});
app.get('/login',(req, res)=>{
console.log("Going to login page");
res.redirect('login.html');
});
app.get('/logind',(req, res)=>{
console.log("Going to logind page");
res.redirect('dash.html');
});
app.get("/",(req,res) => {
res.set({
"Allow-access-Allow-Origin": '*'
})
return res.redirect('login.html')
}).listen(3000);
console.log("listening");