2021-12-10 10:41:16 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2021-12-10 10:41:16 +03:00
|
|
|
*
|
|
|
|
* @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-12-10 10:41:16 +03:00
|
|
|
* @since v1.5.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Recovery page.
|
|
|
|
*
|
|
|
|
* This module implements the functionality of the recovery page.
|
|
|
|
*/
|
|
|
|
App.Pages.Recovery = (function () {
|
2021-12-10 10:41:16 +03:00
|
|
|
const $form = $('form');
|
2022-01-17 16:45:20 +03:00
|
|
|
const $username = $('#username');
|
|
|
|
const $email = $('#email');
|
|
|
|
const $getNewPassword = $('#get-new-password');
|
2020-04-27 21:20:35 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Login Button "Click"
|
|
|
|
*
|
|
|
|
* Make an HTTP request to the server and check whether the user's credentials are right. If yes then redirect the
|
|
|
|
* user to the destination page, otherwise display an error message.
|
|
|
|
*/
|
|
|
|
function onFormSubmit(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
2021-12-10 10:41:16 +03:00
|
|
|
const $alert = $('.alert');
|
2020-04-27 21:20:35 +03:00
|
|
|
|
2020-06-18 21:37:11 +03:00
|
|
|
$alert.addClass('d-none');
|
2021-12-10 10:41:16 +03:00
|
|
|
|
2022-01-17 16:45:20 +03:00
|
|
|
$getNewPassword.prop('disabled', true);
|
|
|
|
|
|
|
|
const username = $username.val();
|
|
|
|
const email = $email.val();
|
2020-04-27 21:20:35 +03:00
|
|
|
|
2022-01-17 16:45:20 +03:00
|
|
|
App.Http.Recovery.perform(username, email).done((response) => {
|
2021-11-06 19:38:37 +03:00
|
|
|
$alert.removeClass('d-none alert-danger alert-success');
|
2021-12-10 10:41:16 +03:00
|
|
|
|
2022-01-17 16:45:20 +03:00
|
|
|
$getNewPassword.prop('disabled', false);
|
2021-12-10 10:41:16 +03:00
|
|
|
|
|
|
|
if (response.success) {
|
2021-11-06 19:38:37 +03:00
|
|
|
$alert.addClass('alert-success');
|
2022-01-18 10:22:25 +03:00
|
|
|
$alert.text(lang('new_password_sent_with_email'));
|
2021-11-06 19:38:37 +03:00
|
|
|
} else {
|
|
|
|
$alert.addClass('alert-danger');
|
|
|
|
$alert.text(
|
|
|
|
'The operation failed! Please enter a valid username ' +
|
|
|
|
'and email address in order to get a new password.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2020-04-27 21:20:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$form.on('submit', onFormSubmit);
|
2022-01-14 11:26:44 +03:00
|
|
|
|
|
|
|
return {};
|
2021-12-10 10:41:16 +03:00
|
|
|
})();
|