post instead of put in get_ott
This commit is contained in:
parent
ad2b8ab091
commit
9e2b7e0fa7
2 changed files with 11 additions and 16 deletions
|
|
@ -149,13 +149,8 @@ class User(AbstractUser):
|
|||
self.otp_try = 0
|
||||
|
||||
def set_ott(self):
|
||||
# TODO: get and set application
|
||||
if settings.DEBUG or self.phone_number in DEVELOPMENT_PHONE_NUMBERS:
|
||||
self.ott = 'abcdef12345'
|
||||
|
||||
else:
|
||||
self.ott = ''.join(random.choice(string.ascii_letters+string.digits+string.punctuation) for _ in range(32))
|
||||
|
||||
self.ott = ''.join(random.choice(string.ascii_letters+string.digits+'()*%#@.') for _ in range(32))
|
||||
# self.ott = ''.join(random.choice(string.ascii_letters+string.digits+string.punctuation) for _ in range(32))
|
||||
self.ott_expire = timezone.now() + timedelta(seconds=300)
|
||||
|
||||
def otp_is_valid(self):
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ from apps.gooyal_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRe
|
|||
from apps.users.forms import OTPAuthenticationForm, ProfileUpdateForm
|
||||
from apps.users.models import User
|
||||
from apps.users.provinces_and_cities import State
|
||||
from apps.users.serializers import PublicUserSerializer, AccountSerializer, RequestOTPSerializer, RequestOTTSerializer,\
|
||||
from apps.users.serializers import PublicUserSerializer, AccountSerializer, RequestOTPSerializer, RequestOTTSerializer, \
|
||||
ChangePasswordSerializer, UserInquirySerializer
|
||||
|
||||
UserModel = get_user_model()
|
||||
|
|
@ -63,7 +63,7 @@ class RequestOTPView(generics.CreateAPIView):
|
|||
required_scopes = []
|
||||
|
||||
|
||||
class RequestOTTView(generics.UpdateAPIView):
|
||||
class RequestOTTView(generics.CreateAPIView):
|
||||
permission_classes = [IsAuthenticatedOrTokenHasScope]
|
||||
required_scopes = ['accounts.account:request_ott']
|
||||
serializer_class = RequestOTTSerializer
|
||||
|
|
@ -71,12 +71,13 @@ class RequestOTTView(generics.UpdateAPIView):
|
|||
def get_object(self):
|
||||
return self.request.user
|
||||
|
||||
def update(self, request, *args, **kwargs):
|
||||
# TODO: move it to query set
|
||||
user = self.get_object()
|
||||
user.set_ott()
|
||||
user.save()
|
||||
return super().update(request, *args, **kwargs)
|
||||
def create(self, request, *args, **kwargs):
|
||||
instance: User = self.get_object()
|
||||
serializer = self.get_serializer(instance, data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
instance.set_ott()
|
||||
instance.save()
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
class UserInquiryView(generics.CreateAPIView):
|
||||
|
|
@ -147,4 +148,3 @@ class ProfileUpdateView(UpdateView):
|
|||
|
||||
def form_valid(self, form):
|
||||
return super().form_valid(form)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue