You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.4 KiB
JavaScript

define(function() {
var Login = {};
Login.init = function() {
$('#login').on('click', function() {
var loginData = {
'username': $('#username').val(),
'password': $('#password').val(),
'remember': $('#remember').prop('checked'),
'_csrf': $('#csrf-token').val()
};
$('#login').attr('disabled', 'disabled').html('Logging in...');
$('#login-error-notify').hide();
$.ajax({
type: "POST",
url: RELATIVE_PATH + '/login',
data: loginData,
success: function(data, textStatus, jqXHR) {
$('#login').html('Redirecting...');
if(!app.previousUrl) {
app.previousUrl = '/';
}
if(app.previousUrl.indexOf('/reset/') !== -1) {
window.location.replace(RELATIVE_PATH + "/?loggedin");
} else {
var index = app.previousUrl.indexOf('#');
if(index !== -1) {
window.location.replace(app.previousUrl.slice(0, index) + '?loggedin' + app.previousUrl.slice(index));
} else {
window.location.replace(app.previousUrl + "?loggedin");
}
}
app.loadConfig();
},
error: function(data, textStatus, jqXHR) {
$('#login-error-notify').show();
$('#login').removeAttr('disabled').html('Login');
},
dataType: 'json',
async: true
});
return false;
});
$('#login-error-notify button').on('click', function() {
$('#login-error-notify').hide();
return false;
});
$('#content #username').focus();
};
return Login;
});