【发布时间】:2022-01-26 15:59:05
【问题描述】:
所以我有一个网站我需要修改 HTML 元素在一个登录表单中,例如它会显示用户名是否错误我需要它检查服务器端然后修改它,以便它将文本显示给客户端-侧面
我的网站是聊天应用程序,我尝试的当前代码是
app.post("/signup", function (req, res) {
function makerror(message) {
// idk
}
if (req.body.username) {
const emailregex = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
if (!req.body.email.match(emailregex)) {
return makerror("Please enter a vaild Email");
}
const passwordregex = /^.{8,}$/
if (!req.body.password.match(passwordregex)) {
return makerror('Your password must be 8 characters long.')
}
const usernameregex = /^[a-zA-z0-9]{3,25}$/g
if (!req.body.username.match(usernameregex)) {
return makerror('Your username must contain only character from A to Z, Underscores and number from 0 to 9')
}
const data = new Userdata({ username: req.body.username, password: scureJs.encrypt(req.body.password), email: req.body.email })
data.save()
const obj = {
username: req.body.username,
password: req.body.password,
email: req.body.email,
unix: Math.round(new Date() * 1000)
}
const cookie = scureJs.serialize(obj)
res.cookie('sessionId', cookie, {
expires: false,
httpOnly: true,
sameSite: 'lax',
})
console.log(cookie)
console.log(req.body)
}
})
我的应用是聊天应用
【问题讨论】: