From 390d66f8d2a3c6223f71714c721f065448828aef Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Mon, 17 Jan 2022 14:45:20 +0100 Subject: [PATCH] Code refactoring and improvements for the recovery page. --- application/views/pages/recovery.php | 2 ++ assets/js/http/recovery_http_client.js | 41 ++++++++++++++++++++++++++ assets/js/pages/recovery.js | 20 ++++++------- 3 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 assets/js/http/recovery_http_client.js diff --git a/application/views/pages/recovery.php b/application/views/pages/recovery.php index 318ae94c..bf34501d 100644 --- a/application/views/pages/recovery.php +++ b/application/views/pages/recovery.php @@ -39,6 +39,8 @@ + + diff --git a/assets/js/http/recovery_http_client.js b/assets/js/http/recovery_http_client.js new file mode 100644 index 00000000..ddc96180 --- /dev/null +++ b/assets/js/http/recovery_http_client.js @@ -0,0 +1,41 @@ +/* ---------------------------------------------------------------------------- + * Easy!Appointments - Open Source Web Scheduler + * + * @package EasyAppointments + * @author A.Tselegidis + * @copyright Copyright (c) Alex Tselegidis + * @license https://opensource.org/licenses/GPL-3.0 - GPLv3 + * @link https://easyappointments.org + * @since v1.5.0 + * ---------------------------------------------------------------------------- */ + +/** + * Recovery HTTP client. + * + * This module implements the account recovery related HTTP requests. + */ +App.Http.Recovery = (function () { + /** + * Perform an account recovery. + * + * @param {String} username + * @param {String} email + * + * @return {Object} + */ + function perform(username, email) { + const url = App.Utils.Url.siteUrl('recovery/perform'); + + const data = { + csrf_token: App.Vars.csrf_token, + username, + email + }; + + return $.post(url, data); + } + + return { + perform + }; +})(); diff --git a/assets/js/pages/recovery.js b/assets/js/pages/recovery.js index a5e66624..77b4cdf1 100644 --- a/assets/js/pages/recovery.js +++ b/assets/js/pages/recovery.js @@ -16,6 +16,9 @@ */ App.Pages.Recovery = (function () { const $form = $('form'); + const $username = $('#username'); + const $email = $('#email'); + const $getNewPassword = $('#get-new-password'); /** * Event: Login Button "Click" @@ -26,24 +29,19 @@ App.Pages.Recovery = (function () { function onFormSubmit(event) { event.preventDefault(); - const url = GlobalVariables.baseUrl + '/index.php/recovery/perform'; - - const data = { - csrf_token: GlobalVariables.csrfToken, - username: $('#username').val(), - email: $('#email').val() - }; - const $alert = $('.alert'); $alert.addClass('d-none'); - $('#get-new-password').prop('disabled', true); + $getNewPassword.prop('disabled', true); - $.post(url, data).done((response) => { + const username = $username.val(); + const email = $email.val(); + + App.Http.Recovery.perform(username, email).done((response) => { $alert.removeClass('d-none alert-danger alert-success'); - $('#get-new-password').prop('disabled', false); + $getNewPassword.prop('disabled', false); if (response.success) { $alert.addClass('alert-success');