javascript - Mongodb and nodejs validation form -


i new mongodb , nodejs well. want login validation data html page fed nodejs , checked existence , message sent html. how do it.

var express = require('express'); var bodyparser = require('body-parser'); var app = express();  //note in version 4 of express, express.bodyparser() //deprecated in favor of separate 'body-parser' module. app.use(bodyparser.urlencoded({     extended: true }));  //app.use(express.bodyparser());  app.listen(8080, function () {     console.log('server running @ http://127.0.0.1:8080/');     console.log('chut'); }); app.post('/appl', function (req, res) {     var emai = req.body.email;     var pas = req.body.key;        var mongoclient = require('mongodb').mongoclient,         format = require('util').format;      //connect away     mongoclient.connect('mongodb://127.0.0.1:27017/swapnil', function (err, db) { // change db name//         if (err) throw err;         console.log("connected database");          //simple json record         var document = {             emailid: emai,             password: pas         };          //insert record         db.collection('register').find(document, function (err, records) {             if (err) res.send('fail');             else res.send('pass');         });       }); }); 

this nodejs file.

html:

<form class="form-wrap" role="form" action="http://127.0.0.1:8080/appl" method="post" onsubmit="return vali()" id="login-form" autocomplete="off">     <div class="form-group">         <label for="email" class="sr-only">email</label>         <input type="email" name="email" id="email" class="form-control" placeholder="email id">     </div>     <div class="form-group">         <label for="key" class="sr-only">password</label>         <input type="password" name="key" id="key" class="form-control" placeholder="password">         <p class="req" id="vaa"></p>     </div> <a href="javascript:;" class="forget grey-text text-lighten-1" data-toggle="modal" data-target=".forget-modal" style="text-align:left;">forgot password?</a>      <input type=submit> <a id="new" href="#" class="forget grey-text text-lighten-1">new user? sign up</a>  </form> 

stackoverflow isn't place questions this, however:

the popular node authentication system passport.

here's tutorial passport mongoose.

also, don't save passwords in plain text or you'll end here.


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

php - Improving script execution time -

How to provide Authorization & Authentication using Asp.net, C#? -