email.js 1.42 KB

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;