简体   繁体   English

跟踪用户日常登录 function Ruby on Rails

[英]Track user daily login function Ruby on Rails

I have a quick question.我有一个快速的问题。 I am writing a function that determines whether a user is logged in for the day as part of a larger effort to track daily logins and user that function in the controller to increment (or not) a point value per user.我正在编写一个 function 来确定用户是否在当天登录,作为跟踪每日登录和用户 function 中的 function 的更大努力的一部分,Z594C103F2C6E04C3D8AB059F031E0 不是每个 C 点的值。 I know that the Devise gem has the Trackable module to record such values for the user.我知道 Devise gem 有 Trackable 模块来为用户记录这些值。 But when using those methods in an overall function, would I need to keep track of the last sign in time and compare that to the current sign in time.但是,当在整个 function 中使用这些方法时,我是否需要跟踪上次登录时间并将其与当前登录时间进行比较。 Kinda of confused on how to implement this in a user login tracking function.关于如何在用户登录跟踪 function 中实现这一点有点困惑。 Would anyone be able to help?有人能帮忙吗?

I think you can go at this multiple ways if you want to roll it yourself.如果您想自己滚动,我认为您可以通过多种方式使用 go。

You can extend your user table with 2 columns (one for the current login and one for the previous login timestamp) and create an after login callback to update both columns.您可以使用 2 列(一列用于当前登录,一列用于先前登录时间戳)扩展您的用户表,并创建登录后回调以更新两列。

You could create a second table (one user has many timestamps) and record every login timestamp for your users.您可以创建第二个表(一个用户有许多时间戳)并为您的用户记录每个登录时间戳。 Then you can compare the latest 2 logins然后你可以比较最近的2次登录

However, you have to consider that sessions get retained in cookies and a login depends largely on how long a cookie exists.但是,您必须考虑会话会保留在 cookies 中,并且登录很大程度上取决于 cookie 存在的时间。 Maybe what you want instead is when users request or update a resource that is gated behind the login?也许您想要的是当用户请求或更新登录后门控的资源时?

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

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