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:
parent
f1b32336cd
commit
7dc80c10ce
|
|
@ -42,7 +42,7 @@
|
|||
}
|
||||
|
||||
.google_login_button {
|
||||
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.signed_in_to_google {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
<% else %>
|
||||
<%= render "layouts/social_meta" %>
|
||||
<% end %>
|
||||
<%= yield(:extra_js) %>
|
||||
</head>
|
||||
<body class="jam" data-client-type="<%= @nativeClient ? 'client' : 'browser' %>">
|
||||
<%= yield %>
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
Loading…
Reference in New Issue