简体   繁体   English

使用sails.js编写密码重置

[英]Writing Password reset using sails.js

I am stuck with user reset password. 我卡住了用户重置密码。 These are the steps that I have accomplished. 这些是我已经完成的步骤。

  1. User selects 'reset password link'. 用户选择“重置密码链接”。

  2. Sails.js generates GUID and saves it to a resetPassTable. Sails.js生成GUID并将其保存到resetPassTable。

  3. Email is sent to the users email. 电子邮件发送到用户的电子邮件。

  4. I have changePwdController that has reset action 我有具有重置操作的changePwdController

  5. The email that is sent, contains localhost:1337/changePwd/reset/secrethash 发送的电子邮件包含localhost:1337 / changePwd / reset / secrethash
  6. User clicks on that link and is directed to my action 用户点击该链接,并定向到我的操作
  7. Basically I have access to that hash that is in id, something like: 基本上,我可以访问id中的哈希,例如:

    var secretHash = req.param('id') var secretHash = req.param('id')

  8. I check that hash against the one in the database, and can make decision as what to do. 我对照数据库中的哈希值检查该哈希值,并可以决定要做什么。

  9. If the check is passed, meaning there is that hash in DB... 如果检查通过,则意味着数据库中存在哈希...
  10. ...how do I present a user with two simple textboxes (new pass and repeat pass) and send button? ...如何为用户提供两个简单的文本框(新通过和重复通过)和发送按钮?

You should show the password reset form when the user clicks on the link from the email (this would be just rendering a view normally). 当用户单击电子邮件中的链接时,您应该显示密码重置表单(这只会正常显示视图)。 You do need to carry the hash to that view though, maybe an URL param? 但是,您确实需要将哈希值携带到该视图中,也许是URL参数?

Then once the user submits the password reset form then do the password reset or rejection if hash does not match one in the database. 然后,一旦用户提交了密码重置表单,然后在哈希与数据库中的哈希不匹配时执行密码重置或拒绝。 So you need two different actions. 因此,您需要两种不同的操作。 One for showing the view, and another one the form hits upon submission. 一种用于显示视图,另一种用于在提交时单击表格。

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

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