From: Tomas Sedovic tsedovic@redhat.com
https://bugzilla.redhat.com/show_bug.cgi?id=726779
This handles two issues with our login-over-javascript situation.
The first was a broken UI when the error message was unexpectedly a HTML page instead of a single text response that we set on entering bad credentials.
This could happen if the Rails app or Apache returned a 5xx error when the user tried to log in.
The second was not being able to get through the login page if the user has already signed in in another tab. --- src/app/controllers/user_sessions_controller.rb | 2 +- src/app/views/user_sessions/new.haml | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/app/controllers/user_sessions_controller.rb b/src/app/controllers/user_sessions_controller.rb index d8baf72..8ade923 100644 --- a/src/app/controllers/user_sessions_controller.rb +++ b/src/app/controllers/user_sessions_controller.rb @@ -37,7 +37,7 @@ class UserSessionsController < ApplicationController flash[:notice] = "Login successful!" redirect_back_or_default root_url end - format.js { render :text => "window.location='#{root_url}'" } + format.js { render :status => 201, :text => root_url } end else respond_to do |format| diff --git a/src/app/views/user_sessions/new.haml b/src/app/views/user_sessions/new.haml index 3ef9eb3..ee8b409 100644 --- a/src/app/views/user_sessions/new.haml +++ b/src/app/views/user_sessions/new.haml @@ -23,8 +23,13 @@ $.ajax({ url: this.action, type: 'POST', - dataType: 'script', + accepts: { html: "application/javascript" }, + dataType: 'html', data: form_data, + success: function(data, textStatus, jqXHR) { + if(jqXHR.status === 201) window.location = data; + else window.location.reload(); + }, error: function(response) { //TODO: for some reason error connection errors are not handled by 'error' callback, //what's worse jquery sets 'textStatus' to success, if we want to catch connection errors @@ -32,7 +37,8 @@ $('#error-content').remove(); $('#primary-container').prepend('<div id="error-content" class="error" style="opacity: 0; position: relative;"></div>'); var text = $.isEmptyObject(response.responseText) ? response.statusText : response.responseText; - $('#error-content').html('<p class="text">' + text + '</div>'); + if(response.status !== 401) text = "Internal Server Error"; + $('#error-content').html('<p class="text">' + text + '</p>'); $('#error-content').animate({ 'opacity': 1, 'top': -10 },{queue:false,duration:150}); $('#progress-indicator').hide(); $('#login input').each(function(){ $(this).removeAttr('disabled'); });
ACK
On 08/04/2011 04:41 PM, tsedovic@redhat.com wrote:
From: Tomas Sedovictsedovic@redhat.com
https://bugzilla.redhat.com/show_bug.cgi?id=726779
This handles two issues with our login-over-javascript situation.
The first was a broken UI when the error message was unexpectedly a HTML page instead of a single text response that we set on entering bad credentials.
This could happen if the Rails app or Apache returned a 5xx error when the user tried to log in.
The second was not being able to get through the login page if the user has already signed in in another tab.
src/app/controllers/user_sessions_controller.rb | 2 +- src/app/views/user_sessions/new.haml | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/app/controllers/user_sessions_controller.rb b/src/app/controllers/user_sessions_controller.rb index d8baf72..8ade923 100644 --- a/src/app/controllers/user_sessions_controller.rb +++ b/src/app/controllers/user_sessions_controller.rb @@ -37,7 +37,7 @@ class UserSessionsController< ApplicationController flash[:notice] = "Login successful!" redirect_back_or_default root_url end
format.js { render :text => "window.location='#{root_url}'" }
format.js { render :status => 201, :text => root_url } end else respond_to do |format|
diff --git a/src/app/views/user_sessions/new.haml b/src/app/views/user_sessions/new.haml index 3ef9eb3..ee8b409 100644 --- a/src/app/views/user_sessions/new.haml +++ b/src/app/views/user_sessions/new.haml @@ -23,8 +23,13 @@ $.ajax({ url: this.action, type: 'POST',
dataType: 'script',
accepts: { html: "application/javascript" },
dataType: 'html', data: form_data,
success: function(data, textStatus, jqXHR) {
if(jqXHR.status === 201) window.location = data;
else window.location.reload();
}, error: function(response) { //TODO: for some reason error connection errors are not handled by 'error' callback, //what's worse jquery sets 'textStatus' to success, if we want to catch connection errors
@@ -32,7 +37,8 @@ $('#error-content').remove(); $('#primary-container').prepend('<div id="error-content" class="error" style="opacity: 0; position: relative;"></div>'); var text = $.isEmptyObject(response.responseText) ? response.statusText : response.responseText;
$('#error-content').html('<p class="text">' + text +'</div>');
if(response.status !== 401) text = "Internal Server Error";
$('#error-content').html('<p class="text">' + text +'</p>'); $('#error-content').animate({ 'opacity': 1, 'top': -10 },{queue:false,duration:150}); $('#progress-indicator').hide(); $('#login input').each(function(){ $(this).removeAttr('disabled'); });
aeolus-devel@lists.fedorahosted.org