Skip to content

Commit bccaa85

Browse files
committed
Day 13 sign up form using node.js express.js mongodb
1 parent d5b4947 commit bccaa85

30 files changed

Lines changed: 527 additions & 0 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var express = require('express');
2+
var fs = require('fs')
3+
4+
var app = express()
5+
6+
app.get('/', function (req, res) {
7+
res.send('Simple Example of routes!');
8+
})
9+
10+
app.get('/signup', function(req,res){
11+
// this is how we will receive params from front end
12+
13+
var name = req.query.name;
14+
var email = req.query.email;
15+
var password = req.query.password;
16+
//For demo purpose
17+
console.log(name + '' + email + ' ' + password);
18+
19+
/**
20+
* Store this in a database and perform further processing
21+
*/
22+
res.send("In signup module")
23+
});
24+
25+
app.listen(3000, function () {
26+
console.log('Server is listening at 3000')
27+
})
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var express = require('express')
2+
var app = express()
3+
4+
app.get('/', function (req, res) {
5+
res.send('Simple Example of routes!');
6+
})
7+
8+
app.get('/signup', function (req, res) {
9+
res.send('This is demo route for sign up');
10+
})
11+
12+
app.get('/signin', function (req, res) {
13+
res.send('This is demo route for sign in');
14+
})
15+
16+
17+
18+
app.get('/signin/dashboard', function (req, res) {
19+
res.send('This is demo route for user who signed in and now reaches their dashboard');
20+
})
21+
22+
23+
app.listen(3000, function () {
24+
console.log('Server is listening at 3000')
25+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var express = require('express')
2+
var app = express()
3+
4+
app.get('/', function (req, res) {
5+
res.send('Hello World!')
6+
})
7+
app.listen(3000, function () {
8+
console.log('Server is listening at 3000')
9+
})

day13-signup-form/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "nj-signup",
3+
"version": "1.0.0",
4+
"description": "Sign up using node, express and mongo",
5+
"main": "serve.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"start": "node server.js"
9+
},
10+
"author": "@rajatgarian",
11+
"license": "ISC",
12+
"dependencies": {
13+
"express": "^4.16.1",
14+
"mongodb": "^2.2.30"
15+
}
16+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<html>
2+
<head>
3+
<title> Signup Form | nodejsera </title>
4+
5+
<!-- Including bootstrap v3.3.7 -->
6+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
7+
8+
<!-- Including Custom css -->
9+
<link rel="stylesheet" type="text/css" href="style.css">
10+
11+
</head>
12+
<body>
13+
14+
<br>
15+
<br>
16+
<br>
17+
<div class="container" >
18+
<div class="row">
19+
<div class="col-md-3">
20+
<!-- Blank DIV -->
21+
</div>
22+
23+
<div class="col-md-6 main">
24+
<!-- Form Tag starts here -->
25+
<!-- Action attribute is the route on backend. Method is POST -->
26+
<form action="/sign_up" method="post">
27+
28+
<h1> Signup form </h1>
29+
30+
<input class="box" type="text" name="name" id="name" placeholder="Enter your Name" required /><br>
31+
32+
<input class="box" type="email" name="email" id="email" placeholder="Enter your E-Mail " required /><br>
33+
34+
<input class="box" type="password" name="password" id="password" placeholder="Enter your Password " required/><br>
35+
36+
<input class="box" type="text" name="phone" id="phone" placeholder="Enter your Phone Number " required/><br>
37+
<br>
38+
<input type="submit" id="submitDetails" name="submitDetails" value="Submit Your Details" /><br>
39+
40+
</form>
41+
42+
</div>
43+
44+
45+
<div class="col-md-3">
46+
<!-- Blank DIV -->
47+
</div>
48+
49+
</div>
50+
</div>
51+
</body>
52+
</html>

day13-signup-form/public/style.css

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
@import url('https://fonts.googleapis.com/css?family=Josefin+Slab');
2+
3+
.main{
4+
padding:20px;
5+
font-family: 'Josefin Slab', serif;
6+
border : 2px solid #50d8a4;
7+
border-radius: 15px;
8+
9+
}
10+
.main h1{
11+
font-size: 50px;
12+
text-align:center;
13+
font-family: 'Josefin Slab', serif;
14+
color: #549978;
15+
}
16+
input{
17+
font-family: 'Josefin Slab', serif;
18+
width: 100%;
19+
font-size: 30px;
20+
padding: 12px 20px;
21+
margin: 8px 0;
22+
border: none;
23+
border-bottom: 2px solid #50d8a4;
24+
}
25+
input[type=submit] {
26+
font-family: 'Josefin Slab', serif;
27+
width: 100%;
28+
background-color: #549978;
29+
border: none;
30+
color: white;
31+
padding: 16px 32px;
32+
text-decoration: none;
33+
margin: 4px 2px;
34+
cursor: pointer;
35+
border-radius: 15px;
36+
}
37+
input:focus,
38+
select:focus,
39+
textarea:focus,
40+
button:focus {
41+
outline: none;
42+
}
43+
44+
input:hover {
45+
font-family: 'Josefin Slab', serif;
46+
width: 100%;
47+
padding: 12px 20px;
48+
margin: 8px 0;
49+
box-sizing: border-box;
50+
border: none;
51+
border-bottom: 2px solid #549978;
52+
}
53+
54+
input[type=submit]:hover {
55+
font-family: 'Josefin Slab', serif;
56+
width: 100%;
57+
background-color: #549978;
58+
border: none;
59+
color: white;
60+
padding: 16px 32px;
61+
text-decoration: none;
62+
margin: 4px 2px;
63+
cursor: pointer;
64+
border-radius: 15px;
65+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<html>
2+
<head>
3+
<title> Signup Form | nodejsera </title>
4+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
5+
6+
<link rel="stylesheet" type="text/css" href="style.css">
7+
</head>
8+
<body>
9+
<br>
10+
<br>
11+
<br>
12+
<div class="container" >
13+
<div class="row">
14+
<div class="col-md-3">
15+
</div>
16+
17+
<div class="col-md-6 main">
18+
19+
<h1> Signup Successful <br> Congratulations!!</h1>
20+
21+
</div>
22+
23+
24+
<div class="col-md-3">
25+
</div>
26+
27+
</div>
28+
</div>
29+
</body>
30+
</html>

day13-signup-form/server.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
var express = require('express');
2+
var path = require('path');
3+
var fs = require('fs');
4+
var app = express();
5+
var mongo = require('mongodb');
6+
var new_db = "mongodb://localhost:27017/agfgf";
7+
var bodyParser = require('body-parser');
8+
var crypto = require('crypto');
9+
//Creating the database
10+
11+
app.get('/',function(req,res){
12+
res.set({
13+
'Access-Control-Allow-Origin' : '*'
14+
});
15+
return res.redirect('/public/index.html');
16+
}).listen(3000);
17+
18+
console.log("Server listening at : 3000");
19+
app.use('/public', express.static(__dirname + '/public'));
20+
app.use( bodyParser.json() );
21+
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
22+
extended: true
23+
}));
24+
25+
var getHash = ( pass , phone ) => {
26+
27+
var hmac = crypto.createHmac('sha512', phone);
28+
29+
//passing the data to be hashed
30+
data = hmac.update(pass);
31+
//Creating the hmac in the required format
32+
gen_hmac= data.digest('hex');
33+
//Printing the output on the console
34+
console.log("hmac : " + gen_hmac);
35+
return gen_hmac;
36+
}
37+
38+
// Sign-up function starts here. . .
39+
app.post('/sign_up' ,function(req,res){
40+
var name = req.body.name;
41+
var email= req.body.email;
42+
var pass = req.body.password;
43+
var phone = req.body.phone;
44+
var password = getHash( pass , phone );
45+
46+
47+
var data = {
48+
"name":name,
49+
"email":email,
50+
"password": password,
51+
"phone" : phone
52+
}
53+
54+
mongo.connect(new_db , function(error , db){
55+
if (error){
56+
throw error;
57+
}
58+
console.log("connected to database successfully");
59+
//CREATING A COLLECTION IN MONGODB USING NODE.JS
60+
db.collection("details").insertOne(data, (err , collection) => {
61+
if(err) throw err;
62+
console.log("Record inserted successfully");
63+
console.log(collection);
64+
});
65+
});
66+
67+
console.log("DATA is " + JSON.stringify(data) );
68+
res.set({
69+
'Access-Control-Allow-Origin' : '*'
70+
});
71+
return res.redirect('/public/success.html');
72+
73+
/**
74+
var filePath = path.join(__dirname, 'public/success.html');
75+
var stat = fs.statSync(filePath);
76+
77+
res.writeHead(200, {
78+
'Content-Type': 'text/html',
79+
'Content-Length': stat.size
80+
});
81+
82+
var readStream = fs.createReadStream(filePath);
83+
// We replaced all the event handlers with a simple call to readStream.pipe()
84+
readStream.pipe(res);
85+
*/
86+
87+
});
88+
89+
90+

day9-crypto-module/createCipher.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var crypto = require('crypto'),
2+
algorithm = 'aes-256-ctr',
3+
password = 'd6F3Efeq';
4+
5+
var cipher = crypto.createCipher(algorithm,password);
6+
//console.log(cipher);
7+
var crypted = cipher.update('1223234','utf8','hex');
8+
//console.log(crypted);
9+
crypted += cipher.final('hex');
10+
console.log(crypted);
11+
12+
function encrypt(text){
13+
var cipher = crypto.createCipher(algorithm,password)
14+
var crypted = cipher.update(text,'utf8','hex')
15+
crypted += cipher.final('hex');
16+
return crypted;
17+
}

0 commit comments

Comments
 (0)