各网站可以正常登录,但是但是跳转怎么也不能跳回原路径
我做的是自动登录,判断是微信浏览器,自动调用 weixin 的 Omniauth
def check_login
if is_from_Weixin?
redirect_to user_omniauth_authorize_path(provider: :weixin)
else
authenticate_user!
end
end
authenticate_user! 是可以跳转到原路径,是不是我还有什么没有设置
求大神支招
application_controller.rb 的 after_sign_in_path_for:
def after_sign_in_path_for resource
if resource.is_a?(User) && resource.respond_to?(:blocked?) && resource.blocked?
sign_out resource
flash[:alert] = "Your account is blocked. Retry when an admin has unblocked it."
new_user_session_path
else
request.env['omniauth.origin'] || stored_location_for(resource) || root_path
end
end
在 app/controller 增加了 omniauth_callbacks_controller.rb
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def weixin
@user = User.find_for_oauth_user(request.env["omniauth.auth"], current_user)
if @user
sign_in_and_redirect @user, :event => :authentication
else
session["devise.weixin_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end