Skip to content

Commit

Permalink
fix password check
Browse files Browse the repository at this point in the history
  • Loading branch information
submarcos committed Apr 29, 2024
1 parent 393aba1 commit 5859bf6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion georiviere/contribution/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-04-29 07:30+0000\n"
"POT-Creation-Date: 2024-04-29 07:55+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down
2 changes: 1 addition & 1 deletion georiviere/contribution/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-04-29 07:30+0000\n"
"POT-Creation-Date: 2024-04-29 07:55+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down
14 changes: 5 additions & 9 deletions georiviere/portal/serializers/contribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.contrib.gis.geos import GEOSGeometry
from django.db import transaction
from django.db.models import ForeignKey
from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext as _

from georiviere.contribution.schema import (
get_contribution_properties,
Expand Down Expand Up @@ -228,6 +228,7 @@ def __init__(self, *args, **kwargs):
self.fields["password"] = serializers.CharField(required=True, write_only=True)

def create(self, validated_data):
validated_data.pop("password", None)
custom_type = self.context.get("custom_type")
# add and customize fields from json schema
schema = custom_type.get_json_schema_form()
Expand All @@ -239,16 +240,11 @@ def create(self, validated_data):
validated_data["data"] = data
return super().create(validated_data)

def validate(self, data):
# check password if required
def validate_password(self, value):
custom_type = self.context.get("custom_type")
if (
custom_type
and custom_type.password
and data.get("password", "") != custom_type.password
):
if custom_type and custom_type.password and value != custom_type.password:
raise serializers.ValidationError(_("Password mismatch."))
return data
return value

class Meta:
model = CustomContribution
Expand Down
3 changes: 2 additions & 1 deletion georiviere/portal/views/contribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ def create_contribution(self, request, *args, **kwargs):
custom_type = self.get_object()
context["custom_type"] = custom_type
serializer = self.get_serializer(data=request.data, context=context)
serializer.is_valid(raise_exception=True)
if not serializer.is_valid():
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
extra_save_params = {}
# if station selected, save its geom
if "station" in serializer.validated_data:
Expand Down

0 comments on commit 5859bf6

Please sign in to comment.