From 69f4daca8987eb0c1dd846f245332046b734128d Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Mon, 27 Apr 2020 20:20:35 +0200 Subject: [PATCH] Move the javascript logic of the forgot password page to an external file. --- application/views/user/forgot_password.php | 55 ++++------------------ assets/js/forgot_password.js | 46 ++++++++++++++++++ 2 files changed, 55 insertions(+), 46 deletions(-) create mode 100644 assets/js/forgot_password.js diff --git a/application/views/user/forgot_password.php b/application/views/user/forgot_password.php index 93a0e887..4c8c6b46 100644 --- a/application/views/user/forgot_password.php +++ b/application/views/user/forgot_password.php @@ -11,7 +11,7 @@ - + @@ -127,5 +89,6 @@ + diff --git a/assets/js/forgot_password.js b/assets/js/forgot_password.js new file mode 100644 index 00000000..8af8d828 --- /dev/null +++ b/assets/js/forgot_password.js @@ -0,0 +1,46 @@ +$(function () { + 'use strict'; + + var $form = $('form'); + + /** + * 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(); + + var url = GlobalVariables.baseUrl + '/index.php/user/ajax_forgot_password'; + + var data = { + 'csrfToken': GlobalVariables.csrfToken, + 'username': $('#username').val(), + 'email': $('#email').val() + }; + + var $alert = $('.alert'); + + $alert.addClass('hidden'); + $('#get-new-password').prop('disabled', true); + + $.post(url, data) + .done(function (response) { + $alert.removeClass('hidden alert-danger alert-success'); + $('#get-new-password').prop('disabled', false); + if (response === GlobalVariables.AJAX_SUCCESS) { + $alert.addClass('alert-success'); + $alert.text(EALang['new_password_sent_with_email']); + } 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.'); + } + }) + .fail(GeneralFunctions.ajaxFailureHandler); + } + + + $form.on('submit', onFormSubmit); +});