当前位置: 首页 > 软件库 > Web应用开发 > >

express-4.x-local-example

授权协议 Unlicense License
开发语言 JavaScript
所属分类 Web应用开发
软件类型 开源软件
地区 不详
投 递 者 尹辰沛
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

This example illustrates how to use Express 4.x andPassport to sign users in with a username andpassword. Use this example as a starting point for your own web applications.

Quick Start

To get started with this example, clone the repository and install thedependencies.

$ git clone https://github.com/passport/express-4.x-local-example.git
$ cd express-4.x-local-example
$ npm install

Start the server.

$ npm start

Navigate to http://localhost:3000.

Overview

This example illustrates how to use Passport andthe passport-localstrategy within an Express application to sign users inwith a username and password.

The example builds upon the scaffolding created by Express generator,and uses EJS as a view engine and plain CSS for styling. Thisscaffolding was generated by executing:

$ express --view ejs express-4.x-local-example

The example uses SQLite for storing user accounts.SQLite is a lightweight database that works well for development, including thisexample.

Added to the scaffolding are files which add authentication to the application.

  • boot/db.js

    This file initializes the database by creating the tables used to store useraccounts and credentials.

  • boot/auth.js

    This file initializes Passport. It configures the password strategy with averify callback. The callback verifies the password by finding the useraccount in the database. If the account is found, the callback hashes thepassword entered and compares it to the hashed password stored in thedatabase. If the comparison is equal, the user is authenticated.

    This file also supplies the serialization functions used for sessionmanagement.

  • routes/auth.js

    This file defines the routes used for authentication. In particular, thereare two routes used to authenticate with a username and password:

    • GET /login

      This route renders a page that prompts the user to enter their username andpassword.

    • POST /login/password

      This route authenticates the user using their username and password.

  • routes/users.js

    This file defines the routes used for registration. In particular, there aretwo routes used to create an account:

    • GET /users/new

      This route renders a page that prompts the user to enter the informationneeded to register an acccount. This information consists of their name,preferred username, and password.

    • POST /users

      This route creates a new account using the information entered by the user.The password is first hashed and stored in hashed format.

License

The Unlicense

  • 地址:https://github.com/skonves/express-http-context   1.简介   在任何地方获取并设置请求范围的上下文。这只是cls-hooked(由continuation-local-storage派生)的不受限制的,惯用的ExpressJS实现。 这是存储用户状态,JWT声明,请求/关联ID以及任何其他请求范围数据的好地方。即使在async/await时

 相关资料
  • This example demonstrates how to use Express 4.x andPassport to log users in with Facebook.Use this example as a starting point for your own web applications. Quick Start To get started with this exam

  • express() Creates an Express application. The express() function is a top-level function exported by the express module. var express = require('express') var app = express() Methods express.json([opt

  • 问题内容: 如何与Socket.io 1.0和Express 4.x共享会话?我使用Redis商店,但我认为这没有关系。我知道我必须使用中间件来查看cookie和获取会话,但是不知道如何。我搜索了但找不到任何工作 问题答案: 解决方案非常简单。它只是没有很好的记录。也可以通过如下所示的小型适配器将快速会话中间件用作Socket.IO中间件: 这是Express 4.x,Socket.IO 1.x和

  • 问题内容: 我刚刚开始在Node.js应用程序中学习Express 4.0,我发现它生成了文件,在该文件上仅写入了应用程序服务器和端口设置,并且在文件中定义了其他所有内容(例如中间件和路由)。 但是,我不确定这是做什么的。我使用Express 3.x,并且始终在同一文件中定义服务器和端口设置以及路由和中间件,并使用来启动我的节点应用程序。那么使用的意义何在?它仅将服务器和端口定义与其他定义分开吗?

  • 问题内容: 我正在使用Express 4.0,并且我知道主体解析器已从Express核心中移除,我使用的是推荐的替代品,但是我得到了 我在哪里可以找到这个所谓的中间件?还是我不应该得到这个错误? 问题答案: 这意味着自2014年6月19日起,不赞成使用 构造函数 。 您现在需要分别调用方法 等等。 如果仍然收到警告,则需要使用 在现在的配置对象的关键需要明确的被传递,因为它现在已经没有默认值。 如

  • 服务器端(app.js) var app = require('express')(); var server = require('http').Server(app); var io = require('socket.io')(server); server.listen(80); app.get('/', function (req, res) { res.sendfile(__d