mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-19 04:49:37 +02:00
migration to new backend
This commit is contained in:
parent
28a5d423c2
commit
9abe9fb315
309 changed files with 21476 additions and 24132 deletions
28
backend/server/users/views.py
Normal file
28
backend/server/users/views.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from .serializers import ChangeEmailSerializer
|
||||
from drf_yasg.utils import swagger_auto_schema
|
||||
from drf_yasg import openapi
|
||||
|
||||
class ChangeEmailView(APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
@swagger_auto_schema(
|
||||
request_body=ChangeEmailSerializer,
|
||||
responses={
|
||||
200: openapi.Response('Email successfully changed'),
|
||||
400: 'Bad Request'
|
||||
},
|
||||
operation_description="Change the email address for the authenticated user."
|
||||
)
|
||||
def post(self, request):
|
||||
serializer = ChangeEmailSerializer(data=request.data, context={'request': request})
|
||||
if serializer.is_valid():
|
||||
user = request.user
|
||||
new_email = serializer.validated_data['new_email']
|
||||
user.email = new_email
|
||||
user.save()
|
||||
return Response({"detail": "Email successfully changed."}, status=status.HTTP_200_OK)
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
Loading…
Add table
Add a link
Reference in a new issue