From e2c73573b781da07c68447fad2e482fe42c6b9b4 Mon Sep 17 00:00:00 2001 From: Cameron Hurst Date: Sun, 1 May 2011 17:31:08 -0400 Subject: [PATCH] Fixed handling of no logged in user on IGN. Fixed error from previous hack. --- oa-more/lib/omniauth/strategies/ign.rb | 36 +++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/oa-more/lib/omniauth/strategies/ign.rb b/oa-more/lib/omniauth/strategies/ign.rb index acefaca..27e3675 100644 --- a/oa-more/lib/omniauth/strategies/ign.rb +++ b/oa-more/lib/omniauth/strategies/ign.rb @@ -25,7 +25,7 @@ module OmniAuth protected def request_phase - OmniAuth::Page.build(:title => 'IGN Authentication', :hostname=>@hostname) do + OmniAuth::Form.build(:title => 'IGN Authentication', :header_info=>js) do label_field('Identifying you with the IGN server', IDENTIFIER_URL_PARAMETER) end.to_response end @@ -54,6 +54,40 @@ module OmniAuth 'nickname' => request.params["username"], } end + + def js + @js = <<-JS + $(document).ready(function() { + $.ajax({ + url: "http://#{@hostname}/users/current.json?callback=z33k", + type: "get", + dataType:"jsonp", + success: function(data) { + if(typeof data.error == 'undefined'){ + // There is a current My IGN user + var username = data.my_ign_username; + var signature = data.signature; + var timestamp = data.timestamp; + window.location = "/auth/ign/callback?username=" +username+"&signature="+signature+"×tamp=" + timestamp; + } + else{ + nouser(); + } + } + }); + return false; + }); + function nouser() { + var url = "http://my.ign.com/login?r="+window.location; + top.location = url; + window.location = url; + } + JS + "\n" + + "\n" + + "\n" + end + end end end \ No newline at end of file