1
因此,我知道有大约50万个问题绕过编辑用户的设计密码要求,如果他们通过Facebook进行身份验证。我保证我读了至少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(account_update_params)后@ user.update_attributes(account_update_params)? update_attributes()只是update()的别名。 – 2015-04-03 04:27:13
我补充说,因为它不会保存,我认为这可能会使它开始保存更新的属性。我会把它拿出来。谢谢!任何想法为什么它没有保存? – ChiefRockaChris 2015-04-03 04:46:05
保存用户时在日志中看到什么? – 2015-04-03 05:07:27