Tut*_*teC 3 ruby devise warden ruby-on-rails-3.1 acts-as-paranoid
我有一个Rails 3.1.3应用程序,devise用于用户身份验证和软删除它们acts_as_paranoid.我希望在密码重新创建,用户注册和用户登录时取消删除帐户,因此如果他们提供已删除的电子邮件,我会抓取该帐户,重新启用该帐户,然后继续操作(密码重新创建或登录) ).
但是在Users::SessionsController#create操作中,在用户取消删除后,它会收到一个未经授权的错误(但用户现在应该可见).代码是:
def create
# Take into account acts_as_paranoid deleted users
resource = resource_class.only_deleted.find_by_email(params[resource_name][:email])
resource.undelete! if resource
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_in_path_for(resource)
end
Run Code Online (Sandbox Code Playgroud)
如果我resource.reload在取消删除后添加一个电话,它不会改变任何东西.如果我再次登录,用户通常会登录,因为它在之前的尝试中未被删除.
为什么会这样?如何通过一次create通话取消删除并登录?
解决了以下代码片段:
def create
# Take into account acts_as_paranoid deleted users
if (resource = resource_class.only_deleted.find_by_email(params[resource_name][:email]))
resource.undelete!
# Copied from Warden::Strategies database_authenticatable:
sign_in resource if resource.valid_password?(params[resource_name][:password])
end
super
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2477 次 |
| 最近记录: |