本文共 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,
在实施护照本地化策略的第一部分中,我们将
Create an html login form
创建一个HTML登录表单
Install express and other middlewares such as body-parser which we need to work with
安装Express和其他我们需要使用的中间件,例如body-parser
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”>表示后端位于主路径或本国路径上,该路径由“ /”全局表示,该方法为发布。
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终端 ,移至节点项目目录,然后键入以下命令,如下所示,
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/