Skip to content

Commit

Permalink
node js login is added
Browse files Browse the repository at this point in the history
  • Loading branch information
Meghraj Deshmukh authored and Meghraj Deshmukh committed Apr 20, 2020
1 parent 2afd40f commit 72b2b91
Show file tree
Hide file tree
Showing 22 changed files with 1,769 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
19 changes: 19 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const Express=require('express');
var router=require('./router/register');
var path=require('path');
var bodyParser = require('body-parser')
var mongoose=require('./config/mongoose');

const app=Express();
//app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));

app.use(Express.static(path.join(__dirname, 'asset')));

app.use('/', router);

app.listen(2000, function(err){

console.log("server starts on"+2000);

});
7 changes: 7 additions & 0 deletions loginStyel.css → asset/Css/loginStyel.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,12 @@



}

.form-group{

display: flex;
color: black;

}

8 changes: 4 additions & 4 deletions register.html → asset/Css/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="loginStyel.css">
<link rel="stylesheet" href="/Css/loginStyel.css">
</head>


Expand All @@ -24,7 +24,7 @@
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">
<img src="./logo.png" style="max-width: 100%; max-height:100%;">
<img src="/images/logo.png" style="max-width: 100%; max-height:100%;">
</img>
</a>
</div>
Expand All @@ -47,9 +47,9 @@


<div class="Register">
<form action="/action_page.php" class="was-validated">
<form action="/registerUser" class="was-validated" method="POST">
<div class="form-group">
<label for="uname">Name:</label>
<label for="uname">Name</label>
<input type="text" class="form-control" id="uname" placeholder="Enter username" name="uname" required>

</div>
Expand Down
File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion style.css → asset/Css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

width: 30% !important;
height: 100px !important;
background: url('./btn2.png') no-repeat;
background: url('/images/btn2.png') no-repeat;
color: rgb(250, 59, 11);
font-size: xx-large;
font-weight: bolder;
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
15 changes: 15 additions & 0 deletions config/mongoose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

const mongoose=require('mongoose');

mongoose.connect(`mongodb://localhost/DonateCovid`);

const db=mongoose.connection;

db.on('error',console.error.bind(console,'error in connecting to Mongodb'));

db.once('open',function(){
console.log('Connected to Database:: Mongodb');
});
module.exports=db;


67 changes: 67 additions & 0 deletions controller/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const user=require('../model/user');

module.exports.register=function(req, res)
{

console.log("on the page of registration");
console.log(req.body);

user.create({

name:req.body.uname,
phone:req.body.phone,
email:req.body.email,
password:req.body.pswd



}, function(error, user){

if(error)
{
console.log("cannot create user"+error);
res.send(error);

}else{

console.log(user+"Created");
res.redirect('/userlogin');

}

})
//res.send("error");



}

module.exports.login=function(req,res)
{



user.find(email=req.body.email, function(err, user){

if(err)
{
res.send(err);

}
console.log(user);

if(user.password==req.body.password)
{
res.redirect('/');
}else{
res.send("password doesnt match");

}


})




}
35 changes: 35 additions & 0 deletions model/Admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

const mongoose=require('mongoose');



//const schema={name:{type:String}}
const adminSchema=mongoose.Schema({

name:{
type:String,
require:true,
},

email:{
type:String,
require:true,
unique:true,
},

phone:{
type:String,


},
password:{
type:String,
require:true,

}

});


const Admin=mongoose.model('Admin',adminSchema);
module.exports=Admin;
35 changes: 35 additions & 0 deletions model/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

const mongoose=require('mongoose');



//const schema={name:{type:String}}
const userSchema=mongoose.Schema({

name:{
type:String,
require:true,
},

email:{
type:String,
require:true,
unique:true,
},

phone:{
type:String,


},
password:{
type:String,
require:true,

}

});


const User=mongoose.model('User',userSchema);
module.exports=User;
Loading

0 comments on commit 72b2b91

Please sign in to comment.