1
我正在尝试为Twitter的登录功能实现我的RoR项目的弹出窗口。目前,当您登录时,您会被重定向到授权页面,然后一旦您登录,您就会被重定向回去。我想要一个弹出窗口在当前浏览器窗口的顶部,然后在验证后关闭。Twitter登录的弹出窗口
这是我的会话控制器:
def create
auth_hash = request.env['omniauth.auth']
@user = User.find_by_user_id(auth_hash["uid"])
if @user
@authorization = @user.authorization
flash.now[:notice] = "Welcome back #{@user.name}! You have already signed up."
session[:user_id] = auth_hash["uid"].to_i
else
@user = User.new :name => auth_hash["info"]["name"], :user_name => auth_hash["info"]["nickname"], :user_id => auth_hash["uid"], :profile_image_url => auth_hash["info"]["image"].sub("_normal", "")
@user.build_authorization :secret => auth_hash['credentials']['secret'], :token => auth_hash['credentials']['token']
@user.build_preference
@user.save!
@user.errors.each do |error|
puts error
end
flash.now[:notice] = "Hi #{@user.name}! You've signed up."
session[:user_id] = auth_hash["uid"].to_i
end
redirect_to :root
end
def logout
session[:user_id] = nil
redirect_to :root
end
def failure
render :text => "Sorry, but you didn't allow access to our app!"
end
def destroy
@user = current_user
if @user
@user.destroy
end
redirect_to :root
end
end
我搜索周围,我看到的是一个Javascript弹出是做它的方式,所以我得到这个从其他StackOverflow的问题之一:
Turn omniauth facebook login into a popup
凡弹出代码如下:
function popupCenter(url, width, height, name) {
var left = (screen.width/2)-(width/2);
vartop = (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;
});
而且我已经做了回调的观点,但我不知道是在哪里,就把这行:
=link_to "Log in with Facebook", omniauth_authorize_path(:user, :facebook), :class => "popup", :"data-width" => 600, :"data-height" => 400
类=>弹出线应该去的地方,我们设置了Twitter的键/秘密关键,但我不认为这是正确的位置(Omniauth - Display facebook connect as popup)。无论如何,它都不起作用。 :/
任何想法?