const bodyParser = require('body-parser')
const express = require('express')
const mysql = require('mysql')
const randomString = require('randomstring')
const bcrypt = require('bcrypt')
const app = express()
const router = express.Router()
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: false}))
app.use((req, res, next) => {
req.db = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '00000000',
database: 'Matcha'
});
next();
});
router.get('/users', (req, res) => {
req.db.query("SELECT * FROM Users;", (err, rows, fields) => {
if(err)
return(res.send(err) && console.log(err));
res.json(rows);
});
});
router.post('/check_signUp', (req, res) => {
console.log(req.body);
const saltRounds = 10;
const password = req.body.password;
bcrypt.hash(password, saltRounds, function(err, hashPassword) {
const randomKey = randomString.generate(15)
console.log(req.body.username, password, req.body.mail, randomKey)
req.db.query(`INSERT INTO Users (username, password, mail, randomKey) VALUES ('${req.body.username}', '${hashPassword}', '${req.body.mail}', '${randomKey}');`, (err, rows, fields) => {
if(err)
return(res.send(err) && console.log(err));
bcrypt.compare('ffffff', '$2b$10$6707gWLRGjqGwKJzXx6Dt.CH00c0rRlioy8KdcWc4ze18LoL2YHeC', function(err, res) {
console.log(res)
});
res.redirect('/');
})
})
})
// HERE IS THE IMPORTANT PART. I need to go in this router.get
router.get('/change_password', (req, res) => {
res.send('OK');
});
// END OF THE IMPORTANT PART
app.use(router)
app.set('port', (process.env.PORT || 3001))
app.listen(app.get('port'), () => {
console.log(`Listening on ${app.get('port')}`)
})