email.js
1.42 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var express = require('express')
var app = express()
var mysql = require('mysql')
var router = express.Router();
var path = require('path')
var connection = mysql.createConnection({
host : 'localhost',
port : 3306,
user:'root',
password : 'ksmhjh88',
database : 'nodetest'
})
connection.connect()
router.post('/form', function (req, res) {
//get : req.param('email')
//console.log(req.body.email)
//res.send("<h1>Welcome!</h1>" + req.body.email)
res.render('email.ejs',{'email' : req.body.email ,'password' : req.body.password})
})
router.post('/ajax',function(req,res) {
console.log(req.body.email)
console.log(req.body.password)
var email = req.body.email
var password = req.body.password
//var responseData = {'result' : 'ok' , 'email' : req.body.email};
//res.json(responseData)
//DB 처리
var responseData = {};
var query = connection.query('select name from user where email="' + email + '"' + ' and password="' + password + '"' , function(err,rows) {
if(err) throw err;
if(rows[0]) {
console.log(rows[0]);
responseData.result = "ok";
responseData.name = rows[0].name;
}
else {
responseData.result = "none";
responseData.name = "";
console.log('none : ' + rows[0])
}
res.json(responseData)
})
})
module.exports = router;