简体   繁体   English

如何组织两步确认? 节点js

[英]How to organize two steps confirmation? node js

I have the node.js server that proceeds cash operations. 我有进行现金操作的node.js服务器。 I want to make the user confirmation of cash transactions. 我想让用户确认现金交易。 I provide this feature to prevent user mistakes. 我提供此功能是为了防止用户出错。

Step 1: User inputs some values into the html form, then server gets values from this form(eg post query), prepares it and sends back to the user. 步骤1:用户将一些值输入到html表单中,然后服务器从该表单中获取值(例如,后查询),进行准备并将其发送回用户。

Step 2: User checks received data and press "OK" or "Cancel", depends on it the server uses the data, received on step 1 in a special way. 步骤2:用户检查接收到的数据,然后按“确定”或“取消”,这取决于服务器使用特殊方式从步骤1接收到的数据。

My problems are: Connection between step 1 and step 2 on the server side. 我的问题是:服务器端步骤1和步骤2之间的连接。 Where should I store the data from step 1 until step 2? 从步骤1到步骤2的数据应该存储在哪里?

Or can you advise me another logic in this situation? 或者您可以在这种情况下建议我另一种逻辑吗?

You have a session that comes from passport.js for the user, so you would typically save the data temporarily as a property on the session object for that user. 您有一个来自passport.js的用户会话,因此通常会将数据临时保存为该用户的会话对象上的属性。 Then, on the confirmation, you can retrieve the data from the session and continue the process. 然后,在确认后,您可以从会话中检索数据并继续该过程。

You may want to also have some logic that removes the extra data from session after some timeout if there is no confirming response from the user within some period of time. 如果在一段时间内没有来自用户的确认响应,您可能还需要一些逻辑来在超时后从会话中删除多余的数据。 Of, you could just leave it there until the session itself times out. 当然,您可以将其保留在那里直到会话本身超时。

There's a lot written in this article ExpressJS and PassportJS Sessions Deep Dive about how to add more properties to the session. 本文中有很多关于如何向会话添加更多属性的ExpressJS和PassportJS会话深入探讨。 Depending upon your passport configuration, it may be as simple as just adding a property to req.user or it may be slightly more involved. 根据您的护照配置,它可能只是简单地向req.user添加一个属性,或者可能稍微复杂一些。

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

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