博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
js 验证护照_护照本地策略第1部分| Node.js
阅读量:2535 次
发布时间:2019-05-11

本文共 3197 字,大约阅读时间需要 10 分钟。

js 验证护照

In my last article, we had an and explained the meaning of strategies.

在上一篇文章中,我们进行了并解释了策略的含义。

Here, we will look at the various requirements for setting up the passport-local strategy with node/express and MongoDB database to build a login form.

在这里,我们将研究通过node / express和MongoDB数据库设置本地护照策略以构建登录表单各种要求

I have broken the steps down to make it simpler to understand.

我将步骤分解为更易于理解。

Note: You should have a basic understanding of Node.js, Express, MongoDB database, and HTML.

注意 :您应该对Node.js,Express,MongoDB数据库和HTML有基本的了解。

Getting started...

入门...

In this first section of the passport-local strategy implementation, we will,

实施护照本地化策略的第一部分中,我们将

  1. Create an html login form

    创建一个HTML登录表单

  2. Install express and other middlewares such as body-parser which we need to work with

    安装Express和其他我们需要使用的中间件,例如body-parser

  3. Set up our express server

    设置我们的快递服务器

Note: Make sure your own files are organized in one folder.

注意:确保将自己的文件组织在一个文件夹中。

Let's begin by creating our html login form...

让我们开始创建我们的html登录表单...

Open a text editor and type the following code: Save the file as form.html

打开一个文本编辑器,然后键入以下代码: 将文件另存为form.html

    passport    
    

The form action above has been set to: <form action="/" method="post"> meaning the back-end is found at the main route or home route which is globally represented by "/" and the method as the post.

上面的表单动作已设置为: <form action =“ /” method =“ post”>表示后端位于主路径或本国路径上,该路径由“ /”全局表示,该方法为发布。

安装所需的模块和中间件 (Install required modules and middlewares)

We are now going to install all the modules/middlewares we are going to use.

现在,我们将安装将要使用的所有模块/中间件。

To quickly do so, open your cmd terminal, move to your node project directory and type the following commands as seen below,

为此,请打开cmd终端 ,移至节点项目目录,然后键入以下命令,如下所示,

passport module 3
passport module 4
passport module 5

Wait for a while as npm downloads the packages for you.

等待一段时间,因为npm为您下载了软件包。

Note: You can use either command prompt or PowerShell as terminal.

注意:您可以使用命令提示符或PowerShell作为终端。

Let's set up our express server...

让我们设置快递服务器...

Open a text editor and type the following code: save the file as app.js

打开一个文本编辑器,然后输入以下代码: 将文件另存为app.js

/*  EXPRESS SETUP  */const express = require('express'); // require express modulesconst app = express();const bodyParser = require('body-parser'); // require body-parser app.use(bodyParser.urlencoded({
extended: true}));app.get('/', (req, res) => res.sendFile('form.html', {
root: __dirname})); // create main route// the route is configured to read the html file // we created above called form.htmlconst port = process.env.PORT || 3000; // set port 3000 app.listen(port, () => console.log('App listening on port ' + port));

That's all for this first section. We have created our HTML form, installed the modules we are going to use and finally set up our express server.

这就是第一部分的全部内容。 我们已经创建了HTML表单,安装了将要使用的模块,最后设置了Express服务器。

Read further setup steps:

阅读更多设置步骤:

Thanks for coding with me! See you @ the next article. Feel free to drop a comment or question.

感谢您与我编码! 下次见。 随意发表评论或问题。

翻译自:

js 验证护照

转载地址:http://vpvzd.baihongyu.com/

你可能感兴趣的文章
iOS语言中的KVO机制
查看>>
excel第一次打开报错 向程序发送命令时出错 多种解决办法含终极解决方法
查看>>
响应式web设计之CSS3 Media Queries
查看>>
实验三
查看>>
机器码和字节码
查看>>
环形菜单的实现
查看>>
Python 函数参数 传引用还是传值
查看>>
【解决Chrome浏览器和IE浏览器上传附件兼容的问题 -- Chrome关闭flash后,uploadify插件不可用的解决办法】...
查看>>
34 帧动画
查看>>
二次剩余及欧拉准则
查看>>
Centos 7 Mysql 最大连接数超了问题解决
查看>>
thymeleaf 自定义标签
查看>>
关于WordCount的作业
查看>>
C6748和音频ADC连接时候的TDM以及I2S格式问题
查看>>
UIView的layoutSubviews,initWithFrame,initWithCoder方法
查看>>
STM32+IAP方案 实现网络升级应用固件
查看>>
用74HC165读8个按键状态
查看>>
jpg转bmp(使用libjpeg)
查看>>
linear-gradient常用实现效果
查看>>
sql语言的一大类 DML 数据的操纵语言
查看>>