2021-10-04 10:26:48 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
2021-10-04 10:26:48 +03:00
|
|
|
* @since v1.4.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
2021-10-28 14:30:39 +03:00
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Login page.
|
|
|
|
*
|
|
|
|
* This module implements the functionality of the login page.
|
|
|
|
*/
|
|
|
|
App.Pages.Login = (function () {
|
2021-12-07 12:53:59 +03:00
|
|
|
const $loginForm = $('#login-form');
|
2020-04-27 21:27:18 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
|
2022-01-14 10:34:46 +03:00
|
|
|
const url = App.Vars.baseUrl + '/index.php/login/validate';
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2021-12-07 12:53:59 +03:00
|
|
|
const data = {
|
2022-01-14 10:34:46 +03:00
|
|
|
csrf_token: App.Vars.csrf_token,
|
2021-12-10 10:31:00 +03:00
|
|
|
username: $('#username').val(),
|
|
|
|
password: $('#password').val()
|
2020-04-27 21:27:18 +03:00
|
|
|
};
|
|
|
|
|
2021-12-07 12:53:59 +03:00
|
|
|
const $alert = $('.alert');
|
2020-04-27 21:27:18 +03:00
|
|
|
|
2020-06-18 21:37:11 +03:00
|
|
|
$alert.addClass('d-none');
|
2020-04-27 21:27:18 +03:00
|
|
|
|
2021-12-07 12:53:59 +03:00
|
|
|
$.post(url, data).done((response) => {
|
2021-11-06 19:38:37 +03:00
|
|
|
if (response.success) {
|
2022-01-14 10:34:46 +03:00
|
|
|
window.location.href = App.Vars.dest_url;
|
2021-11-06 19:38:37 +03:00
|
|
|
} else {
|
2021-12-13 09:52:09 +03:00
|
|
|
$alert.text(App.Lang.login_failed);
|
2021-11-06 19:38:37 +03:00
|
|
|
$alert.removeClass('d-none alert-danger alert-success').addClass('alert-danger');
|
|
|
|
}
|
|
|
|
});
|
2020-04-27 21:27:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$loginForm.on('submit', onLoginFormSubmit);
|
2022-01-14 11:26:44 +03:00
|
|
|
|
|
|
|
return {};
|
2021-12-07 12:53:59 +03:00
|
|
|
})();
|