37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
"""Web account views"""
|
|
from rest_framework import status, generics
|
|
from rest_framework.response import Response
|
|
|
|
from account import models
|
|
from account.serializers import web as serializers
|
|
from utils import exceptions as utils_exceptions
|
|
|
|
|
|
# Password reset
|
|
class PasswordResetView(generics.GenericAPIView):
|
|
"""View for resetting user password"""
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
"""Post-method for password resetting"""
|
|
user = request.user
|
|
obj = models.ResetPasswordToken.objects.create(
|
|
user=user,
|
|
ip_address=request.META.get('REMOTE_ADDR'),
|
|
source=models.ResetPasswordToken.MOBILE
|
|
)
|
|
try:
|
|
# todo: make as celery task
|
|
obj.send_reset_password_request()
|
|
return Response(status=status.HTTP_200_OK)
|
|
except:
|
|
raise utils_exceptions.EmailSendingError(user.email)
|
|
|
|
|
|
class PasswordResetConfirmView(generics.GenericAPIView):
|
|
"""View for confirmation new password"""
|
|
|
|
serializer_class = serializers.PasswordResetConfirmSerializer
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
"""Post method to confirm user change password request"""
|