Ruby on rails 整合邪恶、设计和Omniauth Facebook
我正在开发一个应用程序,使用我在本文标题中写的这三个gem。我使用可确认模块(?)设置了designe,因此当用户使用其电子邮件/密码创建帐户时,它会收到一封确认电子邮件。如果用户注册facebook(使用omniauth facebook gem),Desive将跳过确认步骤 在user.rb中Ruby on rails 整合邪恶、设计和Omniauth Facebook,ruby-on-rails,ruby,devise,omniauth,wicked-gem,Ruby On Rails,Ruby,Devise,Omniauth,Wicked Gem,我正在开发一个应用程序,使用我在本文标题中写的这三个gem。我使用可确认模块(?)设置了designe,因此当用户使用其电子邮件/密码创建帐户时,它会收到一封确认电子邮件。如果用户注册facebook(使用omniauth facebook gem),Desive将跳过确认步骤 在user.rb中 "Of course the :confirmable is active in the model" ... # Omniauth-facebook def sel
"Of course the :confirmable is active in the model"
...
# Omniauth-facebook
def self.find_for_facebook_oauth(auth)
where(auth.slice(:provider, :uid)).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.email = auth.info.email
user.password = Devise.friendly_token[0,20]
user.first_name = auth.info.first_name
user.last_name = auth.info.last_name
user.skip_confirmation!
# user.image = auth.info.image # assuming the user model has an image
end
end
...
当我为巫师添加邪恶宝石时,事情发生了。我配置了路由文件
在routes.rb中
MyApp::Application.routes.draw do
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks",
:registrations => "registrations" }
root 'home#index'
# Registration wizard routes
resources :after_register
end
我创建了一个注册控制器来覆盖Desive注册方法
class RegistrationsController < Devise::RegistrationsController
def create
super
end
protected
def after_sign_in_path_for(resource)
puts "<<<<<<<<<<<<<<<< SIGN IN"
after_register_path(:import_contacts)
end
def after_sign_up_path_for(resource)
puts "<<<<<<<<<<<<<<<< SIGN UP ACTIVE"
after_register_path(:import_contacts)
end
def after_inactive_sign_up_path_for(resource)
puts "<<<<<<<<<<<<<<<< SIGN IN INACTIVE"
after_register_path(:import_contacts)
end
end
类注册控制器 放置“如果一切都是按常规方式配置的(而且我看到的看起来很标准),然后使用Facebook登录将根本不会通过RegistrationController
进行。它将通过OmniauthCallbacks
控制器进行登录,您还没有发布代码。这取决于他们通过Facebook登录时您在那里做了什么。我假设您有一个Facebook()
方法,该方法调用用户。查找\u for facebook\u oauth(auth)
。然后您是否只是将其登录,而不是转到注册控制器
?如果是这样,则不会触摸注册控制器
,因此在
的路径中对其进行签名后覆盖的,将不会产生任何效果
如果您希望在为
在路径中签名后覆盖的在整个应用程序中生效,您可以在应用程序控制器
中定义它。如果您只希望它在您的OmniAuthCallbackController
中生效,您可以在那里定义它。在任何情况下,他们每次登录usin时都会点击它g Facebook(如果您将其放入ApplicationController
,每次有人使用任何方法登录时),因此您需要跟踪他们已经通过向导的情况,假设您希望确保这只在他们第一次登录时发生。如果您正在使用Desive:trackable模块,可能需要检查user.sign\u in\u计数,或者您可以通过其他方法轻松检查他们是否已通过向导已经通过向导了
有关评论问题的更新:
您的第一个问题:“假设我在ApplicationController中放置了after_sign_in_path_fot,我应该删除RegistrationController中的after_inactive_sign_up_path_方法,对吗?“这取决于你想要什么样的行为。使用您的问题中的RegistrationController
,在他们注册后和确认电子邮件之前,它将转到向导(因为在本例中将调用的ApplicationController
中的
路径中的
的登录后将再次将他们发送到向导。所以,是的,如果您只是想在登录后使用向导,请从注册控制器中删除inactive。然后可能不需要在注册控制器中注册(资源)后调用,因为designe中的默认实现只是在注册(资源)
后调用。无论如何,如果由于RegistrationController.create()的默认实现中的逻辑,您总是需要确认,那么在注册之后将不会调用path\u for()
-需要确认将导致resource.active\u for\u authentication?
返回false,从而导致调用after\u inactive\u sign\u path\u for(resource)
对于第二条评论中的问题,您说“如果我删除应用程序控制器路径中的后签名”-我想您的意思是RegistrationController
?如果这是正确的,那么是的,在您覆盖的RegistrationsController
版本中不需要任何方法(如果这是您在问题中粘贴的整个控制器),因为您的create()
只调用super
,
的after\u-sign\u-in\u-path\u将位于ApplicationController
中,并且您可能不希望上述的after\u(非活动)\u-sign\u-up\u-path\u用于方法。因此,是的,您不需要注册控制器。您可以完全删除它并删除routes.rb中的:registrations=>“registrations”
-然后将再次使用registrations controller
的设计实现
然后您会说“只需覆盖ApplicationController中RegistrationController的方法?”。从RegistrationController
剩下的唯一方法是在ApplicationController
中为(资源)
在路径中签名后使用,因此我认为RegistrationController
中不会有任何您在ApplicationController
中需要的其他方法。如果我错过了您的要求或做出了错误的假设,请告诉我。谢谢您的回答!是的,我发现RegistrationsController与facebook登录无关。我找到了一个解决方案,但它看起来比你的更脏(你的绝对更好)。我在用户模型中使用了一个新字段作为标志(它的作用与注册计数完全相同),然后在OmniauthCallbacks中的facebook方法中调用@user.update\u属性(:flag,true)。假设我在ApplicationController中将after_sign_in_path_fot放在ApplicationController中,我应该删除RegistrationController中的after_inactive_sign_up_path_方法,对吗?谢谢另一个问题。如果我在应用程序控制器的路径中删除after\u sign\u,则其内部将没有任何方法。那个么routes.rb中的:registrations=>“registrations”会发生什么呢?是吗
class AfterRegisterController < ApplicationController
include Wicked::Wizard
before_filter :authenticate_user!
steps :import_contacts, :select_agents, :wish_form
def show
@user = current_user
render_wizard
end
def update
@user = current_user
@user.attributes = params[:user]
render_wizard @user
end
end