Skip to content

Commit

Permalink
Merge pull request #56 from cookiewho/userAPIimplementation
Browse files Browse the repository at this point in the history
Fixing error checking for password
  • Loading branch information
MrJKappa authored Oct 22, 2021
2 parents 42d96de + dee76ef commit 117445c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 10 additions & 1 deletion wishlist/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from rest_framework.authtoken.views import Token
from rest_framework.exceptions import NotAuthenticated
from .models import UserList, Item
import re

class UserSerializer(serializers.ModelSerializer):
password2 =serializers.CharField(style={'input_type': 'password'}, write_only=True)
Expand All @@ -25,10 +26,18 @@ def save(self):
password = self.validated_data['password']
password2 = self.validated_data['password2']
if password != password2:
raise serializers.ValidationError({'password': "Password must match."})
raise serializers.ValidationError({"Password must match.": "Password"})
if len(password) < 6 :
print("password is small")
raise serializers.ValidationError({"Password must be greater than 6 characters.": "Password"})
if re.match(r"^(?=.*[\d])(?=.*[A-Z])(?=.*[a-z])(?=.*[!?@#$])[\w\d!?@#$]{6,15}$", password) == False:
print("password is not valid")
raise serializers.ValidationError({ "Password must include 1 lower case and 1 upper case lette, as well as a special character !.?,@,#, or $.": "Password"})

user.set_password(password)
user.save()
return user




Expand Down
5 changes: 4 additions & 1 deletion wishlist/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ def create_users(request):
#Save the new user list
newUserList.save()
return Response(serializer1.data, status=status.HTTP_200_OK)
return Response(serializer1.errors, status=status.HTTP_400_BAD_REQUEST)
errors = []
for key, values in serializer1.errors.items():
errors = [value[:] for value in values]
return Response(errors, status=status.HTTP_400_BAD_REQUEST)

#[url]/api/login/
@api_view(['POST'])
Expand Down

0 comments on commit 117445c

Please sign in to comment.