mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-25 17:33:19 +03:00
Move the javascript logic of the login page to an external file.
This commit is contained in:
parent
2f17d46960
commit
8ded0851d8
2 changed files with 43 additions and 32 deletions
|
@ -53,42 +53,11 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
var EALang = <?= json_encode($this->lang->language) ?>;
|
var EALang = <?= json_encode($this->lang->language) ?>;
|
||||||
|
|
||||||
var availableLanguages = <?= json_encode(config('available_languages')) ?>;
|
var availableLanguages = <?= json_encode(config('available_languages')) ?>;
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
GeneralFunctions.enableLanguageSelection($('#select-language'));
|
GeneralFunctions.enableLanguageSelection($('#select-language'));
|
||||||
|
|
||||||
/**
|
|
||||||
* Event: Login Button "Click"
|
|
||||||
*
|
|
||||||
* Make an ajax call to the server and check whether the user's credentials are right.
|
|
||||||
* If yes then redirect him to his desired page, otherwise display a message.
|
|
||||||
*/
|
|
||||||
$('#login-form').submit(function(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
var url = GlobalVariables.baseUrl + '/index.php/user/ajax_check_login';
|
|
||||||
var data = {
|
|
||||||
'csrfToken': GlobalVariables.csrfToken,
|
|
||||||
'username': $('#username').val(),
|
|
||||||
'password': $('#password').val()
|
|
||||||
};
|
|
||||||
|
|
||||||
$('.alert').addClass('hidden');
|
|
||||||
|
|
||||||
$.post(url, data)
|
|
||||||
.done(function(response) {
|
|
||||||
if (response === GlobalVariables.AJAX_SUCCESS) {
|
|
||||||
window.location.href = GlobalVariables.destUrl;
|
|
||||||
} else {
|
|
||||||
$('.alert').text(EALang['login_failed']);
|
|
||||||
$('.alert')
|
|
||||||
.removeClass('hidden alert-danger alert-success')
|
|
||||||
.addClass('alert-danger');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
@ -129,5 +98,6 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="<?= asset_url('assets/js/general_functions.js') ?>"></script>
|
<script src="<?= asset_url('assets/js/general_functions.js') ?>"></script>
|
||||||
|
<script src="<?= asset_url('assets/js/login.js') ?>"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
41
assets/js/login.js
Normal file
41
assets/js/login.js
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
$(function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var $loginForm = $('#login-form');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Login Button "Click"
|
||||||
|
*
|
||||||
|
* Make an ajax call to the server and check whether the user's credentials are right.
|
||||||
|
* If yes then redirect him to his desired page, otherwise display a message.
|
||||||
|
*/
|
||||||
|
function onLoginFormSubmit(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
var url = GlobalVariables.baseUrl + '/index.php/user/ajax_check_login';
|
||||||
|
var data = {
|
||||||
|
'csrfToken': GlobalVariables.csrfToken,
|
||||||
|
'username': $('#username').val(),
|
||||||
|
'password': $('#password').val()
|
||||||
|
};
|
||||||
|
|
||||||
|
var $alert = $('.alert');
|
||||||
|
|
||||||
|
$alert.addClass('hidden');
|
||||||
|
|
||||||
|
$.post(url, data)
|
||||||
|
.done(function (response) {
|
||||||
|
if (response === GlobalVariables.AJAX_SUCCESS) {
|
||||||
|
window.location.href = GlobalVariables.destUrl;
|
||||||
|
} else {
|
||||||
|
$alert.text(EALang['login_failed']);
|
||||||
|
$alert
|
||||||
|
.removeClass('hidden alert-danger alert-success')
|
||||||
|
.addClass('alert-danger');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
$loginForm.on('submit', onLoginFormSubmit);
|
||||||
|
});
|
Loading…
Reference in a new issue