VRFS-1849: Check for google authorization using AJAX and show/hide the google login button / "signed in" label as appropriate:

This commit is contained in:
Steven Miers 2014-11-06 13:16:58 -06:00
parent f1b32336cd
commit 7dc80c10ce
5 changed files with 33 additions and 6 deletions

View File

@ -42,7 +42,7 @@
}
.google_login_button {
vertical-align: middle;
}
.signed_in_to_google {

View File

@ -150,6 +150,10 @@ class SessionsController < ApplicationController
render 'oauth_complete', :layout => "landing"
end
def has_google_auth
render :json => {has_google_auth: (!!current_user && !!UserAuthorization.google_auth(current_user).first)}
end
def redirect_after_signin(default)
redirect_to(params['redirect-to'].blank? ? default : params['redirect-to'])
end

View File

@ -30,6 +30,7 @@
<% else %>
<%= render "layouts/social_meta" %>
<% end %>
<%= yield(:extra_js) %>
</head>
<body class="jam" data-client-type="<%= @nativeClient ? 'client' : 'browser' %>">
<%= yield %>

View File

@ -1,5 +1,26 @@
-google_auth = (current_user.nil?) ? nil : JamRuby::UserAuthorization.google_auth(current_user).first
-if google_auth
span.signed_in_to_google="(Signed in)"
-else
input.google_login_button type='image' onclick='window._oauth_win = window.open("/auth/google_login", "_blank", "height=500,width=500,menubar=no,resizable=no,status=no");' src="/assets/google_signin.png" height="30px"
-content_for :extra_js do
javascript:
// Check for google authorization using AJAX and show/hide the
// google login button / "signed in" label as appropriate:
$(window).on('focus', function() {
$.ajax({
type: "GET",
dataType: "json",
url: "/auth/has_google_auth"
}).success(function(data) {
if(data.has_google_auth) {
$("input.google_login_button").addClass("hidden")
$("span.signed_in_to_google").removeClass("hidden")
if (window._oauth_win) {
window._oauth_win.close()
}
} else {
$("span.signed_in_to_google").addClass("hidden")
$("input.google_login_button").removeClass("hidden")
}
})
});
-google_auth = (current_user.nil?) ? nil : !!JamRuby::UserAuthorization.google_auth(current_user).first
span.signed_in_to_google class=((!google_auth) ? "hidden" : "") ="(Signed in)"
input.google_login_button class=((google_auth) ? "hidden" : "") type='image' onclick='window._oauth_win = window.open("/auth/google_login", "_blank", "height=500,width=500,menubar=no,resizable=no,status=no");' src="/assets/google_signin.png" height="30px"

View File

@ -30,6 +30,7 @@ SampleApp::Application.routes.draw do
# oauth
match '/auth/:provider/callback', :to => 'sessions#oauth_callback'
match '/auth/failure', :to => 'sessions#failure'
match '/auth/has_google_auth', :to => 'sessions#has_google_auth'
# session info page
match '/sessions/:id/details' => 'music_sessions#session_info', :via => :get, :as => 'music_scheduled_session_detail'