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
|
2022-01-18 15:01:22 +03:00
|
|
|
* @since v1.5.0
|
2021-10-04 10:26:48 +03:00
|
|
|
* ---------------------------------------------------------------------------- */
|
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');
|
2022-01-17 16:27:10 +03:00
|
|
|
const $username = $('#username');
|
|
|
|
const $password = $('#password');
|
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.
|
2022-01-17 20:22:59 +03:00
|
|
|
*
|
2020-04-27 21:27:18 +03:00
|
|
|
* If yes then redirect him to his desired page, otherwise display a message.
|
|
|
|
*/
|
|
|
|
function onLoginFormSubmit(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
2022-01-17 20:22:59 +03:00
|
|
|
const username = $username.val();
|
|
|
|
const 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
|
|
|
|
2022-01-17 20:22:59 +03:00
|
|
|
App.Http.Login.validate(username, password).done((response) => {
|
2021-11-06 19:38:37 +03:00
|
|
|
if (response.success) {
|
2022-01-18 10:18:22 +03:00
|
|
|
window.location.href = vars('dest_url');
|
2021-11-06 19:38:37 +03:00
|
|
|
} else {
|
2022-01-18 10:22:25 +03:00
|
|
|
$alert.text(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
|
|
|
})();
|