[英]How do I have devise / omniauth redirect to the page from which I signed in from?
[英]How to redirect a user signed up with omniauth (Rails with Devise) to a specific page?
嗨,我只是按照以下教程在我的應用中為Facebook和Google設置了omniauth: http : //sourcey.com/rails-4-omniauth-using-devise-with-twitter-facebook-and-linkedin/這是我的OmniauthCallbacksController:
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def self.provides_callback_for(provider)
class_eval %Q{
def #{provider}
@user = User.find_for_oauth(env["omniauth.auth"], current_user)
if @user.persisted?
sign_in_and_redirect @user, event: :authentication
set_flash_message(:notice, :success, kind: "#{provider}".gsub(/_/," ").split[0...1].join(' ').capitalize) if is_navigational_format?
else
session["devise.#{provider}_data"] = env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
}
end
[:google_oauth2, :facebook].each do |provider|
provides_callback_for provider
end
def after_sign_in_path_for(resource)
#if resource.email_verified?
super resource
#else
# finish_signup_path(resource)
#end
end
# def google_oauth2
# raise request.env["omniauth.auth"]
# end
end
我想將所有已使用facebook或google注冊(未登錄,注冊新帳戶)的用戶重定向到其用戶個人資料頁面,並發出一條通知,要求他們更改用戶名,因為我將電子郵件設置為注冊。 我怎樣才能做到這一點?
在此行之后sign_in_and_redirect @user, event: :authentication
您可以添加一個使用omniauth注冊該用戶的cookie值。
cookies[:oA] = true
在after_sign_in_path_for(resource)
方法中,檢查cookie的值是否為true,例如,添加路徑username_path(resource)
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.