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
|
self.otp_try = 0
|
||||||
|
|
||||||
def set_ott(self):
|
def set_ott(self):
|
||||||
# TODO: get and set application
|
self.ott = ''.join(random.choice(string.ascii_letters+string.digits+'()*%#@.') for _ in range(32))
|
||||||
if settings.DEBUG or self.phone_number in DEVELOPMENT_PHONE_NUMBERS:
|
# self.ott = ''.join(random.choice(string.ascii_letters+string.digits+string.punctuation) for _ in range(32))
|
||||||
self.ott = 'abcdef12345'
|
|
||||||
|
|
||||||
else:
|
|
||||||
self.ott = ''.join(random.choice(string.ascii_letters+string.digits+string.punctuation) for _ in range(32))
|
|
||||||
|
|
||||||
self.ott_expire = timezone.now() + timedelta(seconds=300)
|
self.ott_expire = timezone.now() + timedelta(seconds=300)
|
||||||
|
|
||||||
def otp_is_valid(self):
|
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.forms import OTPAuthenticationForm, ProfileUpdateForm
|
||||||
from apps.users.models import User
|
from apps.users.models import User
|
||||||
from apps.users.provinces_and_cities import State
|
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
|
ChangePasswordSerializer, UserInquirySerializer
|
||||||
|
|
||||||
UserModel = get_user_model()
|
UserModel = get_user_model()
|
||||||
|
|
@ -63,7 +63,7 @@ class RequestOTPView(generics.CreateAPIView):
|
||||||
required_scopes = []
|
required_scopes = []
|
||||||
|
|
||||||
|
|
||||||
class RequestOTTView(generics.UpdateAPIView):
|
class RequestOTTView(generics.CreateAPIView):
|
||||||
permission_classes = [IsAuthenticatedOrTokenHasScope]
|
permission_classes = [IsAuthenticatedOrTokenHasScope]
|
||||||
required_scopes = ['accounts.account:request_ott']
|
required_scopes = ['accounts.account:request_ott']
|
||||||
serializer_class = RequestOTTSerializer
|
serializer_class = RequestOTTSerializer
|
||||||
|
|
@ -71,12 +71,13 @@ class RequestOTTView(generics.UpdateAPIView):
|
||||||
def get_object(self):
|
def get_object(self):
|
||||||
return self.request.user
|
return self.request.user
|
||||||
|
|
||||||
def update(self, request, *args, **kwargs):
|
def create(self, request, *args, **kwargs):
|
||||||
# TODO: move it to query set
|
instance: User = self.get_object()
|
||||||
user = self.get_object()
|
serializer = self.get_serializer(instance, data=request.data)
|
||||||
user.set_ott()
|
serializer.is_valid(raise_exception=True)
|
||||||
user.save()
|
instance.set_ott()
|
||||||
return super().update(request, *args, **kwargs)
|
instance.save()
|
||||||
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
class UserInquiryView(generics.CreateAPIView):
|
class UserInquiryView(generics.CreateAPIView):
|
||||||
|
|
@ -147,4 +148,3 @@ class ProfileUpdateView(UpdateView):
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue