From f3f4912e41228352b5abc96e2c8f3dbfd3f57ecc Mon Sep 17 00:00:00 2001 From: Gabriel De Los Rios Date: Sun, 17 Nov 2024 22:39:04 -0300 Subject: [PATCH] feat(users): adds in client password matching validation --- app/templates/users/register.html | 9 ++++++++- app/utils/form_errors_dict.py | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/templates/users/register.html b/app/templates/users/register.html index 9a001c2..b5eca1a 100644 --- a/app/templates/users/register.html +++ b/app/templates/users/register.html @@ -87,7 +87,7 @@ required type="password" > - {{ form_field_validation(FORM_ERRORS['REQUIRED'] + " " + FORM_ERRORS['PASSWORD_LENGTH']) }} + {{ form_field_validation(FORM_ERRORS['REQUIRED'] + " " + FORM_ERRORS['PASSWORD_LENGTH'] + " " + FORM_ERRORS['MUST_MATCH_PASSWORD']) }}
@@ -118,6 +118,13 @@ form.classList.add('was-validated') }, false) }) + + const password = document.getElementById("password") + const password_validation = document.getElementById("password-confirmation") + password.addEventListener('change', (c) => { + password_validation.setAttribute("pattern", c.target.value) + }) + })() {% endblock %} \ No newline at end of file diff --git a/app/utils/form_errors_dict.py b/app/utils/form_errors_dict.py index aa2dde0..2d6f742 100644 --- a/app/utils/form_errors_dict.py +++ b/app/utils/form_errors_dict.py @@ -1,6 +1,7 @@ FORM_ERRORS = { 'REQUIRED': "This field is required.", 'PASSWORD_LENGTH': 'It must be at least 6 characters long.', + 'MUST_MATCH_PASSWORD': 'It must match the given password.', 'VALID_EMAIL': 'Enter a valid email address.', 'PHONE_NUMBER_FORMAT': 'It can be prefixed with the "+" sign and may only contain numbers after it.', 'NAME_FORMAT': 'It must be at least 2 characters long, it may only contain letters.'