Skip to content

Commit

Permalink
#140 - added api endpoint to reset password
Browse files Browse the repository at this point in the history
  • Loading branch information
jjoseba committed May 22, 2024
1 parent bb260e7 commit b121c24
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
3 changes: 2 additions & 1 deletion api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from fcm_django.api.rest_framework import FCMDeviceAuthorizedViewSet

from api.views import NodeViewSet, ProviderViewSet, CategoryViewSet
from api.views.auth import LoginView, LogoutView
from api.views.auth import LoginView, LogoutView, ResetPasswordView
from api.views.benefits import BenefitsViewSet
from api.views.consumer import ConsumerViewSet
from api.views.member_status import MemberStatusViewSet
Expand All @@ -24,6 +24,7 @@
path("v2/", include(router.urls)),
path("v2/login/", LoginView.as_view()),
path("v2/logout/", LogoutView.as_view()),
path("v2/reset_password/", ResetPasswordView.as_view()),
path("v2/member_status/", MemberStatusViewSet.as_view()),
re_path(r"v2/nodes/(?P<node>\d+)/consumer/", ConsumerViewSet.as_view()),

Expand Down
41 changes: 20 additions & 21 deletions api/views/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from rest_framework.views import APIView
from django.utils.translation import gettext_lazy as _

from authentication.forms.password import PasswordReset
from authentication.models.api_token import APIToken
from market.models import Account, Provider

Expand Down Expand Up @@ -121,24 +122,22 @@ def delete(self, request, format=None):
user = APIToken.objects.get(pk=request.user.auth_token).user
user.delete()
logout(request)
return Response(
status=status.HTTP_200_OK,
data={'response': _('Usuario eliminado con éxito.')}
)

#
# class ResetPasswordView(APIView):
# permission_classes = (AllowAny,)
#
# def post(self, request, *args, **kwargs):
# user_email = request.data['email']
# logger.info(f"Starting reset password process for user [{user_email}]")
# try:
# user = User.objects.get(email=user_email)
# reset_password_token, created = ResetPasswordToken.objects.update_or_create(user=user)
# except User.DoesNotExist:
# return Response(status=status.HTTP_404_NOT_FOUND)
#
# email.send_email(user, email.RESET_PASSWORD_EMAIL, {"reset_password_token": reset_password_token.key})
# return Response(status=status.HTTP_200_OK)
#
return Response(status=status.HTTP_200_OK, data={'response': _('Usuario eliminado con éxito.')} )


class ResetPasswordView(APIView):
permission_classes = (AllowAny,)

def post(self, request, *args, **kwargs):
email = request.data.get('email')
logger.info(f"Starting reset password process for email [{email}]")
try:
User.objects.get(email=email)
reset_form = PasswordReset(request.data)
if reset_form.is_valid():
reset_form.save()
return Response(status=status.HTTP_200_OK)
else:
return Response(status=status.HTTP_400_BAD_REQUEST, data=reset_form.errors)
except User.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)

0 comments on commit b121c24

Please sign in to comment.