Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10807 from mrclay/10805_login
chore(js): improves ajax login workflow
- Loading branch information
Showing
3 changed files
with
37 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,32 @@ | ||
define(['jquery', 'elgg', 'elgg/Ajax'], function($, elgg, Ajax) { | ||
var ajax = new Ajax(); | ||
|
||
define(function(require) { | ||
var $ = require('jquery'); | ||
var elgg = require('elgg'); | ||
var Ajax = require('elgg/Ajax'); | ||
var spinner = require('elgg/spinner'); | ||
|
||
// manage Spinner manually | ||
var ajax = new Ajax(false); | ||
|
||
$(document).on('submit', '.elgg-form-login', function(e) { | ||
var $form = $(this); | ||
|
||
spinner.start(); | ||
ajax.action($form.prop('action'), { | ||
data: ajax.objectify($form) | ||
}).success(function(json, status, xhr) { | ||
if (typeof json.forward !== 'undefined') { | ||
}).done(function(json, status, jqXHR) { | ||
if (jqXHR.AjaxData.status == -1) { | ||
$('input[name=password]', $form).val('').focus(); | ||
spinner.stop(); | ||
return; | ||
} | ||
|
||
if (json && (typeof json.forward === 'string')) { | ||
elgg.forward(json.forward); | ||
} else if (json === '') { | ||
// BC fallback if action did not return a forward url | ||
// elgg_ok_response will have the forward url | ||
// elgg_error_response will have the error text | ||
// everything else is unknown, so forward | ||
elgg.forward(); | ||
} else { | ||
elgg.forward(); | ||
} | ||
}); | ||
|
||
e.preventDefault(); | ||
}); | ||
}); |