简体   繁体   English

使用 Electron 注册 PouchDB/CouchDB/ 的用户

[英]User registration for PouchDB/CouchDB/ with Electron

I am building an Electron desktop app, and one of the first things I want to tackle is user creation to interact with the db.我正在构建一个Electron桌面应用程序,我想要解决的第一件事是创建用户以与 db 交互。 The idea is they log in and then they are able to see their own user information within the app.这个想法是他们登录,然后他们就可以在应用程序中看到自己的用户信息。 To my understanding, I can make this happen in pouchDB and that will ultimately sync with a remote CouchDB server.据我了解,我可以在 pouchDB 中实现这一点,并且最终将与远程 CouchDB 服务器同步。

I am stuck on user creation (I haven't even begun to tackle user sessions yet).我被困在用户创建上(我什至还没有开始处理用户会话)。 I have created an html form with Electron that takes an email, username, and a password.我用 Electron 创建了一个html表单,它带有电子邮件、用户名和密码。 I plan to use PouchDB to store information locally and eventually sync with a CouchDB server.我计划使用 PouchDB 在本地存储信息并最终与 CouchDB 服务器同步。 I haven't written any JS yet to handle the form submission.我还没有写任何 JS 来处理表单提交。 When they click "Sign Up", I want that user to be created.当他们单击“注册”时,我希望创建该用户。

I get confused because there is a _users database in CouchDB that I understand stores user's sensitive information (like a password).我很困惑,因为 CouchDB 中有一个 _users 数据库,我知道它存储用户的敏感信息(如密码)。

My Question: When a user submits the aforementioned form, do I create a db in PouchDB called _users?我的问题:当用户提交上述表单时,我是否在 PouchDB 中创建一个名为 _users 的数据库? And eventually when I sync it with CouchDB will it know automatically what information to store in users?最终当我将它与 CouchDB 同步时,它会自动知道要在用户中存储哪些信息?

You should use PouchDB only in case it must be possible to also work offline with your application.您应该仅在必须可以离线使用您的应用程序时才使用PouchDB Otherwise it makes the code unnecessary more complex, but does not bring any real benefits in your case.否则,它会使代码不必要地变得更加复杂,但不会为您的案例带来任何真正的好处。 Simply access CouchDB directly through its HTTP API.只需通过其 HTTP API 直接访问 CouchDB。

CouchDB distinguishes between two types of users CouchDB 区分两种类型的用户

  1. admin users are stored in the [admins] section of the configuration file $COUCHDB_HOME/etc/local.ini. admin 用户存储在配置文件 $COUCHDB_HOME/etc/local.ini 的[admins]部分。 When setting up your CouchDB, you're requested to define a first admin user.设置 CouchDB 时,您需要定义第一个管理员用户。 Additional admin users may be created later on (see Creating New Admin User ).稍后可能会创建其他管理员用户(请参阅创建新管理员用户)。
  2. regular users are stored in the authentication database , named _users .常规用户存储在名为_users身份验证数据库中 User documents contain system information like login, password hash and roles but may also contain personal information like real name, email, phone etc. Creating a new regular user is trivial (see Creating New User ).用户文档包含系统信息,如登录名、密码哈希和角色,但也可能包含个人信息,如真实姓名、电子邮件、电话等。创建一个新的普通用户是微不足道的(参见创建新用户)。

If the CouchDB is going to be on the Internet (rather than on an Intranet, with only trusted users having access), then I would consider a server-side process to handle sign-ups.如果 CouchDB 将在 Internet 上(而不是在 Intranet 上,只有受信任的用户才能访问),那么我会考虑使用服务器端进程来处理注册。 That server-side process is the only one that needs to know an admin user/password that allows it to add users to the couchDB _users table (as described in the answer by uminder ).该服务器端进程是唯一需要知道管理员用户/密码的进程,以便将用户添加到 couchDB _users 表(如uminder回答中所述)。

Ie write user signup as a normal website, and in the electron app just access that as a web page.即,将用户注册写为普通网站,在电子应用程序中只需将其作为网页访问即可。

You can have the Electron app construct and send a specially signed cookie that would stop non-app users accessing that page.您可以构建 Electron 应用程序并发送一个特别签名的 cookie,以阻止非应用程序用户访问该页面。

Restricting by that cookie should give you good control against abuse.通过该 cookie 进行限制应该可以让您很好地控制滥用。 But by having a webserver process you still have all the options to add an email confirmation step, restrict by IP address, rate limit, etc. (or even, if really desperate, add Cursed Captcha to the form).但是,通过网络服务器进程,您仍然可以选择添加电子邮件确认步骤、通过 IP 地址进行限制、速率限制等(甚至,如果真的很绝望,可以将 Cursed Captcha 添加到表单中)。

The other advantage of this approach is that you don't need to hard-code your CouchDB admin username/password in the Electron app.这种方法的另一个优点是你不需要在 Electron 应用程序中硬编码你的 CouchDB 管理员用户名/密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM