【发布时间】:2015-04-03 03:58:25
【问题描述】:
所以我知道,如果他们通过 Facebook 进行身份验证,大约有 50 万个问题是关于绕过编辑用户的设计密码要求。我保证我已经阅读了至少 75% 的内容,但仍然无法弄清楚这一点。
基本上,我已经按照Carl Edward & Laurie Laine's SO answer here 为 Devise 创建了一个注册控制器,如果用户正在编辑他们的帐户并且用户从 Facebook 登录,这将允许我绕过密码验证。使用以下代码,它最终不会引发错误,但我更新的属性都没有保存。
class RegistrationsController < Devise::RegistrationsController
def update_resource(resource, params)
if current_user.provider == "facebook"
params.delete("current_password")
resource.update_without_password(params)
else
resource.update_with_password(params)
end
end
def update
account_update_params = devise_parameter_sanitizer.sanitize(:account_update)
# required for settings form to submit when password is left blank
if account_update_params[:password].blank?
account_update_params.delete("password")
account_update_params.delete("password_confirmation")
end
@user = User.find(current_user.id)
if @user.update_attributes(account_update_params)
@user.update(account_update_params)
set_flash_message :notice, :updated
update_resource(@user,account_update_params)
# Sign in the user bypassing validation in case their password changed
sign_in @user, :bypass => true
redirect_to after_update_path_for(@user)
else
render "edit"
end
end
end
我真的不知道我做错了什么,但每次我尝试将我的用户个人资料更新为通过 Facebook 验证的登录用户时,我的个人资料或当我在控制台中查询数据库时都没有任何变化。
【问题讨论】:
-
为什么在@user.update_attributes(account_update_params) 之后调用@user.update(account_update_params)? update_attributes() 只是 update() 的别名。
-
我补充说,因为它不会保存,我认为这可能使它开始保存更新的属性。我会把它拿出来。谢谢!知道为什么它不保存吗?
-
保存用户时在日志中看到了什么?
-
` 用户负载 (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT 1 [["id", 3]] 弃用警告:
#column_for_attribute将为 Rails 5 中不存在的列返回空对象。如果需要检查,请使用#has_attribute?为一个属性的存在。 (从 _app_views_devise_registrations_edit_html_erb___2743138430619144028_70258934707800 中的块调用,位于 views/devise/registrations/edit.html.erb:14)在布局/应用程序中渲染了 devise/registrations/edit.html.erb(19.4 毫秒)完成 200 OK ` -
看起来 account_update_params 哈希中的 smth 使用户对象无效。尝试使用 rails 控制台来找出答案。
标签: ruby-on-rails facebook devise omniauth omniauth-facebook