18910140161

重新启动服务器后无法获取

顺晟科技

2021-09-04 12:35:17

299

所以我做了一个网站,我做了一个登录功能,出于某种原因,当我做了一个帐户,试图登录它工作,但当我重新启动服务器时,它说“无法获取”,我不知道会发生什么变化

函数验证

function validation(email, password) { let data = `{ "email": "${email}", "password": "${password}" }`; alert(data) fetch("https://domain/api/user/get", { "method": "POST", "headers": { "Content-Type": "application/json" }, "body": data }) .then(async response => { response.json().then(json => { if (json.error.isError == true) { document.getElementById('invalid').style.borderColor='red' document.getElementById('invalid').style.visibility = 'visible' document.getElementById('invalid').style.opacity = '1' return document.getElementById('invalid').innerText = json.error.message // return false; } location.href='/dashboard' }); }).catch(e => { alert(e) return false; }) }

函数登录

function login() { try { let email = document.getElementById('nemail').value; let password = document.getElementById('npassword').value; var emailReg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; if (!emailReg.test(email)) { return false; } validation(email, password); } catch(e) { console.log(e); return false; } }

应用程序发布

app.post("/api/user/get", async (req, res) => {
  try {
    let {email, password} = req.body

    if (!email) {
      eValid = '{"error": {"isError": true, "message": "No Email Provided"}}'
        return res.send(eValid)
    }

    if (!password) {
      eValid = '{"error": {"isError": true, "message": "No password provided"}}'
      return res.send(eValid)
    }
  if(email) {
      var emailReg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
      if(!emailReg.test(email)) {
        eValid = '{"error": {"isError": true, "message": "Invalid Email"}}'
      return res.send(eValid)
      } 
    }
    const userData = await userdb.findOne({email: email});

    if (!userData) {
      eValid = '{"error": {"isError": true, "message": "Account Not found. Is the Email correct?"}}'
        return res.send(eValid)
    }
  let hashMatch = await bcrypt.compare(password, userData.password)
    if(!hashMatch) {
      eValid = '{"error": {"isError": true, "message": "Password is Incorrect. Please Try Again."}}'
      return res.send(eValid)
    }
  eValid = '{"error": {"isError": false, "message": null}}'
  req.session.isAuth = true;
  console.log("it gets here at least")
  return res.send(eValid)
  } catch(e) {
    console.log(e)
  }
})

我不知道我可能做错了什么D:如果你们能帮忙,那太好了,我已经尝试了控制台日志记录,并试图登录它,但我不知道为什么它会抛出错误,也不知道为什么当我次注册时它会工作。抱歉,如果代码有点乱,我知道人们会对此生气


顺晟科技:

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航