diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2014-02-20 18:05:16 +0100 |
---|---|---|
committer | Petr Vobornik <pvoborni@redhat.com> | 2014-04-15 12:41:54 +0200 |
commit | 937533c48e27c5a8d4d63978d32990451a10a36a (patch) | |
tree | 22c710970e69f1ea3196306d3d33a3e220830b7b /install/ui/src/freeipa/ipa.js | |
parent | 2ec5d969a27b91b04a2b424d93800e68a77aa6e8 (diff) | |
download | freeipa-937533c48e27c5a8d4d63978d32990451a10a36a.tar.gz freeipa-937533c48e27c5a8d4d63978d32990451a10a36a.tar.xz freeipa-937533c48e27c5a8d4d63978d32990451a10a36a.zip |
webui: use asynchronous call for authentication
Change `IPA.login_password` and `IPA.get_credentials` to use async AJAX
and to return promise instead of blocking the code.
IPA.get_credentials is still partially blocking because of negotiate process.
We can't do anything about that.
It allows activity indicators to do their job.
https://fedorahosted.org/freeipa/ticket/3903
Reviewed-By: Adam Misnyovszki <amisnyov@redhat.com>
Diffstat (limited to 'install/ui/src/freeipa/ipa.js')
-rw-r--r-- | install/ui/src/freeipa/ipa.js | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/install/ui/src/freeipa/ipa.js b/install/ui/src/freeipa/ipa.js index a44d60b24..c0136811a 100644 --- a/install/ui/src/freeipa/ipa.js +++ b/install/ui/src/freeipa/ipa.js @@ -23,6 +23,7 @@ */ define([ + 'dojo/Deferred', 'dojo/keys', 'dojo/topic', './jquery', @@ -36,8 +37,8 @@ define([ './rpc', './text', 'exports' - ], function(keys, topic, $, JSON, i18n, auth, datetime, metadata_provider, - builder, reg, rpc, text, exports) { + ], function(Deferred, keys, topic, $, JSON, i18n, auth, datetime, + metadata_provider, builder, reg, rpc, text, exports) { /** * @class @@ -366,28 +367,30 @@ IPA.object = function(s) { */ IPA.get_credentials = function() { var status; + var d = new Deferred(); function error_handler(xhr, text_status, error_thrown) { - status = xhr.status; + d.resolve(xhr.status); + IPA.hide_activity_icon(); } function success_handler(data, text_status, xhr) { - status = xhr.status; auth.current.set_authenticated(true, 'kerberos'); + d.resolve(xhr.status); + IPA.hide_activity_icon(); } var request = { url: IPA.login_url, cache: false, - async: false, type: "GET", success: success_handler, error: error_handler }; - + IPA.display_activity_icon(); $.ajax(request); - return status; + return d.promise; }; /** @@ -415,6 +418,7 @@ IPA.logout = function() { } function success_handler(data, text_status, xhr) { + IPA.hide_activity_icon(); if (data && data.error) { show_error(data.error.message); } else { @@ -423,6 +427,7 @@ IPA.logout = function() { } function error_handler(xhr, text_status, error_thrown) { + IPA.hide_activity_icon(); if (xhr.status === 401) { reload(); } else { @@ -441,7 +446,7 @@ IPA.logout = function() { success: success_handler, error: error_handler }; - + IPA.display_activity_icon(); $.ajax(request); }; @@ -456,14 +461,18 @@ IPA.logout = function() { IPA.login_password = function(username, password) { var result = 'invalid'; + var d = new Deferred(); function success_handler(data, text_status, xhr) { + IPA.hide_activity_icon(); result = 'success'; auth.current.set_authenticated(true, 'password'); + d.resolve(result); } function error_handler(xhr, text_status, error_thrown) { + IPA.hide_activity_icon(); if (xhr.status === 401) { var reason = xhr.getResponseHeader("X-IPA-Rejection-Reason"); @@ -473,6 +482,7 @@ IPA.login_password = function(username, password) { result = reason; } } + d.resolve(result); } var data = { @@ -486,7 +496,6 @@ IPA.login_password = function(username, password) { contentType: 'application/x-www-form-urlencoded', processData: true, dataType: 'html', - async: false, type: 'POST', success: success_handler, error: error_handler @@ -494,9 +503,8 @@ IPA.login_password = function(username, password) { IPA.display_activity_icon(); $.ajax(request); - IPA.hide_activity_icon(); - return result; + return d.promise; }; /** |