Skip to content

Commit

Permalink
related to #2158 change password rework
Browse files Browse the repository at this point in the history
- add new method for generate a password link
- update password.php now we're using functions to generate the link to the password and the contents of the email and we've removed the email from the reset key
- update user_list.tpl add modal for pasword and update css
- update user_list.js add ajax function for reset password and adjusting scripts for modal password
- add functions 'ws_users_generate_reset_password_link', 'generate_reset_password_link' and 'pwg_generate_reset_password_mail'
  • Loading branch information
LintyDev committed May 27, 2024
1 parent 343c447 commit e9f4a64
Show file tree
Hide file tree
Showing 7 changed files with 386 additions and 115 deletions.
155 changes: 123 additions & 32 deletions admin/themes/default/js/user_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function open_user_list() {

function close_user_list() {
hide_temporary_messages();
$('#result_send_mail_copy_input').val('');
$("#UserList").fadeOut();
}

Expand All @@ -81,6 +82,15 @@ function isSelectionMode() {
return $("#toggleSelectionMode").is(":checked")
}

function reset_password_modals() {
$('.user-property-password-change').hide();
$('.user-property-password-change-inputs').hide();
$('#edit_password_success_change').hide();
$('#edit_password_result_mail').hide();
$('#edit_password_result_mail_copy').hide();
$('.user-property-password-choice').show();
}


$( document ).ready(function() {
$(".user-property-register").tipTip({
Expand All @@ -96,9 +106,10 @@ $( document ).ready(function() {
fadeOut: 200
});
$(".advanced-filter-level select option").eq(1).remove();

/* Edit Password */
$('.button-edit-password-icon').click(function () {
$('.user-property-password-change-inputs, .edit-password-success').hide()
$('.user-property-password-choice').show();
reset_password_modals();
$('.user-property-password-change').fadeIn();
})

Expand All @@ -107,6 +118,24 @@ $( document ).ready(function() {
reset_input_password();
})

$('.icon-show-password').on('click', function() {
const icon = $(this);
const closestInput = icon.siblings();
if (closestInput.attr('type') === 'password') {
closestInput.attr('type', 'text');
icon.removeClass('icon-eye').addClass('icon-eye-off');
} else {
closestInput.attr('type', 'password');
icon.removeClass('icon-eye-off').addClass('icon-eye');
}
});

// Password input onkeyup clear error
$('#edit_user_password, #edit_user_conf_password').on('keyup', function() {
hide_error_edit_user();
});

/* Edit Username */
$('.edit-username').click(function () {
$('.user-property-username-change').show();
})
Expand Down Expand Up @@ -382,25 +411,6 @@ $( document ).ready(function() {
});
});

// Show / Hide password input
$('.icon-show-password').on('click', function() {
const icon = $(this);
const closestInput = icon.siblings();
if (closestInput.attr('type') === 'password') {
closestInput.attr('type', 'text');
icon.removeClass('icon-eye').addClass('icon-eye-off');
} else {
closestInput.attr('type', 'password');
icon.removeClass('icon-eye-off').addClass('icon-eye');
}
});

// Password input onchange clear error
$('#edit_user_password, #edit_user_conf_password').on('keyup', function() {
hide_error_edit_user();
});


/* tabsheet pop in guest */
$('.guest-edit-user-tabsheet').off('click').on('click', function() {
const tabName = $(this).attr('id').split('_');
Expand Down Expand Up @@ -1026,9 +1036,9 @@ function editTabsBind () {
}

function check_tabs (title_tab_name_id) {

if (plugins_load.length > 1) {
const countMoresPlugins = plugins_load.length - 1;
if (plugins_load.length > 2) {
$('.edit-user-tab-title').css({gap : '0px', justifyContent: 'space-between'});
const countMoresPlugins = plugins_load.length - 2;
if (!document.getElementById('mores_plugins_expand')) {
$('.edit-user-tab-title').append(
'<span class="close mores-plugins" id="mores_plugins_expand"></span>' +
Expand All @@ -1044,7 +1054,7 @@ function check_tabs (title_tab_name_id) {
tabsheetTitle.css({'max-width': '100%'});
tabsheetTitle.appendTo(dropdown);

if (1 == countMoresPlugins) {
if (1 === countMoresPlugins) {
tabsheetTitle.css('border-radius', '10px');
} else {
dropdown.children().css('border-radius', '0');
Expand Down Expand Up @@ -1124,13 +1134,12 @@ function plugin_add_tab_in_user_modal(tab_name, content_id, users_table=null, se
// DOM modification
const content = $('#' + content_id);

// TODO Add a super div with the real width and height (for better css custom)
$('.edit-user-tab-title').append(
'<p class="edit-user-tabsheet" id="name_tab_' + name + '" title="'+ tab_name +'">'+ tab_name +'</p>'
);

$('.edit-user-slides').append(
'<div class="'+ name +'-container" id="tab_'+ name +'"></div>'
'<div class="edit-user-tabsheet-plugins '+ name +'-container" id="tab_'+ name +'"></div>'
);

content.appendTo('#tab_' + name);
Expand All @@ -1143,7 +1152,7 @@ function plugin_add_tab_in_user_modal(tab_name, content_id, users_table=null, se
plugins_load.push('name_tab_' + name);
check_tabs('name_tab_' + name);

if (plugins_load.length <= 1) {
if (plugins_load.length <= 2) {
$('#name_tab_' + name).tipTip({
delay: 0,
fadeIn: 200,
Expand Down Expand Up @@ -1249,6 +1258,9 @@ function generate_user_list() {
$(".user-container").click(user_container_click);
}

function copyToClipboard(toCopy) {
navigator.clipboard.writeText(toCopy);
}
/*---------------------
Fill the pop-in values
---------------------*/
Expand Down Expand Up @@ -1315,6 +1327,7 @@ function fill_user_edit_summary(user_to_edit, pop_in, isGuest) {
if(!window.isSecureContext) {
$('#copy_password').hide();
$('.update-password-success').css('margin', '40px 0');
$('#result_send_mail_copy').hide();
}
}

Expand Down Expand Up @@ -1369,12 +1382,49 @@ function fill_user_edit_update(user_to_edit, pop_in) {
$('.user-property-password-choice').hide();
$('.user-property-password-change-inputs').fadeIn();
});
if (user_to_edit.email) {
pop_in.find('#send_password_link')
.removeClass('unavailable tiptip')
.attr('title', '')
.off('click')
.on('click', function () {
send_link_password(user_to_edit.email, user_to_edit.username, user_to_edit.id, true);
});
pop_in.find('#send_password_link').off('mouseenter mouseleave focus blur');
} else {
pop_in.find('#send_password_link')
.addClass('unavailable tiptip')
.off('click')
.attr('title', cannotSendMail)
.tipTip({
delay: 0,
fadeIn: 200,
fadeOut: 200,
edgeOffset: 3
});
}
pop_in.find('#copy_password_link').off('click').on('click', function() {
const inputValue = $('#result_send_mail_copy_input').val();
if (inputValue === '') {
send_link_password(user_to_edit.email, user_to_edit.username, user_to_edit.id, false);
} else {
if (window.isSecureContext && navigator.clipboard) {
copyToClipboard(inputValue);
};
}
$('.user-property-password-choice').hide();
$('#edit_password_result_mail_copy').fadeIn();
$('#close_password_mail_send_close').off('click').on('click', function() {
reset_password_modals();
});
$('#result_send_mail_copy_input').trigger('focus');
});
pop_in.find('.edit-password-validate').unbind("click").click(function() {
const errDiv = $('#UserList .EditUserErrors');
const inputPassword = $('#edit_user_password').val();
const inputConfirmPassword = $('#edit_user_conf_password').val();

if (inputPassword == '' || inputConfirmPassword == '') {
if (inputPassword === '' || inputConfirmPassword === '') {
errDiv.html(missingField);
show_error_edit_user();
} else if (inputPassword !== inputConfirmPassword) {
Expand Down Expand Up @@ -1663,18 +1713,18 @@ function update_user_password() {
data = jQuery.parseJSON(raw_data);
if (data.stat == 'ok') {
$('.user-property-password-change-inputs').hide();
$('.edit-password-success').fadeIn();
$('#edit_password_success_change').fadeIn();

if (window.isSecureContext && navigator.clipboard) {
$('#copy_password').on('click', async function() {
navigator.clipboard.writeText(ajax_data['password']);
copyToClipboard(ajax_data['password'])
$('#password_msg_success').html(passwordCopied);
});
};

$('#close_password_success').on('click', function() {
$('.user-property-password-change').hide();
$('.edit-password-success').hide();
$('#edit_password_success_change').hide();
$('.user-property-password-change-inputs').show();
reset_input_password();
});
Expand Down Expand Up @@ -1989,3 +2039,44 @@ function show_filter_infos(nb_filters) {
$(".filter-counter").css('display', 'none').html(0);
}
}

function send_link_password(email, username, user_id, send_by_mail) {
$.ajax({
url: "ws.php?format=json",
dataType: "json",
data: {
method: 'pwg.users.generateResetPasswordLink',
user_id: user_id,
send_by_mail: send_by_mail,
pwg_token: pwg_token
},
success: function(response) {
if('ok' === response.stat) {
$('#result_send_mail_copy_input').val(response.result.generated_link);
if(send_by_mail) {
if(response.result.send_by_mail) {
$('#result_send_mail').removeClass('update-password-fail icon-red').addClass('update-password-success icon-green');
$('#icon_password_msg_result_mail').removeClass('icon-cancel').addClass('icon-ok');
$('#password_msg_result_mail').html(sprintf(mailSentAt, username, email));
} else {
$('#result_send_mail').removeClass('update-password-success icon-green').addClass('update-password-fail icon-red');
$('#icon_password_msg_result_mail').removeClass('icon-ok').addClass('icon-cancel');
$('#password_msg_result_mail').html(errorMailSent);
}
$('.user-property-password-choice').hide();
$('#edit_password_result_mail').fadeIn();
$('#close_password_mail_close').off('click').on('click', function() {
reset_password_modals();
});
} else {
if (window.isSecureContext && navigator.clipboard) {
copyToClipboard(response.result.generated_link);
};
}
}
},
error: function(err) {
console.log(err);
},
});
}

0 comments on commit e9f4a64

Please sign in to comment.