将omniauth facebook登录到一个弹出窗口 [英] Turn omniauth facebook login into a popup

查看:128
本文介绍了将omniauth facebook登录到一个弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有轨道的omniauth gem,它可以很好地登录用户,但是每当你进入fb登录页面,然后重定向你。我想知道是否有办法做大多数页面的操作,并在弹出窗口中显示fb登录,然后重新加载父div完成。任何想法?

I'm using the omniauth gem with rails and it works great with loging in users, but everytime it takes you to the fb login page then redirects you back. I was wondering if there is a way to do what most pages do and show the fb login in a popup and then reload the parent div once that is complete. Any ideas?

谢谢!

推荐答案

当然可以轻松

在您的看法中:

=link_to "Log in with Facebook", omniauth_authorize_path(:user, :facebook), :class => "popup", :"data-width" => 600, :"data-height" => 400

在您的application.js中:

In your 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;
});

然后在您的回调视图中:

And then in your callback view:

:javascript
  if(window.opener) {
    window.opener.location.reload(true);
    window.close()
  }

这将弹出你的Facebook在一个居中的600x400弹出窗口中,然后当用户从验证返回时,该视图将关闭弹出窗口并刷新父页面。如果用户ctrl-点击链接或没有启用Javascript,它会正常降级。

This'll pop up your Facebook auth in a centered 600x400 popup, then when the user returns from authentication, the view will close the popup and refresh the parent page. It degrades gracefully if a user ctrl-clicks the link, or doesn't have Javascript enabled, too.

这篇关于将omniauth facebook登录到一个弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆