我将 omniauth gem 与 rails 一起使用,它非常适合登录用户,但每次它都会将您带到 fb 登录页面,然后将您重定向回来。我想知道是否有一种方法可以做大多数页面所做的事情,并在弹出窗口中显示 fb 登录,然后在完成后重新加载父 div。有什么想法吗?
谢谢!
最佳答案
当然,你可以很容易。
在你看来:
=link_to "Log in with Facebook", omniauth_authorize_path(:user, :facebook), :class => "popup", :"data-width" => 600, :"data-height" => 400
在你的 application.js 中:
function popupCenter(url, width, height, name) {
var left = (screen.width/2)-(width/2);
var top = (screen.height/2)-(height/2);
return window.open(url, name, "menubar=no,toolbar=no,status=no,width="+width+",height="+height+",toolbar=no,left="+left+",top="+top);
}
$("a.popup").click(function(e) {
popupCenter($(this).attr("href"), $(this).attr("data-width"), $(this).attr("data-height"), "authPopup");
e.stopPropagation(); return false;
});
然后在你的回调 View 中:
:javascript
if(window.opener) {
window.opener.location.reload(true);
window.close()
}
这将在居中的 600x400 弹出窗口中弹出您的 Facebook 身份验证,然后当用户从身份验证返回时, View 将关闭弹出窗口并刷新父页面。如果用户按住 Ctrl 并单击链接,或者也没有启用 Javascript,它会正常降级。
关于ruby-on-rails - 将 omniauth facebook 登录变成弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4491433/