Add docker setup for demo project

This commit is contained in:
Gabriel Le Breton 2019-07-03 11:09:27 -04:00
parent 3e8a7e308c
commit 18983960a1
4 changed files with 26 additions and 5 deletions

8
demo/Dockerfile Normal file
View File

@ -0,0 +1,8 @@
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/

View File

@ -150,6 +150,6 @@ CACHES = {
}
REST_AUTH_SERIALIZERS = {
'LOGIN_SERIALIZER': 'myapp.serializers.RestAuthLoginSerializer',
'LOGIN_SERIALIZER': 'myapp.serializers.RestAuthAxesLoginSerializer',
# 'TOKEN_SERIALIZER': 'path.to.custom.TokenSerializer',
}

13
demo/docker-compose.yml Normal file
View File

@ -0,0 +1,13 @@
version: '3'
services:
web:
build: .
image: gableroux/django-rest-auth-demo
command: python manage.py runserver 0.0.0.0:1234
environment:
PYTHONUNBUFFERED: 1
volumes:
- .:/code
ports:
- "1234:1234"

View File

@ -5,12 +5,12 @@ from rest_framework import exceptions
# noinspection PyAbstractClass
class RestAuthLoginSerializer(LoginSerializer):
class RestAuthAxesLoginSerializer(LoginSerializer):
def validate(self, attrs):
try:
attrs = super().validate(attrs)
except exceptions.ValidationError:
return super().validate(attrs)
except exceptions.ValidationError as e:
if getattr(self.context['request'], 'axes_locked_out', None):
raise serializers.ValidationError(get_lockout_message())
return attrs
raise e