Authlogic和用于同一用户的多个会话 [英] Authlogic and multiple sessions for the same user

查看:150
本文介绍了Authlogic和用于同一用户的多个会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Authlogic来管理我的应用程序会话。结果
然而,在默认情况下,authlogic允许从不同的电脑多次登录的用户。结果
我不希望这样(用户付费来获得访问,我想避免用户分享​​他们的帐户)。

I'm using Authlogic to manage the sessions in my application.
However, by default, authlogic allows a user to be logged in many times from different computers.
I don't want that (the user pays to get access and I want to avoid users sharing their accounts).

放眼Authlogic文档中,我发现关于 perishable_token 。但是,试图实现它的时候,我只是得到一个错误说的 persistence_token 是必需的(当它不应该是因为我用的易腐之一)。

Looking in the Authlogic documentation, I've found about the perishable_token. But when trying to implement it, I just get an error saying the persistence_token is required (when it shouldn't be as I use the perishable one).

你会怎么做这使用Authlogic的特点是什么?

How would you do this using the Authlogic's features ?

感谢:)

推荐答案

确定这样的易腐令牌是绝对不正确的道路;)

Ok so the perishable token was absolutely not the right path ;)

我们只是需要每次用户登录重置令牌持续存在或注销。
有了这个我UserSession模型中,每个用户会从登录时任何其他会话注销。

We "just" need to reset the persistence token every time a user logs in or logs out. With this in my UserSession model, every user gets logged off from any other session when logging in.

class UserSession < Authlogic::Session::Base
    before_destroy :reset_persistence_token
    before_create  :reset_persistence_token

    def reset_persistence_token
        record.reset_persistence_token
    end 
end

这篇关于Authlogic和用于同一用户的多个会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆