app.post("/register", urlencodedParser, async(req, res, next) => {
let name = req.body.username;
let email = req.body.email;
let password = req.body.password;
const [row] = await dbConnection.query( // Здесь мы запрашиваем данные, существует ли введенный пользователем логин или нет.
"SELECT * FROM `users` WHERE `email`=?", [email]
);
if (req.body.password == 123456 || req.body.password == 098765 || req.body.password == 987654 || req.body.password == 111111 || req.body.password == 222222 || req.body.password == 333333 || req.body.password == 444444 || req.body.password == 555555 || req.body.password == 666666 || req.body.password == 777777 || req.body.password == 888888 || req.body.password == 999999 || req.body.password == 000000 || req.body.password == 123123) {
res.send("Ваш пароль слишком простой, вам нужно придумать посложнее.");
} // Checking password. If password is easy, server send error.
else {
if (row.length === 0) { // Checking users, if username already registered, server will send error
if (password.length >= 6) { // Checking length password. If less than 6 - server will send error.
res.render('verification-email')
const code = makecode(6);
await transporter.sendMail({
from: '"Verificator email" <support@galaktika-sluha.ml>',
to: `${req.body.email}`,
subject: 'Подтвердите свой E-mail',
html: `<h1>Ваш код:<h1> <h3>${code}</h3>`,
})
req.locals = {
name: name,
email: email,
password: password
}
next()
} else {
res.send('Пароль должен быть минимум из 6 символов')
}
} else {
res.send("Введённая электронная почта уже зарегистрирована");
}
}
});
app.post('/email-verification', async(req, res) => {
console.log(req.locals.email)
if (req.body.code === code) {
let post = {
name: `${req.locals.name}`,
email: `${req.locals.email}`,
password: `${req.locals.password}`
} // Структура данных для сервера
let sql = "INSERT INTO users SET ?" // Writing data to the DB
let query = await dbConnection.query(sql, post, err => {});
res.send(`Вы зарегистрированы!`);
req.session.loggedin = true;
req.session.username = username;
}
})
Server started on port 3000
/home/nikita/galaxy-of-hearing/index.js:118
console.log(req.locals.email)
^
TypeError: Cannot read properties of undefined (reading 'email')
at /home/nikita/galaxy-of-hearing/index.js:118:28
at Layer.handle [as handle_request] (/home/nikita/galaxy-of-hearing/node_modules/express/lib/router/layer.js:95:5)
at next (/home/nikita/galaxy-of-hearing/node_modules/express/lib/router/route.js:144:13)
at Route.dispatch (/home/nikita/galaxy-of-hearing/node_modules/express/lib/router/route.js:114:3)
at Layer.handle [as handle_request] (/home/nikita/galaxy-of-hearing/node_modules/express/lib/router/layer.js:95:5)
at /home/nikita/galaxy-of-hearing/node_modules/express/lib/router/index.js:284:15
at Function.process_params (/home/nikita/galaxy-of-hearing/node_modules/express/lib/router/index.js:346:12)
at next (/home/nikita/galaxy-of-hearing/node_modules/express/lib/router/index.js:280:10)
at /home/nikita/galaxy-of-hearing/node_modules/body-parser/lib/read.js:137:5
at AsyncResource.runInAsyncScope (node:async_hooks:202:9)