2014-10-08 15:36:47 -04:00
|
|
|
"use strict";
|
2015-02-25 19:09:39 -05:00
|
|
|
/* global define, app, translator, config, RELATIVE_PATH */
|
2014-10-08 15:36:47 -04:00
|
|
|
|
2014-11-18 14:54:54 -05:00
|
|
|
define('forum/login', ['csrf'], function(csrf) {
|
2014-10-08 15:36:47 -04:00
|
|
|
var Login = {};
|
|
|
|
|
|
|
|
|
|
Login.init = function() {
|
|
|
|
|
var errorEl = $('#login-error-notify'),
|
|
|
|
|
submitEl = $('#login'),
|
|
|
|
|
formEl = $('#login-form');
|
|
|
|
|
|
|
|
|
|
submitEl.on('click', function(e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
if (!$('#username').val() || !$('#password').val()) {
|
|
|
|
|
translator.translate('[[error:invalid-username-or-password]]', function(translated) {
|
2014-11-18 14:54:54 -05:00
|
|
|
errorEl.find('p').text(translated);
|
2014-10-08 15:36:47 -04:00
|
|
|
errorEl.show();
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
errorEl.hide();
|
|
|
|
|
|
|
|
|
|
if (!submitEl.hasClass('disabled')) {
|
|
|
|
|
submitEl.addClass('disabled');
|
2014-11-18 14:54:54 -05:00
|
|
|
formEl.ajaxSubmit({
|
|
|
|
|
headers: {
|
|
|
|
|
'x-csrf-token': csrf.get()
|
|
|
|
|
},
|
|
|
|
|
success: function(data, status) {
|
|
|
|
|
window.location.href = data;
|
|
|
|
|
},
|
|
|
|
|
error: function(data, status) {
|
|
|
|
|
translator.translate(data.responseText, config.defaultLang, function(translated) {
|
2015-02-25 19:09:39 -05:00
|
|
|
errorEl.find('p').text(translated);
|
2014-11-18 14:54:54 -05:00
|
|
|
errorEl.show();
|
|
|
|
|
submitEl.removeClass('disabled');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-10-08 15:36:47 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#login-error-notify button').on('click', function(e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
errorEl.hide();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#content #username').focus();
|
2014-10-14 11:48:16 -04:00
|
|
|
|
|
|
|
|
// Add "returnTo" data if present
|
|
|
|
|
if (app.previousUrl) {
|
|
|
|
|
var returnToEl = document.createElement('input');
|
|
|
|
|
returnToEl.type = 'hidden';
|
|
|
|
|
returnToEl.name = 'returnTo';
|
2014-12-03 22:29:56 -05:00
|
|
|
returnToEl.value = app.previousUrl;
|
2014-10-14 11:48:16 -04:00
|
|
|
$(returnToEl).appendTo(formEl);
|
|
|
|
|
}
|
2014-10-08 15:36:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return Login;
|
|
|
|
|
});
|