From 0310edb2dadfec71f8b6f0136b0f3c50c8542b22 Mon Sep 17 00:00:00 2001 From: Stefan Kairinos <118008817+SKairinos@users.noreply.github.com> Date: Fri, 3 Nov 2023 15:27:24 +0000 Subject: [PATCH] feat: reveal password button (#2218) * register forms * register forms pt.2 * teacher password visibility * student login * independent login * reset password * teacher account * student account * fix teacher password * teacher edits student password * feedback * Merge branch 'master' into reveal_password_button --- portal/static/portal/js/independentLogin.js | 16 +++++ .../static/portal/js/organisation_manage.js | 62 +++++++++++++++++++ portal/static/portal/js/passwordStrength.js | 46 ++++++++++++++ portal/static/portal/js/resetPassword.js | 23 +++++++ portal/static/portal/js/studentLogin.js | 16 +++++ portal/static/portal/js/teacherEditStudent.js | 23 +++++++ portal/static/portal/js/teacherLogin.js | 16 +++++ .../portal/login/independent_student.html | 7 ++- portal/templates/portal/login/student.html | 7 ++- portal/templates/portal/login/teacher.html | 8 ++- .../portal/play/student_edit_account.html | 13 ++-- portal/templates/portal/register.html | 12 ++-- .../portal/reset_password_confirm.html | 11 +++- portal/templates/portal/teach/dashboard.html | 7 ++- .../portal/teach/teacher_edit_student.html | 17 +++-- 15 files changed, 256 insertions(+), 28 deletions(-) create mode 100644 portal/static/portal/js/independentLogin.js create mode 100644 portal/static/portal/js/resetPassword.js create mode 100644 portal/static/portal/js/studentLogin.js create mode 100644 portal/static/portal/js/teacherEditStudent.js create mode 100644 portal/static/portal/js/teacherLogin.js diff --git a/portal/static/portal/js/independentLogin.js b/portal/static/portal/js/independentLogin.js new file mode 100644 index 000000000..3f10bb6a3 --- /dev/null +++ b/portal/static/portal/js/independentLogin.js @@ -0,0 +1,16 @@ +$(document).ready(() => { + $('#independent_student_login_form').on('click', '#password-field-icon', () => { + let inputType; + let dataIcon = $('#password-field-icon').attr('data-icon'); + if (dataIcon === 'material-symbols:visibility') { + inputType = 'password'; + dataIcon = 'material-symbols:visibility-off'; + } else { + inputType = 'text'; + dataIcon = 'material-symbols:visibility'; + } + + $('#id_password').attr('type', inputType); + $('#password-field-icon').attr('data-icon', dataIcon); + }); +}); diff --git a/portal/static/portal/js/organisation_manage.js b/portal/static/portal/js/organisation_manage.js index 255eaa285..f6977d944 100644 --- a/portal/static/portal/js/organisation_manage.js +++ b/portal/static/portal/js/organisation_manage.js @@ -89,3 +89,65 @@ function showDeleteAccountConfirmation(delete_password, unsubscribe_newsletter, function hideDeleteAccountPopup() { $("#popup-delete-review").removeClass("popup--fade"); } + +$(document).ready(() => { + $('#edit_account_details_password, #student_account_form').on( + 'click', + '#password-field-icon, #confirm-password-field-icon', + () => { + let inputType; + let dataIcon = $('#password-field-icon').attr('data-icon'); + if (dataIcon === 'material-symbols:visibility') { + inputType = 'password'; + dataIcon = 'material-symbols:visibility-off'; + } else { + inputType = 'text'; + dataIcon = 'material-symbols:visibility'; + } + + $('#id_password').attr('type', inputType); + $('#id_confirm_password').attr('type', inputType); + + $('#password-field-icon').attr('data-icon', dataIcon); + $('#confirm-password-field-icon').attr('data-icon', dataIcon); + } + ); + + $('#edit_account_details_password, #student_account_form').on( + 'click', + '#current-password-field-icon', + () => { + let inputType; + let dataIcon = $('#current-password-field-icon').attr('data-icon'); + if (dataIcon === 'material-symbols:visibility') { + inputType = 'password'; + dataIcon = 'material-symbols:visibility-off'; + } else { + inputType = 'text'; + dataIcon = 'material-symbols:visibility'; + } + + $('#id_current_password').attr('type', inputType); + $('#current-password-field-icon').attr('data-icon', dataIcon); + } + ); + + $('#delete-account, #delete-indy-account').on( + 'click', + '#delete-password-field-icon', + () => { + let inputType; + let dataIcon = $('#delete-password-field-icon').attr('data-icon'); + if (dataIcon === 'material-symbols:visibility') { + inputType = 'password'; + dataIcon = 'material-symbols:visibility-off'; + } else { + inputType = 'text'; + dataIcon = 'material-symbols:visibility'; + } + + $('#id_delete_password').attr('type', inputType); + $('#delete-password-field-icon').attr('data-icon', dataIcon); + } + ); +}); diff --git a/portal/static/portal/js/passwordStrength.js b/portal/static/portal/js/passwordStrength.js index de17330a6..3b3dc0209 100644 --- a/portal/static/portal/js/passwordStrength.js +++ b/portal/static/portal/js/passwordStrength.js @@ -117,10 +117,56 @@ async function handlePwnedPasswordApiAvailability() { } } +function onClickPasswordVisibility( + formId, + passwordIconId, + confirmPasswordIconId, + passwordId, + confirmPasswordId +) { + // Delegate event listeners. + $(formId).on('click', '[data-icon^="material-symbols:visibility"]', function () { + // Get icons and input types. + let inputType; + let dataIcon; + if ($(this).attr('data-icon') === 'material-symbols:visibility') { + inputType = 'password'; + dataIcon = 'material-symbols:visibility-off'; + } else { + inputType = 'text'; + dataIcon = 'material-symbols:visibility'; + } + + // Set icons. + $(passwordIconId).attr('data-icon', dataIcon); + $(confirmPasswordIconId).attr('data-icon', dataIcon); + + // Set input types. + $(passwordId).attr('type', inputType); + $(confirmPasswordId).attr('type', inputType); + }) +} + $(document).ready(function () { handlePasswordStrength(); // the password strength text is updated dynamically hence this is the initial first call handlePwnedPasswordApiAvailability(); $( `#${TEACHER_PASSWORD_FIELD_ID}, #${INDEP_STUDENT_PASSWORD_FIELD_ID}` ).on('input change focus blur', handlePasswordStrength); + + onClickPasswordVisibility( + '#teacher-register-form', + '#teacher-password-field-icon', + '#teacher-confirm-password-field-icon', + '#id_teacher_signup-teacher_password', + '#id_teacher_signup-teacher_confirm_password' + ); + + onClickPasswordVisibility( + '#independent-student-register-form', + '#independent-student-password-field-icon', + '#independent-student-confirm-password-field-icon', + '#id_independent_student_signup-password', + '#id_independent_student_signup-confirm_password' + ); }); diff --git a/portal/static/portal/js/resetPassword.js b/portal/static/portal/js/resetPassword.js new file mode 100644 index 000000000..11aeb195b --- /dev/null +++ b/portal/static/portal/js/resetPassword.js @@ -0,0 +1,23 @@ +$(document).ready(() => { + $('#reset-password-form').on( + 'click', + '#password-field-icon, #confirm-password-field-icon', + () => { + let inputType; + let dataIcon = $('#password-field-icon').attr('data-icon'); + if (dataIcon === 'material-symbols:visibility') { + inputType = 'password'; + dataIcon = 'material-symbols:visibility-off'; + } else { + inputType = 'text'; + dataIcon = 'material-symbols:visibility'; + } + + $('#id_new_password1').attr('type', inputType); + $('#id_new_password2').attr('type', inputType); + + $('#password-field-icon').attr('data-icon', dataIcon); + $('#confirm-password-field-icon').attr('data-icon', dataIcon); + } + ); +}); diff --git a/portal/static/portal/js/studentLogin.js b/portal/static/portal/js/studentLogin.js new file mode 100644 index 000000000..694f4fe23 --- /dev/null +++ b/portal/static/portal/js/studentLogin.js @@ -0,0 +1,16 @@ +$(document).ready(() => { + $('#form-login-school').on('click', '#password-field-icon', () => { + let inputType; + let dataIcon = $('#password-field-icon').attr('data-icon'); + if (dataIcon === 'material-symbols:visibility') { + inputType = 'password'; + dataIcon = 'material-symbols:visibility-off'; + } else { + inputType = 'text'; + dataIcon = 'material-symbols:visibility'; + } + + $('#id_password').attr('type', inputType); + $('#password-field-icon').attr('data-icon', dataIcon); + }); +}); diff --git a/portal/static/portal/js/teacherEditStudent.js b/portal/static/portal/js/teacherEditStudent.js new file mode 100644 index 000000000..b67deacc6 --- /dev/null +++ b/portal/static/portal/js/teacherEditStudent.js @@ -0,0 +1,23 @@ +$(document).ready(() => { + $('#edit-student-password-form').on( + 'click', + '#password-field-icon, #confirm-password-field-icon', + () => { + let inputType; + let dataIcon = $('#password-field-icon').attr('data-icon'); + if (dataIcon === 'material-symbols:visibility') { + inputType = 'password'; + dataIcon = 'material-symbols:visibility-off'; + } else { + inputType = 'text'; + dataIcon = 'material-symbols:visibility'; + } + + $('#id_password').attr('type', inputType); + $('#id_confirm_password').attr('type', inputType); + + $('#password-field-icon').attr('data-icon', dataIcon); + $('#confirm-password-field-icon').attr('data-icon', dataIcon); + } + ); +}); \ No newline at end of file diff --git a/portal/static/portal/js/teacherLogin.js b/portal/static/portal/js/teacherLogin.js new file mode 100644 index 000000000..59a4d687c --- /dev/null +++ b/portal/static/portal/js/teacherLogin.js @@ -0,0 +1,16 @@ +$(document).ready(() => { + $('#form-login-teacher').on('click', '#password-field-icon', () => { + let inputType; + let dataIcon = $('#password-field-icon').attr('data-icon'); + if (dataIcon === 'material-symbols:visibility') { + inputType = 'password'; + dataIcon = 'material-symbols:visibility-off'; + } else { + inputType = 'text'; + dataIcon = 'material-symbols:visibility'; + } + + $('#id_auth-password').attr('type', inputType); + $('#password-field-icon').attr('data-icon', dataIcon); + }); +}); diff --git a/portal/templates/portal/login/independent_student.html b/portal/templates/portal/login/independent_student.html index 7ab16e59b..d631d6c94 100644 --- a/portal/templates/portal/login/independent_student.html +++ b/portal/templates/portal/login/independent_student.html @@ -18,8 +18,10 @@
Register below to create your school or club.
@@ -53,7 +53,7 @@@@ -149,7 +149,7 @@
Please enter a new password and confirm it in the boxes below to reset your account’s password.
-