I use following code to accept the regsiter
call from client
.post('/regsiter', async (ctx) => {
requestfrom = JSON.parse(JSON.stringify(ctx.request.body))
let regxemail = /^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/;
let email = requestfrom.email
let password = md5(requestfrom.password)
if (regxemail.test(email)) {
await userModel.checkemailexist([email])
.then(async(result) => {
if (result.length === 0) {
console.log("insert email to database")
await userModel.insertUser([email,password])
} else {
console.log("email exist")
}
})
}
})
If the visiter's network is well, this function will work well, but if the visiter's network is so slow, there's no enough response time, and it will insert some same datas into database, the result.length
is always ===0
, how can I stop this, any ideas?