2013-10-03 15:04:25 -04:00
|
|
|
define(function() {
|
|
|
|
|
var Login = {};
|
|
|
|
|
|
2013-12-28 13:11:49 -05:00
|
|
|
Login.init = function() {
|
2013-10-03 15:04:25 -04:00
|
|
|
$('#login').on('click', function() {
|
|
|
|
|
var loginData = {
|
|
|
|
|
'username': $('#username').val(),
|
|
|
|
|
'password': $('#password').val(),
|
2014-01-31 15:27:13 -05:00
|
|
|
'remember': $('#remember').prop('checked'),
|
2013-10-03 15:04:25 -04:00
|
|
|
'_csrf': $('#csrf-token').val()
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-26 11:43:25 -05:00
|
|
|
$('#login').attr('disabled', 'disabled').html('Logging in...');
|
|
|
|
|
$('#login-error-notify').hide();
|
|
|
|
|
|
2013-10-03 15:04:25 -04:00
|
|
|
$.ajax({
|
|
|
|
|
type: "POST",
|
|
|
|
|
url: RELATIVE_PATH + '/login',
|
|
|
|
|
data: loginData,
|
|
|
|
|
success: function(data, textStatus, jqXHR) {
|
2014-02-20 18:30:15 -05:00
|
|
|
$('#login').html('Redirecting...');
|
|
|
|
|
if(!app.previousUrl) {
|
|
|
|
|
app.previousUrl = '/';
|
|
|
|
|
}
|
2013-11-26 11:43:25 -05:00
|
|
|
|
2014-02-20 18:30:15 -05:00
|
|
|
if(app.previousUrl.indexOf('/reset/') !== -1) {
|
|
|
|
|
window.location.replace(RELATIVE_PATH + "/?loggedin");
|
2013-10-03 15:04:25 -04:00
|
|
|
} else {
|
2014-02-20 18:30:15 -05:00
|
|
|
var index = app.previousUrl.indexOf('#');
|
|
|
|
|
if(index !== -1) {
|
|
|
|
|
window.location.replace(app.previousUrl.slice(0, index) + '?loggedin' + app.previousUrl.slice(index));
|
2014-02-20 14:37:10 -05:00
|
|
|
} else {
|
2014-02-20 18:30:15 -05:00
|
|
|
window.location.replace(app.previousUrl + "?loggedin");
|
2014-02-20 14:37:10 -05:00
|
|
|
}
|
2013-10-03 15:04:25 -04:00
|
|
|
}
|
2014-02-20 18:30:15 -05:00
|
|
|
|
|
|
|
|
app.loadConfig();
|
2013-10-03 15:04:25 -04:00
|
|
|
},
|
|
|
|
|
error: function(data, textStatus, jqXHR) {
|
2013-08-28 17:22:48 -04:00
|
|
|
$('#login-error-notify').show();
|
2013-11-26 11:43:25 -05:00
|
|
|
$('#login').removeAttr('disabled').html('Login');
|
2013-10-03 15:04:25 -04:00
|
|
|
},
|
|
|
|
|
dataType: 'json',
|
2013-12-28 13:11:49 -05:00
|
|
|
async: true
|
2013-10-03 15:04:25 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return false;
|
2013-06-25 20:55:02 -04:00
|
|
|
});
|
2013-06-26 13:18:19 -04:00
|
|
|
|
2013-10-03 15:04:25 -04:00
|
|
|
$('#login-error-notify button').on('click', function() {
|
|
|
|
|
$('#login-error-notify').hide();
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2013-08-23 14:30:58 -04:00
|
|
|
|
2014-02-26 21:55:29 -05:00
|
|
|
$('#content input').focus();
|
2013-10-03 15:04:25 -04:00
|
|
|
};
|
2013-08-28 17:22:48 -04:00
|
|
|
|
2013-10-03 15:04:25 -04:00
|
|
|
return Login;
|
2013-10-06 04:24:38 -04:00
|
|
|
});
|