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)。無論如何,它都不起作用。 :/
任何想法?