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