【问题标题】:How do I impersonate a user with AuthLogic如何使用 AuthLogic 模拟用户
【发布时间】:2009-08-18 10:18:15
【问题描述】:

我需要能够在没有解密密码的情况下创建 UserSession。

我该怎么做?

我目前的解决方法是:

在user.rb中

def valid_crypted_or_non_crypted_password?(password) 
   valid_password?(password) || password == crypted_password
end

在 user_session.rb 中

verify_password_method :valid_crypted_or_non_crypted_password?

登录

UserSession.create(:login => u.login, :password => u.crypted_password) 

有没有更好的方法来做到这一点?

【问题讨论】:

  • 为什么没有解密密码?您不能在此之前使用工厂创建用户并明确密码吗?
  • 不,在这种情况下,我希望我的管理员冒充其他用户浏览网站。或者在打开 id 的情况下,我有用户记录,但密码是加密的

标签: ruby-on-rails ruby authlogic


【解决方案1】:

根据the documentation,您可以将用户对象传递给UserSession.create

UserSession.create(@some_user)

我还没试过。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-03
  • 2021-06-09
相关资源
最近更新 更多