用户管理在节点js中使用express,mongodb作为服务器数据库

时间:2021-01-12 02:34:07

Looking for the way to add user management to my site.

寻找添加用户管理到我的网站的方法。

Site: Working with Node.js & Express, when creating the initial project with Express, the app.js file contains these lines:

站点:使用Node.js和Express,在使用Express创建初始项目时,app.js文件包含以下行:

app.use('/', routes);
app.use('/users', users);

In addition, a file users.js is created under routes folder. My question is how to manage users, force login, and show different views for regular user / admin user. I wish to find a simple example / tutorial.

此外,在routes文件夹下创建文件users.js。我的问题是如何管理用户,强制登录,并为常规用户/管理员用户显示不同的视图。我希望找到一个简单的示例/教程。

Storage: Working with MongoDB & mongoose, I noticed the database has Users folder built-in. I want to save users data (user + password + preference) on MongoDB. What is the way to do this?

存储:使用MongoDB和mongoose,我注意到数据库内置了Users文件夹。我想在MongoDB上保存用户数据(用户+密码+首选项)。这样做的方法是什么?

1 个解决方案

#1


5  

I followed this tutorial. https://scotch.io/tutorials/easy-node-authentication-setup-and-local

我按照本教程。 https://scotch.io/tutorials/easy-node-authentication-setup-and-local

Passport js does the job very nicely, doing this without a library would just require you to reinvent the wheel.

Passport js可以很好地完成这项工作,没有磁带库这样做只需要你重新发明*。

#1


5  

I followed this tutorial. https://scotch.io/tutorials/easy-node-authentication-setup-and-local

我按照本教程。 https://scotch.io/tutorials/easy-node-authentication-setup-and-local

Passport js does the job very nicely, doing this without a library would just require you to reinvent the wheel.

Passport js可以很好地完成这项工作,没有磁带库这样做只需要你重新发明*。