gpt4 book ai didi

Javascript,关于数组中的node.js : How can I make the code store,,SQL值

转载 作者:太空宇宙 更新时间:2023-11-04 01:53:27 25 4
gpt4 key购买 nike

所以这里我有一个大问题:我需要在 json 文件中创建一个存储 SQL 值的数组(代码如下)。问题是,我在哪里声明查询,或者我应该添加哪些额外内容才能使其正常工作?我创建了 viewMontadora 函数,当我运行服务器时它可以正常工作,列出在 SQL 中注册的所有汽车制造商及其所有信息。我对node.js还不是很熟悉。

app.use(express.static(__dirname + '/library'))
app.listen(port, () => {
console.log(`Servidor online em
http://localhost:${port}`)
})

app.get('/', (req, res) => {
res.render('pages/home')
})

app.get('/about', (req, res) => {

function viewMontadora() {
var conn = new sql.Connection(dbConfig);
conn.connect().then(function () {
var req = new sql.Request(conn);
req.query("SELECT * FROM VIEW_PRODUTOS").then(function (recordset) {
res.contentType('application/json');
res.send(JSON.stringify(recordset));
console.log(recordset);
conn.close();
}).catch(function (err) {
console.log(err);
conn.close();
});
}).catch(function (err) {
console.log(err);
});
}
return viewMontadora();

})

app.get('/contact', (req, res) => {
res.render('pages/contact')
})

app.post('/contact', (req, res) => {
res.send('Obrigado por entrar em contato conosco, ' + req.body.name + '!Responderemos em breve!')
})

app.post('/client', (req, res) => {
// Lista de Utilizadores
var usersValid = [{
username: 'SELECT [RazaoSocial] FROM [SITE].[dbo].[Clientes]',
email: 'SELECT [Email] FROM [SITE].[dbo].[Clientes]'
}, ];
console.log(usersValid);
var error = [{
id: 1,
ErrorLogin: 'Usuario não identificado'
}];

usersValid.push({
username: req.body.name,
email: req.body.email
});
for (var i = 0; i < usersValid.length; i++) {
if (usersValid[i].username === req.body.name && usersValid[i].email ===
req.body.email) {

var dataClient = [{
nameClient: req.body.name,
emailClient: req.body.email,
imgClient: 'http://lmdsneto.000webhostapp.com/images/user.png'
}]
res.render('pages/client', {
dataClients: dataClient
})
//res.send('Bem vindo, ' + req.body.name + ' Email ' +
req.body.email
} else {
res.send(error);
}
}
});

最佳答案

在较高级别上,您需要从客户那里接收电子邮件和密码,例如。浏览器,然后您需要确认该用户名和密码是否存在于您的数据库中。如果那么做,那么您可以说他们是有效用户。

因此,除了以纯文本形式存储密码的安全问题之外,您应该能够简单地执行以下操作:(显然只需更改您需要的用户 ID 的任何值)

app.post('/client', (req, res) => {

// place userInfo into an object
var userInfo = {
email: req.body.name,
password: req.body.password
};

var conn = new sql.Connection(dbConfig);

conn.connect().then(function () {
var req = new sql.Request(conn);
req.query("SELECT * FROM FROM [SITE].[dbo].[Clientes] WHERE email = " +
userInfo.email +
" AND password = " +
userInfo.password).then(function (selectedUser) {
// if we have one selected user we know it is valid
if (selectedUser.length === 1) {
// user is valid

} else {
// user is not valid
}
});
}).catch(function (err) {
console.log(err);
});
});

关于Javascript,关于数组中的node.js : How can I make the code store,,SQL值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48832797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com