-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
81 lines (77 loc) · 2.47 KB
/
app.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
const express = require("express");
const bodyParser=require("body-parser");
const mongo = require('mongodb');
const app=express();
app.use(bodyParser.urlencoded({ extended: true }));
app.get("/",function(req,res){
res.sendFile(__dirname+"/index.html")
});
app.get("/Login",function(req,res){
res.sendFile(__dirname+"/Login.html")
});
app.get("/Register",function(req,res){
res.sendFile(__dirname+"/Register.html")
});
app.post("/register",function(req,res){
console.log(req.body);
var emailID=req.body.email;
var password=req.body.password;
var name=req.body.name;
var age=req.body.age;
var number=req.body.number
var MongoClient=require('mongodb').MongoClient
var url= "mongodb://127.0.0.1:27017/";
MongoClient.connect(url,function(err,db){
if(err) throw err;
var dbo=db.db("Users");
dbo.collection("Details").findOne({"email":emailID},function(err,result){
if (err) throw err;
if(result==null){
dbo.collection("Details").insert({
"name":name,
"email":emailID,
"password":password,
"age":age,
"number":number
},function(err,result){
if (err) throw err;
});
res.send("Registered Succesfully!");
}
else{
res.send(emailID+" is already in use!");
}
console.log(result);
});
//db.close();
});
});
app.post("/login",function(req,res){
console.log(req.body);
//res.send("Log in Succesfull!");
var emailID=req.body.email;
var password=req.body.password;
var MongoClient=require('mongodb').MongoClient
var url= "mongodb://127.0.0.1:27017/";
MongoClient.connect(url,function(err,db){
if(err) throw err;
var dbo=db.db("Users");
dbo.collection("Details").findOne({"email":emailID},function(err,result){
if (err) throw err;
if(result==null){
res.send("Invalid Username or Password!");
}
else if(result.password==password){
res.send("Logged In succesfully. Hello"+result.name);
}
else {
res.send("Invalid Password or Username");
}
console.log(result);
});
//db.close();
});
});
app.listen(3000,function(req,res){
console.log("Running on 3000");
});