freeCodeCamp/curriculum/challenges/chinese/06-information-security-and.../advanced-node-and-express/logging-a-user-out.chinese.md

2.0 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
58965611f9fc0f352b528e6c Logging a User Out 2 记录用户

Description

提醒一下,这个项目是基于Glitch的以下入门项目构建的,或者是从GitHub克隆的。创建注销逻辑很容易。路径应该只是取消认证用户并重定向到主页而不是渲染任何视图。在护照中, req.logout();认证用户就像调用req.logout();一样简单req.logout();在重定向之前。
 app.route '/注销'
  .getreqres=> {
      req.logout;
      res.redirect '/';
  }; 
您可能已经注意到我们也没有处理丢失的页面404在Node中处理此问题的常用方法是使用以下中间件。继续在所有其他路线之后添加
 app.usereqresnext=> {
  res.status404
    .TYPE '文本'
    .send'未找到';
}; 
当您认为自己已经做对时,请提交您的页面。

Instructions

Tests

tests:
  - text: 退出路线
    testString: 'getUserInput => $.get(getUserInput("url")+ "/_api/server.js") .then(data => { assert.match(data, /req.logout/gi, "You should be call req.logout() in youre /logout route"); }, xhr => { throw new Error(xhr.statusText); })'
  - text: 注销应该重定向到主页/
    testString: 'getUserInput => $.get(getUserInput("url")+ "/logout") .then(data => { assert.match(data, /Home page/gi, "When a user logs out they should be redirected to the homepage"); }, xhr => { throw new Error(xhr.statusText); })'

Challenge Seed

Solution

// solution required