register.js
1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var express = require('express');
var request = require('request');
var async = require('async');
var cryptoM = require('./../../routes/modules/cryptoM.js');
var router = express.Router();
router.get('/', function(req, res, next) {
// res.render('userlogin/register',{
// msg: "register"
// });
});
router.post('/', function(req, res, next) {
console.log(req.body);
var user_id=req.body.user_id;
var user_pw=req.body.user_pw;
var user_email=req.body.user_email;
var user_name=req.body.user_name;
// var user_phone=req.body.user_phone;
var sqlquery = "SELECT * FROM users WHERE user_id = ?";
connection.query(sqlquery, [user_id], function (err, rows) {
if (rows.length == 0) {
user_pw=cryptoM.encrypt(user_pw);
console.log(user_pw);
var sql = 'INSERT INTO users(user_id,user_pw, user_email, user_name) values (?,?,?,?)';
var values = [user_id, user_pw, user_email, user_name];
connection.query(sql, values, function (err) {
if (err) {
console.log("inserting user failed");
throw err;
} else {
res.redirect('/login');
}
});
} else {
res.redirect("/login");
throw err;
}
});
});
module.exports = router;