TVJR/controllers/register-controller.js

24 lines
789 B
JavaScript
Executable File

// /http://www.expertphp.in/article/user-login-and-registration-using-nodejs-and-mysql-with-example
var connection = require('./../bdd');
var passwordProtection = require('./securepw');
module.exports=function(req,res, next){
var today = new Date();
var users={
"name":req.body.username,
"pw": passwordProtection(req.body.password)
}
connection.query('INSERT INTO user SET ?',users, function (error, results, fields) {
if (error) {
//res.local.stat = 0;
res.locals.message='there are some error with query'+error;
next();
}else{
//res.loacal.stat = 1;
res.locals.data = results;
res.locals.message = 'user registered sucessfully';
next();
}
});
}