Skip to content

Commit

Permalink
Merge pull request #723 from eresearchqut/ERP-541_Clear_incorrect_pas…
Browse files Browse the repository at this point in the history
…sword

[ERP-541] Clear the password field on invalid log in.
  • Loading branch information
ppettitau authored Jan 17, 2025
2 parents 01bb26b + 056f5b2 commit 417485e
Show file tree
Hide file tree
Showing 22 changed files with 94 additions and 94 deletions.
12 changes: 6 additions & 6 deletions rdrf/rdrf/auth/password_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def validation_error_text(min_occurrences):
class ConsecutivelyRepeatingCharacterValidator:
def __init__(self, length=3):
self.length = length
assert (
self.length > 1
), "Length should be at least 2 for consecutively repeating character validators!"
assert self.length > 1, (
"Length should be at least 2 for consecutively repeating character validators!"
)
self.repeating_char = re.compile(
r"""
(.) # any character, in a group so we can backreference
Expand All @@ -117,9 +117,9 @@ def get_help_text(self):
class NumberRuleValidator(ABC):
def __init__(self, length=3):
self.length = length
assert (
self.length > 1
), "Length should be at least 2 for numbers related password validators!"
assert self.length > 1, (
"Length should be at least 2 for numbers related password validators!"
)

@staticmethod
@abstractmethod
Expand Down
2 changes: 1 addition & 1 deletion rdrf/rdrf/auth/pwned_passwords/pwned_passwords.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def range(self, hash_prefix):
return response.content

def _url(self, endpoint, *components):
return f'{self.base_url}/{endpoint}/{"/".join(components)}'
return f"{self.base_url}/{endpoint}/{'/'.join(components)}"

def _request_headers(self):
return {"Add-Padding": f"{str(self.add_padding).lower()}"}
6 changes: 3 additions & 3 deletions rdrf/rdrf/auth/signed_url/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def check_token(username_b64, token, max_token_age):

def make_token(username):
token_username, token = TimestampSigner().sign(username).split(":", 1)
assert (
username == token_username
), "Something went wrong with token generation"
assert username == token_username, (
"Something went wrong with token generation"
)
return token


Expand Down
6 changes: 3 additions & 3 deletions rdrf/rdrf/exporter_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def _export_cascading_form_definition(
non_null_args = [
arg for arg in [context_form_groups, forms, sections, cdes] if arg
]
assert (
len(non_null_args) == 1
), f"Expected 1 form definition part to be provided, got {len(non_null_args)}"
assert len(non_null_args) == 1, (
f"Expected 1 form definition part to be provided, got {len(non_null_args)}"
)

export_definition = {}

Expand Down
2 changes: 1 addition & 1 deletion rdrf/rdrf/forms/dsl/code_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def handle_instruction(self, inst):
cde_validation = target.invalid_cdes()
if cde_validation:
logger.error(
f'Invalid CDEs specified: {" ".join([str(cde) for cde in cde_validation])}'
f"Invalid CDEs specified: {' '.join([str(cde) for cde in cde_validation])}"
)
return []

Expand Down
2 changes: 1 addition & 1 deletion rdrf/rdrf/forms/dsl/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def check_rules(self):
errors.extend(self.handle_instruction(inst, idx + 1, checker))

if errors:
logger.info(f'DSL validation errors: {", ".join(errors)}')
logger.info(f"DSL validation errors: {', '.join(errors)}")
raise ValidationError(
{"conditional_rendering_rules": "\n".join(errors)}
)
2 changes: 1 addition & 1 deletion rdrf/rdrf/forms/navigation/quick_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class LinkDefs:
"admin:patients_patientstagerule_changelist", _("Patient Stages Rules")
)
PatientUser = QuickLink(
f'{reverse("admin:patients_patientuser_changelist")}?{urlencode({"linked": "N"})}',
f"{reverse('admin:patients_patientuser_changelist')}?{urlencode({'linked': 'N'})}",
_("Patient Users"),
)
Reports = make_link("report:reports_list", _("Reports"))
Expand Down
16 changes: 8 additions & 8 deletions rdrf/rdrf/forms/widgets/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,25 +648,25 @@ def render(self, name, value, attrs=None, renderer=None):
<div class="rdrf-cde-slider">
<div style="float:left; margin-right:20px;"><b>{_(left_label)}</b></div>
<div style="float:left">
<input type="hidden" id="{attrs['id']}" name="{name}" value="{value}"/>
<input type="hidden" id="{attrs["id"]}" name="{name}" value="{value}"/>
</div>
<div style="float:left;margin-left:20px;"><b>{_(right_label)}</b></div>
</div>
<br/>
<script>
$(function() {{
$( "#{attrs['id']}" ).bootstrapSlider({{
$( "#{attrs["id"]}" ).bootstrapSlider({{
tooltip: 'always',
id: '{attrs['id']}-slider',
id: '{attrs["id"]}-slider',
value: '{value}',
{widget_attrs}
}});
// Set the uninitialised / null value to ""
$( "#{attrs['id']}" ).val("{value}");
$( "#{attrs["id"]}" ).val("{value}");
// Set the uninitialised / null value to "-" in the tooltip
if ("{value}" === "") {{
$("#{attrs['id']}-slider .tooltip-inner").html("-");
$("#{attrs["id"]}-slider .tooltip-inner").html("-");
}};
// Set z-index to 0 for slider tooltip so it's not displayed through
Expand Down Expand Up @@ -955,9 +955,9 @@ def __init__(self, *args, **kwargs):
def extract_lookup_values(raw_value):
if raw_value:
values = raw_value.split(XnatWidget.SEPARATOR)
assert (
len(values) == 2
), f"Invalid split result. Expected 2, got {len(values)}"
assert len(values) == 2, (
f"Invalid split result. Expected 2, got {len(values)}"
)
return values

return None, None
Expand Down
2 changes: 1 addition & 1 deletion rdrf/rdrf/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def display(form_or_formset, field, error):
).replace("Set", "")
qualifier = de_camelcase(form_name)
if field:
qualifier += f' {field.replace("_", " ")}'
qualifier += f" {field.replace('_', ' ')}"
return f"{qualifier}: {error}"

for form in forms:
Expand Down
4 changes: 2 additions & 2 deletions rdrf/rdrf/services/io/defs/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def _create_cdes(self, cde_maps):
]
if import_value not in valid_types:
raise ValidationError(
f'Invalid data type {import_value} for CDE: {cde_map["code"]}'
f"Invalid data type {import_value} for CDE: {cde_map['code']}"
)
elif field == "widget_name":
import_value = CdeMappings.fix_widget_name(
Expand All @@ -486,7 +486,7 @@ def _create_cdes(self, cde_maps):
valid_widgets = get_widgets_for_data_type(data_type) + [""]
if import_value not in valid_widgets:
raise ValidationError(
f'Invalid widget_name {cde_map[field]} for datatype {data_type} and CDE: {cde_map["code"]}'
f"Invalid widget_name {cde_map[field]} for datatype {data_type} and CDE: {cde_map['code']}"
)

if not created:
Expand Down
2 changes: 1 addition & 1 deletion rdrf/rdrf/templates/two_factor/core/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
</div>
<div class="mb-3">
<label for="id_auth-password">{{ form.password.label }}:</label>
<input type="password" name="auth-password" class="form-control" value="{{ form.password.value|default:"" }}" required="required" id="id_auth-password">
<input type="password" name="auth-password" class="form-control" required="required" id="id_auth-password">
</div>
<div class="mb-3 form-check">
<input type="checkbox" id="id_toggle-password" class="form-check-input">
Expand Down
2 changes: 1 addition & 1 deletion rdrf/rdrf/testing/behaviour/features/auth/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def submit(self):

def get_site_links(site_url, registry_code):
def _make_url(resource):
return f'{"/".join([site_url, resource])}'
return f"{'/'.join([site_url, resource])}"

return {
key: _make_url(resource)
Expand Down
6 changes: 3 additions & 3 deletions rdrf/rdrf/testing/unit/quicklinks_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def assertContainsAll(self, values_dict, container):

def assertContainsNoneOf(self, values_dict, container):
for value in values_dict.values():
assert (
value not in container
), f"{value} found unexpectedly in {container}"
assert value not in container, (
f"{value} found unexpectedly in {container}"
)


class NormalQuickLinksTests(ExtraAssertionsMixin, RDRFTestCase):
Expand Down
84 changes: 42 additions & 42 deletions rdrf/rdrf/testing/unit/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,23 +275,23 @@ def check_cde_in_section(cde_code, section_dict):
if cde_dict_item["code"] == cde_code:
return True

assert not check_cde_in_section(
"CDE00016", s_section
), "CDE00016 is still in source section"
assert check_cde_in_section(
"CDE00016", t_section
), "CDE00016 is not in target section found"
assert not check_cde_in_section("CDE00016", s_section), (
"CDE00016 is still in source section"
)
assert check_cde_in_section("CDE00016", t_section), (
"CDE00016 is not in target section found"
)

assert not check_cde_in_section(
"FHCRP", s_section
), "FHCRP is still in source section"
assert check_cde_in_section(
"FHCRP", t_section
), "FHCRP is not in target section found"
assert not check_cde_in_section("FHCRP", s_section), (
"FHCRP is still in source section"
)
assert check_cde_in_section("FHCRP", t_section), (
"FHCRP is not in target section found"
)

assert check_cde_in_section(
"FHCompliance", s_section
), "FHCompliance has been moved."
assert check_cde_in_section("FHCompliance", s_section), (
"FHCompliance has been moved."
)


def mock_messages():
Expand Down Expand Up @@ -388,9 +388,9 @@ def test_user_in_wrong_group_cant_view_form(self):
def export_yaml_file_test(registry):
exporter = Exporter(registry)
yaml_data, errors = exporter.export_yaml()
assert isinstance(
errors, list
), "Expected errors list in exporter export_yaml"
assert isinstance(errors, list), (
"Expected errors list in exporter export_yaml"
)
assert len(errors) == 0, "Expected zero errors instead got:%s" % errors
assert isinstance(yaml_data, str), (
"Expected yaml_data is string:%s" % type(yaml_data)
Expand Down Expand Up @@ -808,22 +808,22 @@ def form_value(form_name, section_code, cde_code, mongo_record):
the_form = mongo_record["forms"][0]
assert isinstance(the_form, dict), "form data should be a dictionary"
assert "sections" in the_form, "A form should have a sections key"
assert isinstance(
the_form["sections"], list
), "Sections should be in a list"
assert isinstance(the_form["sections"], list), (
"Sections should be in a list"
)
# we've only written data for 2 sections
assert len(the_form["sections"]) == 2, (
"expected 2 sections got %s" % len(the_form["sections"])
)

for section_dict in the_form["sections"]:
assert isinstance(
section_dict, dict
), "sections should be dictioanaries"
assert isinstance(section_dict, dict), (
"sections should be dictioanaries"
)
assert "cdes" in section_dict, "sections should have a cdes key"
assert isinstance(
section_dict["cdes"], list
), "sections cdes key should be a list"
assert isinstance(section_dict["cdes"], list), (
"sections cdes key should be a list"
)
for cde in section_dict["cdes"]:
assert isinstance(cde, dict), "cde should be a dict"
assert "code" in cde, "cde dictionary should have a code key"
Expand Down Expand Up @@ -1527,9 +1527,9 @@ def test_cdes(self):
m = self.make_modjgo("cdes", good)
output = self._run_command(registry_code="foobar", collection="cdes")
print("output = [%s]" % output)
assert (
output == ""
), "check_structure test of good data should output nothing"
assert output == "", (
"check_structure test of good data should output nothing"
)

def test_history(self):
foobar = Registry()
Expand Down Expand Up @@ -1712,9 +1712,9 @@ class Time:

lines = result.split("\n")

assert (
"dummy send reg_code=foobar description=reminder" in lines[0]
), "send-reminders failed?"
assert "dummy send reg_code=foobar description=reminder" in lines[0], (
"send-reminders failed?"
)

# create some dummy email notification history models to simulate previous
# reminders being sent
Expand All @@ -1731,9 +1731,9 @@ class Time:

lines = result.split("\n")

assert (
"not sent" in lines
), "Expected reminder NOT to be sent if one already sent"
assert "not sent" in lines, (
"Expected reminder NOT to be sent if one already sent"
)

# 2nd one allowed
self._clear_notifications()
Expand All @@ -1750,9 +1750,9 @@ class Time:

lines = result.split("\n")
print(lines)
assert (
"dummy send reg_code=foobar description=reminder" in lines[0]
), "send-reminders failed?"
assert "dummy send reg_code=foobar description=reminder" in lines[0], (
"send-reminders failed?"
)

self._clear_notifications()
self._setup_user("testuser", Time.LONG_AGO)
Expand All @@ -1768,9 +1768,9 @@ class Time:

lines = result.split("\n")
print(lines)
assert (
"not sent" in lines
), "Expected reminder NOT to be sent if two or more already sent"
assert "not sent" in lines, (
"Expected reminder NOT to be sent if two or more already sent"
)


class ClinicalDataTestCase(RDRFTestCase):
Expand Down
4 changes: 2 additions & 2 deletions rdrf/rdrf/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ def post(self, request, *args, **kwargs):
messages.add_message(
request,
messages.SUCCESS,
f'{_("An Email address change request has been created for user: %s") % self.user.get_full_name()}',
f"{_('An Email address change request has been created for user: %s') % self.user.get_full_name()}",
)

return self._redirect_response()
else:
form.add_error(
NON_FIELD_ERRORS,
ValidationError(
f'{_("Email address change request has failed for user")}: {self.user.get_full_name()}'
f"{_('Email address change request has failed for user')}: {self.user.get_full_name()}"
),
)

Expand Down
6 changes: 3 additions & 3 deletions rdrf/rdrf/views/context_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ def allowed(self, user, registry_code, patient_id, context_id=None):
def create_context_and_goto_form(
self, registry_model, patient_model, context_form_group
):
assert (
len(context_form_group.forms) == 1
), "Direct link only possible if num forms in form group is 1"
assert len(context_form_group.forms) == 1, (
"Direct link only possible if num forms in form group is 1"
)
patient_content_type = ContentType.objects.get_for_model(patient_model)
form_model = context_form_group.forms[0]
context_model = RDRFContext()
Expand Down
2 changes: 1 addition & 1 deletion rdrf/rdrf/views/registration_rdrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def get_success_url(self, user):
login(
self.request, user, "django.contrib.auth.backends.ModelBackend"
)
return f'{reverse("two_factor:login")}?next={reverse("login_router")}?new_activation=True'
return f"{reverse('two_factor:login')}?next={reverse('login_router')}?new_activation=True"


def validate_recaptcha(response_value):
Expand Down
2 changes: 1 addition & 1 deletion rdrf/registry/groups/admin_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def __init__(self, *args, **kwargs):
"user_email_change", kwargs={"user_id": self.instance.id}
)
sync_email_help_text = (
f'{_("Synchronised email address changes can be made using")}: '
f"{_('Synchronised email address changes can be made using')}: "
f'<a href="{change_email_url}">{_("Change email address form")}</a>.'
)
self.fields["username"].help_text += mark_safe(
Expand Down
2 changes: 1 addition & 1 deletion rdrf/registry/patients/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def patient(self, patient_model):
if patient_model.guid:
patient_attrs.append(f"GUID: {patient_model.guid}")

return f'{patient_model.display_name} ({", ".join(patient_attrs)})'
return f"{patient_model.display_name} ({', '.join(patient_attrs)})"

def get_list_display(self, request):
supports_guid = any(
Expand Down
Loading

0 comments on commit 417485e

Please sign in to comment.