From e15dacba8a7744322cfe71b4a5df1a58881bb252 Mon Sep 17 00:00:00 2001 From: PavelBegunkov <asml.Silence@gmail.com> Date: Tue, 2 Dec 2014 21:49:44 +0300 Subject: [PATCH] change password js fix --- ~dev_rating/media/js/profile.js | 17 +++----- ~dev_rating/media/js/settings.js | 71 ++++++++++++++++++-------------- 2 files changed, 47 insertions(+), 41 deletions(-) diff --git a/~dev_rating/media/js/profile.js b/~dev_rating/media/js/profile.js index c3c73783c..1b9bdbda8 100644 --- a/~dev_rating/media/js/profile.js +++ b/~dev_rating/media/js/profile.js @@ -33,17 +33,12 @@ $(function() }); - function closeSession(time) { - if (time < 0) - time = 0; - - setTimeout(function() { - $.ajax({ - type: "POST", - url: URLdir + "handler/Session/closeSession", - success: function(data) {window.location.replace(URLdir);} - }); - }, time*1000); + function closeSession() { + $.ajax({ + type: "POST", + url: URLdir + "handler/Session/closeSession", + success: function(data) {window.location.replace(URLdir);} + }); } diff --git a/~dev_rating/media/js/settings.js b/~dev_rating/media/js/settings.js index ce8831ea5..fb1db492d 100644 --- a/~dev_rating/media/js/settings.js +++ b/~dev_rating/media/js/settings.js @@ -5,6 +5,10 @@ $(function() { var jChangeLogin = $(".changeLogin").first(); var jChangePass = $(".changePass").first(); + var jInputPwdCurrent = $('.inputCurrentPass').first(); + var jInputPwdNew = $('.inputNewPass').first(); + var jInputPwdConfirm = $('.inputСonfirmPass').first(); + $('.showBlockReport').click(function(){ if ($('.blockReport').css('display') == 'none') $('.blockReport').slideDown("fast"); @@ -68,36 +72,43 @@ $(function() { */ }); - jChangePass.click(function(){ + jChangePass.click(function() { jChangePass.attr("disabled", true); - if ($.trim($('.inputCurrentPass').val()) != '') - checkInput['currentPass'] = true; - else checkInput['currentPass'] = false; - - if ($.trim($('.inputNewPass').val()) != '') - checkInput['newPass'] = true; - else checkInput['newPass'] = false; - - if (checkInput['currentPass'] == true && checkInput['newPass'] == true && $('.inputСonfirmPass').val() == $('.inputNewPass').val()) - checkInput['confirmPass'] = true; - else - checkInput['confirmPass'] = false; - - if (checkInput['confirmPass'] == true) - $.post(URLdir + 'handler/settings/changePassword', - { - 'old_password': $.sha1($('.inputCurrentPass').val()), - 'password': $.sha1($('.inputNewPass').val()), - 'confirm_password': $.sha1($('.inputСonfirmPass').val()) - }, - function(data){ - data = $.parseJSON(data); - jChangeLogin.removeAttr("disabled"); - if(data.success === true) { - EventInspector_ShowMsg('Пароль изменен', 'success'); - jChangePass.html("Пароль изменен!").unbind("click"); - } else EventInspector_ShowMsg('Не удалось изменить пароль', 'error'); - } - ); + + var pwdCurrent = $.trim(jInputPwdCurrent.val()); + var pwdConfirm = $.trim(jInputPwdConfirm.val()); + var pwdNew = $.trim(jInputPwdNew.val()); + + if (pwdCurrent === '' || pwdNew === '' || pwdNew !== pwdConfirm) { + EventInspector_ShowMsg('Не удалось изменить пароль', 'error'); + jChangePass.removeAttr("disabled"); + return; + } + + + $.post(URLdir + 'handler/settings/changePassword', + { + 'old_password': $.sha1(pwdCurrent), + 'password': $.sha1(pwdNew), + 'confirm_password': $.sha1(pwdConfirm) + }, + function(data) { + data = $.parseJSON(data); + + if(data.success === true) { + EventInspector_ShowMsg('Пароль изменен', 'success'); + jChangePass.html("Пароль изменен!").unbind("click"); + jInputPwdCurrent.attr("disabled", true); + jInputPwdConfirm.attr("disabled", true); + jInputPwdNew.attr("disabled", true); + + } else + EventInspector_ShowMsg('Не удалось изменить пароль', 'error'); + + jChangePass.removeAttr("disabled"); + } + ); }); + + }); -- GitLab