Skip to content

Commit 5eed983

Browse files
committed
5/30/2020
1 parent 73e5743 commit 5eed983

File tree

12 files changed

+749
-78
lines changed

12 files changed

+749
-78
lines changed

Diff for: .gitignore

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
node_modules
2+
install_tools.bat
3+
nodemon.ps1*
4+
sshkey
5+
CHANGELOG.md
6+
LICENSE
7+
nodevars.bat
8+
sshkey.pub
9+
node.exe*
10+
npm*
11+
sshkey.txt
12+
node_etw_provider.man
13+
npm.cmd
14+
ejs*
15+
npx*
16+
ejs.cmd
17+
nodemon*
18+
npx.cmd
19+
ejs.ps1*
20+
nodemon.cmd
21+

Diff for: README.md

+608
Large diffs are not rendered by default.

Diff for: addmie/css/gaurav.css

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
.containers {
1+
.containerss {
22
box-shadow: 0px 4px 15px 0 rgba(0, 0, 0, 0.2), 0 5px 20px 0 rgba(0, 0, 0, 0.3);
33
float: left;
4-
margin: 50px 50px;
4+
margin: 50px;
5+
margin-left: 190px;
56
}
67

78
.float-right{
89
float: right;
9-
box-shadow: 0px 4px 15px 0 rgba(0, 0, 0, 0.2), 0 5px 18px 0 rgba(0, 0, 0, 0.3);
10+
box-shadow: 0px 4px 15px 0 rgba(0, 0, 0, 0.2), 0 5px 20px 0 rgba(0, 0, 0, 0.3);
1011
position: relative;
11-
margin-top: 50px;
12-
margin-right: 250px;
12+
margin: 50px;
13+
margin-left: 200px;
1314
}
1415
.center {
1516
text-align: center;
1617
padding: 5px;
1718
box-shadow: 0px 4px 15px 0 rgba(0, 0, 0, 0.2);
18-
color: red;
19+
color: #00b9ed;
1920
font-size: 15px;
2021
}
21-
.gaurav {
22+
.form-inside {
2223
padding: 20px;
2324
font-size: 15px;
2425
}
25-
.gaurav input[type=text], input[type=submit] {
26+
.form-inside input[type=text], input[type=submit] {
2627
width: 100%;
2728
padding: 12px;
2829
margin: 6px 0;
29-
display: inline-block;
3030
border: 1px solid #ccc;
3131
box-sizing: border-box;
3232
}
@@ -36,14 +36,17 @@ font-size: 15px;
3636
}
3737
.float-right {
3838
float: left;
39-
margin-right:auto;
40-
margin-left: 50px;
39+
margin-right:40px;
40+
margin-left: 40px;
4141
margin-top: 20px;
4242
}
43+
.containerss {
44+
margin: 50px 40px;
45+
}
4346
}
44-
.gaurav input[type=submit]:hover {
47+
.form-inside input[type=submit]:hover {
4548
background-color: lightblue;
46-
color: red;
49+
color: #00b9ed;
4750
font-size: 15px;
4851
box-shadow: 5px 2px 10px black;
4952
}

Diff for: addmie/css/styles.css

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
font-family: Arial, Helvetica, sans-serif;
33
padding: 0;
44
margin: 0;
5-
/* background-color: #010101 ; */
6-
color: white;
5+
76
font-size: 12px;
87

98
}

Diff for: controllers/controler.js

+31-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
let path=require('path');
22
let bodyparserencoder=require('body-parser');
3-
//adding session
4-
3+
//connecting to db client
4+
let dbconnect=require('../dbconnect/connect');
5+
const MongoClient=dbconnect.MongoClient;
6+
const uri=dbconnect.uri;
7+
const client=dbconnect.client;
8+
dbconnect.main(client);
9+
//adding session authentication
10+
const loginauth=(req,res,next)=>{
11+
if(req.session.loggedIn){
12+
next();
13+
}
14+
else{
15+
res.redirect('/');
16+
console.log('looks like youve been logged out of the session login to continue');
17+
}
18+
};
519
bodyparserencoder = bodyparserencoder.urlencoded({ extended: false })
620
module.exports=function(app){
721
app.get('/',function(req,res){
@@ -12,18 +26,18 @@ module.exports=function(app){
1226
app.post('/login',bodyparserencoder,function(req,res){
1327
console.log('login requested');
1428
let query=require('../'+'dbconnect/'+'login.js');
15-
let exists=query.login({username:req.body.Username,password:req.body.Password},res,req);
29+
let exists=query.login({username:req.body.User,password:req.body.Pass},res,req,client);
1630
//console.log('everything done, exists= ' + exists);
1731
req.session.loggedIn=true;
18-
console.log(req.session);
32+
//console.log(req.session);
1933
});
2034
//request handling when signup is requested
2135
app.post('/signup',bodyparserencoder,function(req,res){
2236
console.log('signup requested');
2337
//if validated sucessfully then fire insert query in database
2438
let query=require('../'+'dbconnect/'+'newsignin.js');
2539
//console.log(req.body);
26-
query(req.body.Username,req.body.Password,req.body.Fname,req.body.Lname,req.body.DOB,req.body.Email);
40+
query(req.body.Username,req.body.Password,req.body.Fname,req.body.Lname,req.body.DOB,req.body.Email,client);
2741
//window.alert('signed up successfully ,now you can login');
2842
//now logging in
2943
query=require('../'+'dbconnect/'+'login.js');
@@ -34,30 +48,34 @@ module.exports=function(app){
3448
/////////////////////////////////////////////// session pages ////////////////////////////////////////
3549
//request handling when logout is requested
3650
app.get('/logout',function(req,res){
37-
console.log(req.session);
51+
//console.log(req.session);
3852
if(req.session.loggedIn){
39-
console.log('logout requested');
40-
res.render('Addmie.ejs');}
53+
req.session.destroy();
54+
}
4155
else{
42-
console.log('login to continue');
56+
//console.log('login to continue');
4357
}
58+
res.redirect('/');
59+
4460
});
4561
//request handling when user posts
46-
app.post('/sendpost/:username',bodyparserencoder,function(req,res){
62+
app.post('/sendpost/:username',bodyparserencoder,loginauth,function(req,res){
4763
console.log('post has been recived');
4864
var query=require('../dbconnect/insertpost');
49-
query(req);
65+
query(req,client);
5066
res.redirect('/profile/'+req.params.username);
5167
});
52-
app.get('/profile/:username',function(req,res){
68+
app.get('/profile/:username',loginauth,function(req,res){
5369
console.log('get request to profile');
5470
var userobj={
5571
username:req.params.username,
5672
};
5773
let fetch=require('../dbconnect/fetch.js');
5874
const fname=null;
59-
fetch(req.params.username,res);
75+
fetch(req.params.username,res,client);
6076
console.log('profile loaded');
6177

6278
});
79+
console.log('closing connection to db');
80+
client.close();
6381
}

Diff for: dbconnect/connect.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
/* JZf111qVS2zqKVfs */
2-
/* async function listDatabases(client){
2+
async function listDatabases(client){
33
databasesList = await client.db().admin().listDatabases();
44

55
console.log("Databases:");
66
databasesList.databases.forEach(db => console.log(` - ${db.name}`));
77
};
8-
9-
module.exports=async function main(){
108
const MongoClient = require('mongodb').MongoClient;
119
const uri = "mongodb+srv://dbuser:[email protected]/test?retryWrites=true&w=majority";
1210
const client = new MongoClient(uri, {useUnifiedTopology:true});
11+
module.exports.MongoClient = MongoClient;
12+
module.exports.uri=uri;
13+
module.exports.client=client;
14+
module.exports.main=async function main(client){
1315
try {
1416
// Connect to the MongoDB cluster
1517
await client.connect();
@@ -20,7 +22,7 @@ const client = new MongoClient(uri, {useUnifiedTopology:true});
2022
} catch (e) {
2123
console.error(e);
2224
} finally {
23-
await client.close();
25+
console.log('beware the client is still loggeed in the db');
26+
//await client.close();
2427
}
2528
};
26-
*/

Diff for: dbconnect/fetch.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
const MongoClient = require('mongodb').MongoClient;
2-
const uri = "mongodb+srv://dbuser:[email protected]/test?retryWrites=true&w=majority";
3-
const client = new MongoClient(uri, {useUnifiedTopology:true});
1+
42
var result=null;
53
var posts=null;
6-
module.exports = async function dbconnect(from,res)
4+
module.exports = async function dbconnect(from,res,client)
75
{
86
try {
97
// Connect to the MongoDB cluster
10-
await client.connect();
8+
//await client.connect();
119
console.log('client connected sucessfully');
1210
// Make the appropriate DB calls
1311
result=await client.db('profile').collection('user').findOne({username:from});
@@ -20,7 +18,7 @@ module.exports = async function dbconnect(from,res)
2018
await res.render('addmie.ejs')
2119
} finally {
2220
console.log('closing client connection');
23-
await client.close();
21+
//await client.close();
2422
console.log(posts);
2523
await res.render('profile.ejs',{userobj:result,postobj:posts});
2624
}

Diff for: dbconnect/insertpost.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
const MongoClient = require('mongodb').MongoClient;
2-
const uri = "mongodb+srv://dbuser:[email protected]/test?retryWrites=true&w=majority";
3-
const client = new MongoClient(uri, {useUnifiedTopology:true});
41
var result=null;
5-
module.exports = async function dbconnect(req)
2+
module.exports = async function dbconnect(req,client)
63
{ console.log(req.body.text);
74
console.log(req.params.username);
85
let today = new Date();
@@ -18,8 +15,8 @@ module.exports = async function dbconnect(req)
1815
};
1916
try {
2017
// Connect to the MongoDB cluster
21-
await client.connect();
22-
console.log('client connected sucessfully');
18+
//await client.connect();
19+
//console.log('client connected sucessfully');
2320
// Make the appropriate DB calls
2421
result=await client.db('profile').collection('post').insertOne(postobj);
2522
//console.log(result);
@@ -30,7 +27,7 @@ module.exports = async function dbconnect(req)
3027

3128
} finally {
3229
console.log('closing client connection');
33-
await client.close();
30+
//await client.close();
3431

3532
}
3633

Diff for: dbconnect/login.js

+7-15
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@ var result=null;
33
async function fetchuser(client,userobj){
44
console.log('finding',userobj);
55
result=await client.db('profile').collection('user').findOne(userobj);
6-
if(result){console.log('user found'+result.username);exists=true;}
6+
if(result){console.log('user found '+result.username);exists=true;}
77
else{console.log('invalid username or password');}
88

99
};
10-
module.exports.login=async function main(userobj,res,req){
11-
const MongoClient = require('mongodb').MongoClient;
12-
const uri = "mongodb+srv://dbuser:[email protected]/test?retryWrites=true&w=majority";
13-
const client = new MongoClient(uri, {useUnifiedTopology:true});
10+
module.exports.login=async function main(userobj,res,req,client){
11+
1412
try {
1513
// Connect to the MongoDB cluster
16-
await client.connect();
14+
//await client.connect();
1715
console.log('client connected sucessfully');
1816
// Make the appropriate DB calls
1917
await fetchuser(client,userobj);
@@ -26,24 +24,18 @@ module.exports.login=async function main(userobj,res,req){
2624
} catch (e) {
2725
console.error(e);
2826
} finally {
29-
await client.close();
27+
//await client.close();
3028
}
3129
if(exists){
3230
console.log(exists);
3331
req.session.username=result.username;
3432
console.log('loggin in account of'+result.username);
3533
res.redirect('/profile/'+result.username);
36-
while(true){
37-
console.log(req.session.username);
38-
if(req.session.username){
39-
console.log('session variable created');
40-
break;
41-
}
42-
}
34+
4335
}
4436
else{
4537
console.log('invalid userid or password');
4638
//window.alert('ivalid username or password');
47-
res.render('Addmie.ejs');
39+
res.redirect('/');
4840
}
4941
}

Diff for: dbconnect/newsignin.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ async function adduser(client,userobj){
44
// console.log(result);
55

66
};
7-
module.exports=async function main(username,password,fname,lname,dob,email){
7+
module.exports=async function main(username,password,fname,lname,dob,email,client){
88
let today = new Date();
99
let dd = String(today.getDate()).padStart(2, '0');
1010
let mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
@@ -20,19 +20,16 @@ module.exports=async function main(username,password,fname,lname,dob,email){
2020
active:0,
2121
friends: ['m416','akm']
2222
};
23-
const MongoClient = require('mongodb').MongoClient;
24-
const uri = "mongodb+srv://dbuser:[email protected]/test?retryWrites=true&w=majority";
25-
const client = new MongoClient(uri, {useUnifiedTopology:true});
2623
try {
2724
// Connect to the MongoDB cluster
28-
await client.connect();
25+
//await client.connect();
2926
console.log('client connected sucessfully');
3027
// Make the appropriate DB calls
3128
await adduser(client,userobj);
3229
} catch (e) {
3330
console.log('error connecting to db');
3431
console.error(e);
3532
} finally {
36-
await client.close();
33+
//await client.close();
3734
}
3835
}

Diff for: npx

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
(set -o igncr) 2>/dev/null && set -o igncr; # cygwin encoding fix
3+
4+
basedir=`dirname "$0"`
5+
6+
case `uname` in
7+
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
8+
esac
9+
10+
NODE_EXE="$basedir/node.exe"
11+
if ! [ -x "$NODE_EXE" ]; then
12+
NODE_EXE=node
13+
fi
14+
15+
NPM_CLI_JS="$basedir/node_modules/npm/bin/npm-cli.js"
16+
NPX_CLI_JS="$basedir/node_modules/npm/bin/npx-cli.js"
17+
18+
case `uname` in
19+
*MINGW*)
20+
NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
21+
NPM_PREFIX_NPX_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npx-cli.js"
22+
if [ -f "$NPM_PREFIX_NPX_CLI_JS" ]; then
23+
NPX_CLI_JS="$NPM_PREFIX_NPX_CLI_JS"
24+
fi
25+
;;
26+
*CYGWIN*)
27+
NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
28+
NPM_PREFIX_NPX_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npx-cli.js"
29+
if [ -f "$NPM_PREFIX_NPX_CLI_JS" ]; then
30+
NPX_CLI_JS="$NPM_PREFIX_NPX_CLI_JS"
31+
fi
32+
;;
33+
esac
34+
35+
"$NODE_EXE" "$NPX_CLI_JS" "$@"

0 commit comments

Comments
 (0)