I'm trying to implement a pop-up window for my RoR project for the login functionality for Twitter. Currently, when you hit login, you are redirected to the authorization page, and then once you've logged in, you're redirected back. I want a pop-up window to come on top of the current browser window and then close after authentication.
This is my sessions controller:
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
I searched around and I see that a Javascript pop-up is the way to do it, so I got this from one of the other StackOverflow questions:
Turn omniauth facebook login into a popup
Where the code for the pop up is as below:
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;
});
And I've done the callback view, but what I don't know is where to put this line:
=link_to "Log in with Facebook", omniauth_authorize_path(:user, :facebook), :class => "popup", :"data-width" => 600, :"data-height" => 400
The class => popup line is supposed to go where we set the Twitter key/secret key, but I don't think that is the right location (Omniauth - Display facebook connect as popup). It didn't work regardless. :/
Any ideas?