Ruby on Rails:没有 Authlogic 的 perishable_token?
我使用 http://ruby.railstutorial.org/ 中实现的注册和登录,没有任何 gem 进行身份验证。但是,现在我尝试通过向用户发送随机生成的 URL 来激活用户,但我遇到了麻烦。我在网上搜索过,看到有些人使用 Authlogic 的 perishable_token 来生成这个,但由于我根本没有使用过 Authlogic,我想知道是否有一种方法可以在不使用任何其他 gem 的情况下生成这个。铁路专业人士有什么建议吗?谢谢
I used signup and login as implemented in http://ruby.railstutorial.org/ without any gems for authentication. However, now that I am trying to activate users by sending them randomly generated URLs, I am having trouble here. I've searched the web and have seen some people that used Authlogic's perishable_token to generate this, but since I haven't used Authlogic at all, I was wondering if there might be a way to generate this without using any other gems. Any advice from rails professionals out there? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有很多方法可以实现这一目标。您首先必须决定如何生成令牌。您可以简单地使用用户的一些数据(例如电子邮件)以及另一条种子数据(例如 Time.now)创建 md5hash,并将其存储为用户的“perishable_token”。
然后,您可以覆盖 perishable_token 的读取器访问器以生成另一个令牌并更新用户模型。
上面只是一些快速的伪代码,但应该能够表达要点。
There are a many ways to achieve this. You first have to decide how you want to generate the token. You can simply create an md5hash using some data on the user such as email along with another piece of seed data like Time.now and store it as the 'perishable_token' on the user.
You can then override the reader accessor for perishable_token to generate another token and update the user model.
The above is just some quick pseudo-code, but should get the point across.
我想一个简单的方法是生成一个随机字符串/数字用作
perishable_token
这里有一个关于随机字符串生成的问题,您可以先看一下。
I suppose a simple way would be to just generate a random string/number to use as the
perishable_token
a question about random string generation here you can look at for a starters.