Rails - 如何为omniauth用户重写Devise'当前密码'
我以前见过这个帖子,但还没有找到适合我的解决方案。Rails - 如何为omniauth用户重写Devise'当前密码'
我曾尝试下面的设计的Wiki,并试图通过他人建议的代码添加到控制器: Editing Users With Devise and Omniauth [Rails]update_without_password does't update user info https://github.com/plataformatec/devise/issues/1620
问题是,通过我们的Twitter Omniauth用户注册后无法更新他们的账户信息,因为设计提示他们的'当前密码'进行更改。通过电子邮件向用户发送随机生成的密码不是一种选择。
我想做什么 -
我想覆盖设计控制器的“更新”方法使其能够识别一个Twitter用户编辑自己的详细信息在第一时间,并允许他们跳过“当前密码”验证。我们为Twitter用户分配一个标准的电子邮件地址,该地址可以是它检查的变量。如果不更改,他们将无法提交。
仍是问题 -
我试过在登记控制器不同的代码块,但我还是很正从一个错误,当前密码不正确重定向回。我甚至没有进入binding.pry,所以它看起来像甚至没有被读取的方法?
我已经尝试彻底删除'当前密码'的表单输入,并将其隐藏传递给默认值。
谢谢你的帮助!
路线
Rails.application.routes.draw do
ActiveAdmin.routes(self)
# devise_for :users,
devise_for :users, controllers: { registrations: 'registrations' },
controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
scope '(:locale)', locale: /en|ca|es/ do
resources :politicians
resources :posts do
resources :comments, only:[:new, :create, :edit, :update, :destroy]
member do
put "like", to: "posts#upvote"
put "dislike", to: "posts#downvote"
end
end
get "/about" => "pages#about_us"
root to: 'pages#home'
end
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
Registrations_Controller.rb
class Users::RegistrationsController < Devise::RegistrationsController
protected
def update_resource(resource, params)
binding.pry
if current_user.email.include?("email.com")
params.delete("current_password")
resource.update_without_password(params)
else
resource.update_with_password(params)
end
end
end
你要创建一个类似这一个在您注册的控制器的方法:
def update_resource(resource, params)
resource.update_without_password(params)
end
Devise提供了一个非常好的深入wiki文章,允许用户在不输入密码here的情况下更新其帐户信息。
嗨thisischuck, 感谢您的答复。我跟着那里的步骤,但不幸的是我回到了表单'我们需要你目前的密码来确认你的变化''的错误信息。 不知道我错过了什么 – dan101
请确保您重新启动服务器并设置您的参数,以便它不查找密码确认字段。 – thisischuck
[编辑用户设计和Omniauth]的可能的复制(https://*.com/questions/13436232/editing-users-with-devise-and-omniauth) – Gerry