1

Authlogic中是否有一种简单的方法(在浏览文档时没有发现任何内容)来确保如果用户已经拥有 UserSession 对象则无法创建 UserSession?

换句话说:我想确保用户不能使用相同的凭据登录两次。

更新:检查小偷答案的评论以找到解决此问题的方法。

4

2 回答 2

3

在您的用户会话控制器中:

    before_filter :require_no_user, :only => [:new, :create]

在您的应用控制器中:

def require_no_user
  if current_user
    store_location
    flash[:notice] = "You must be logged out to access this page"
    redirect_to account_url
    return false
  end
end
于 2009-06-23T16:46:32.970 回答
0

在我看来,更简洁的方法是在 UserSession 类中使用回调。就像,您可以在那里定义一个 before_create 回调,并在适当的情况下将模型标记为无效。不过,我自己还没有尝试过。这是回调模块的文档

于 2009-06-23T17:01:48.443 回答