diff --git a/application/views/user/login.php b/application/views/user/login.php index 3223d6f6..522018f0 100644 --- a/application/views/user/login.php +++ b/application/views/user/login.php @@ -53,42 +53,11 @@ }; var EALang = lang->language) ?>; + var availableLanguages = ; $(document).ready(function() { 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); - }); }); @@ -129,5 +98,6 @@ + diff --git a/assets/js/login.js b/assets/js/login.js new file mode 100644 index 00000000..2fa9da0d --- /dev/null +++ b/assets/js/login.js @@ -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); +});