Code refactoring and improvements for the recovery page.

This commit is contained in:
Alex Tselegidis 2022-01-17 14:45:20 +01:00
parent 2451d4d5b7
commit 390d66f8d2
3 changed files with 52 additions and 11 deletions

View file

@ -39,6 +39,8 @@
<script src="<?= asset_url('assets/vendor/@fortawesome-fontawesome-free/fontawesome.min.js') ?>"></script> <script src="<?= asset_url('assets/vendor/@fortawesome-fontawesome-free/fontawesome.min.js') ?>"></script>
<script src="<?= asset_url('assets/vendor/@fortawesome-fontawesome-free/solid.min.js') ?>"></script> <script src="<?= asset_url('assets/vendor/@fortawesome-fontawesome-free/solid.min.js') ?>"></script>
<script src="<?= asset_url('assets/js/utils/general_functions.js') ?>"></script> <script src="<?= asset_url('assets/js/utils/general_functions.js') ?>"></script>
<script src="<?= asset_url('assets/js/utils/url.js') ?>"></script>
<script src="<?= asset_url('assets/js/http/recovery_http_client.js') ?>"></script>
<script src="<?= asset_url('assets/js/pages/recovery.js') ?>"></script> <script src="<?= asset_url('assets/js/pages/recovery.js') ?>"></script>
<?php section('scripts') ?> <?php section('scripts') ?>

View file

@ -0,0 +1,41 @@
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @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
};
})();

View file

@ -16,6 +16,9 @@
*/ */
App.Pages.Recovery = (function () { App.Pages.Recovery = (function () {
const $form = $('form'); const $form = $('form');
const $username = $('#username');
const $email = $('#email');
const $getNewPassword = $('#get-new-password');
/** /**
* Event: Login Button "Click" * Event: Login Button "Click"
@ -26,24 +29,19 @@ App.Pages.Recovery = (function () {
function onFormSubmit(event) { function onFormSubmit(event) {
event.preventDefault(); 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'); const $alert = $('.alert');
$alert.addClass('d-none'); $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'); $alert.removeClass('d-none alert-danger alert-success');
$('#get-new-password').prop('disabled', false); $getNewPassword.prop('disabled', false);
if (response.success) { if (response.success) {
$alert.addClass('alert-success'); $alert.addClass('alert-success');