我正在为带有nodeJS的服务器使用express开发一个网页。我在注册页面上,并且正在尝试验证用户插入的数据,但是当我进行查询时出现错误。
auth.js
const express = require('express');
const router = express.Router();
const { bd } = require('../database');
const help_functions = require('../lib/common');
router.post('/signup', async (req,res) => {
const fullname = req.body['fullname'];
const email = req.body['email'];
const username = req.body['username'];
const password = req.body['password'];
const password_repeat = req.body['password_repeat'];
var validation_msg = help_functions.validateSignUp(fullname, email, username, password, password_repeat);
validation_msg = await help_functions.checkRepeatedUserEmail(email);
});
数据库.js
const mysql = require('mysql');
const { promisify } = require('util');
const database = { // Database credentials }
const bd = mysql.createPool(database);
bd.getConnection((err,connection) => {
if (err) {
if (err.code === 'PROTOCOL_CONNECTION_LOST') {
console.error('Database connection failed !');
}
if (err.code === 'ER_CON_COUNT_ERROR') {
console.error('Database has too many connections !');
}
if (err.code === 'ECONNREFUSED') {
console.error('Database connection was refused !');
}
}
if (connection) {
connection.release();
console.log('Database is connected !');
return;
}
});
bd.query = promisify(bd.query);
module.exports = bd;
common.js
const { bd } = require('../database');
const helper_functions = {}
helper_functions.validateSignUp = (fullname, email, username, password, password_repeat) => {
if (fullname === '' || email === '' || username === '' || password === '' || password_repeat === '') {
return 'All the fields had to be completed!';
}
if (!(password.length >= 8 && (/\d/g.test(password) && (/[A-Z]/.test(password)))) ) {
return 'The password needs to contain at least one capital letter, a number and 8 digits!';
}
有谁知道发生了什么??谢谢阅读!
青春有我
侃侃无极
尚方宝剑之说
随时随地看视频慕课网APP
相关分类