Phi*_*lip 12 redirect login ruby-on-rails devise omniauth
我使用omniauth设计用于登录Facebook用户.我希望在登录之前登录到他们所在的页面后重定向它们.
我用过了
def after_sign_in_path_for(resource_or_scope)
store_location = session[:return_to]
clear_stored_location
(store_location.nil?) ? "/" : store_location.to_s
end
Run Code Online (Sandbox Code Playgroud)
在我的应用程序控制器中,并使用此代码创建了sessions_helper
def deny_access
store_location
redirect_to new_user_session_path
end
def anyone_signed_in?
!current_user.nil?
end
private
def store_location
session[:return_to] = request.fullpath
end
def clear_stored_location
session[:return_to] = nil
end
Run Code Online (Sandbox Code Playgroud)
并解决问题,重定向到"服务/",我有Facebook和其他平台认证的逻辑,我已经使用了
skip_before_filter :store_location
Run Code Online (Sandbox Code Playgroud)
在服务和其他控制器,我不会存储为位置.
Q1我现在遇到的问题是当我使用ajax并在模态窗口中呈现登录表单时,当用户成功登录时,它会被重定向到/ users/sign_in /.我没有用户控制器,并试图创建一个sessions_controller.rb并添加了skip_before ...但它不起作用.
这是我的sign_in路线
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session GET /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
Run Code Online (Sandbox Code Playgroud)
Q2当用户退出时,我尝试使用重定向
def after_sign_out_path_for(resource_or_scope)
(session[:return_to].nil?) ? "/" : session[:return_to].to_s
end
Run Code Online (Sandbox Code Playgroud)
但这只会将我重定向到根页面.
我非常感谢任何帮助,
Dax*_*xon 19
我在这里回答
使用像facebook这样的omniauth提供程序时,Devise不会正确地重定向到存储位置
在application_controller.rb中
def after_sign_in_path_for(resource_or_scope)
if request.env['omniauth.origin']
request.env['omniauth.origin']
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8358 次 |
| 最近记录: |