27 lines
795 B
JavaScript
27 lines
795 B
JavaScript
require('mysql2')
|
|
|
|
let userInput = "test1"
|
|
|
|
let appRoot = require('app-root-path')
|
|
let dbConnect = require(appRoot + '/scripts/modules/db-connect.js')
|
|
|
|
dbConnect.query("SELECT is_active, name, passwd FROM webshop.user WHERE email = " + "'" + userInput + "'", async (err, result) => {
|
|
if (err)
|
|
console.log(err)
|
|
|
|
if(result.length > 0){
|
|
// tell user "email is already in use"
|
|
} else if (passwd !== passwd_confirm){
|
|
// tell user "passwords do not match"
|
|
}
|
|
let hashedPasswd = await bcrypt.hash(password, 8)
|
|
|
|
dbConnect.query('INSERT INTO user SET?', {name: name, email: email, passwd: hashedPasswd}, (err, res) => {
|
|
if(err)
|
|
console.log(err)
|
|
else{
|
|
// tell user "user registered"
|
|
}
|
|
})
|
|
})
|
|
dbConnect.end() |