django-chelseru 2.0.2__py3-none-any.whl → 2.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: django-chelseru
3
- Version: 2.0.2
3
+ Version: 2.0.3
4
4
  Summary: Authentication system, online and real-time chat, SMS & BANK system for Iranian SMS services.
5
5
  Home-page: https://pipdjango.chelseru.com
6
6
  Author: Sobhan Bahman Rashnu
@@ -1,4 +1,4 @@
1
- django_chelseru-2.0.2.dist-info/licenses/LICENSE,sha256=VupU5KV4NteHaNQb-WH31G_WZWezxXoomjiCIAHoQJo,1089
1
+ django_chelseru-2.0.3.dist-info/licenses/LICENSE,sha256=VupU5KV4NteHaNQb-WH31G_WZWezxXoomjiCIAHoQJo,1089
2
2
  drfchelseru/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  drfchelseru/admin.py,sha256=uamcWPCCw9_dD00XL8Brp8A1NvfhB5FtUfF9DWQCK9c,1022
4
4
  drfchelseru/apps.py,sha256=hOTTzFGLXiTPZeN8p_LLcSECLtsR2Q0SUo8zJzgM-qQ,211
@@ -13,7 +13,7 @@ drfchelseru/signals.py,sha256=CI1mZR5RrdOddXBnPC1eMdt9iQkYFDypfgogtfTc2eQ,2714
13
13
  drfchelseru/tests.py,sha256=mrbGGRNg5jwbTJtWWa7zSKdDyeB4vmgZCRc2nk6VY-g,60
14
14
  drfchelseru/urls.py,sha256=qD3As2gSCEaNDxgU0ejIADLUt9t2EvoaTmqeiV1LRSA,898
15
15
  drfchelseru/validators.py,sha256=jAJASfG4kPcqrGxxIcoR8VjS4L4n_EzZuxJtQ1g9qmo,480
16
- drfchelseru/views.py,sha256=shi3cd19Zxk-nCFr-cK40PtArS3Howu7d6t7x_dxFlE,18079
16
+ drfchelseru/views.py,sha256=-_9Oxa6w26XfnMdc4WTMMxIOYyF0jEsU3i-QkxG3Cqo,19821
17
17
  drfchelseru/migrations/0001_initial.py,sha256=LfkWAeQuPXNW3_igM-w_pyKafCeHQF3aReYgMXfMzEE,1034
18
18
  drfchelseru/migrations/0002_otpcode_session_user.py,sha256=c3oyBTQo2kjsKr5r_XQrqaq-66F7pui-4H4mEyAXgJk,3126
19
19
  drfchelseru/migrations/0003_rename_mobile_otpcode_mobile_number.py,sha256=eiD7t6etg6nOeT7BhJrSfEcR1yTPePXtATgtyu30520,377
@@ -37,7 +37,7 @@ drfchelseru/migrations/0020_payment_paid_at.py,sha256=H6cr-tfjJVjN3tCsCD8ecg9JGJ
37
37
  drfchelseru/migrations/0021_alter_payment_message.py,sha256=g5qIvQ-wecdXGcMf7ZhyfL2u85QpgMUOADHE7t4QHog,397
38
38
  drfchelseru/migrations/0022_payment_pay_mode_wallet.py,sha256=241lZITO1jQHqXkJKYm8DKUh7w9rmROh65LzNifP3BA,1521
39
39
  drfchelseru/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
- django_chelseru-2.0.2.dist-info/METADATA,sha256=XpDHKGThjY6g1xxY19GijeYm8hZTWBjjp1yMEM5F3g4,18242
41
- django_chelseru-2.0.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
42
- django_chelseru-2.0.2.dist-info/top_level.txt,sha256=fsaO1F03W3j4AYi0TfDGv5Cjb_Qrh6RSkwkWqfqaMns,12
43
- django_chelseru-2.0.2.dist-info/RECORD,,
40
+ django_chelseru-2.0.3.dist-info/METADATA,sha256=cRjVWcexYIJrSAMaZHOtzif4IysWpeuauStOTyTNE4Q,18242
41
+ django_chelseru-2.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
42
+ django_chelseru-2.0.3.dist-info/top_level.txt,sha256=fsaO1F03W3j4AYi0TfDGv5Cjb_Qrh6RSkwkWqfqaMns,12
43
+ django_chelseru-2.0.3.dist-info/RECORD,,
drfchelseru/views.py CHANGED
@@ -13,11 +13,18 @@ from .validators import mobile_number as mobile_validator
13
13
  from .serializers import MessageSerializer, OTPCodeSerializer, SessionSerializer, ChatRoomSerializer, MessageChatSerializer, PaymentSerializer
14
14
  from .models import User, ChatRoom
15
15
  from django.utils.timezone import now, timedelta
16
- from django.db import transaction
16
+ from django.db import transaction, IntegrityError, OperationalError
17
17
 
18
18
  from django.conf import settings
19
19
  from django.core.exceptions import ImproperlyConfigured
20
20
 
21
+ import traceback
22
+ import time
23
+ import logging
24
+
25
+
26
+ logger = logging.getlogger(__name__)
27
+
21
28
 
22
29
  class MessageSend(APIView):
23
30
  permission_classes = (AllowAny, )
@@ -164,18 +171,14 @@ class Authentication(APIView):
164
171
  try:
165
172
  if 'mobile_number' not in request.data:
166
173
  return Response({'error': 'mobile_number is required.'}, status=HTTP_204_NO_CONTENT)
167
- # assert 'mobile_number' in request.data, 'mobile_number is required.'
168
174
  mobile_number = request.data['mobile_number']
169
175
  if not mobile_number:
170
176
  return Response({'error': 'mobile_number may not be blank.'}, status=HTTP_204_NO_CONTENT)
171
- # assert mobile_number, 'mobile_number may not be blank.'
172
177
  mobile_number_isvalid = mobile_validator(mobile_number)
173
178
  if mobile_number_isvalid != True:
174
179
  return Response({'error': mobile_number_isvalid}, status=HTTP_204_NO_CONTENT)
175
- # assert mobile_number_isvalid == True, mobile_number_isvalid
176
180
  if 'code' not in request.data:
177
181
  return Response({'error': 'code is required.'}, status=HTTP_204_NO_CONTENT)
178
- # assert 'code' in request.data, 'code is required.'
179
182
 
180
183
  icheck = auth_init_check()
181
184
  if icheck and isinstance(icheck, dict) and 'AUTH_SERVICE' in icheck and 'AUTH_METHOD' in icheck:
@@ -185,9 +188,36 @@ class Authentication(APIView):
185
188
  return Response({'error': 'The code sent to this mobile number was not found.'}, status=HTTP_401_UNAUTHORIZED)
186
189
 
187
190
  if otp.check_code():
191
+ user = None
188
192
  # login / signup
189
- group = int(request.data['group']) if 'group' in request.data else 0
190
- user, created = User.objects.get_or_create(mobile=mobile_number, group=group)
193
+ try:
194
+ group = int(request.data.get('group'), 0)
195
+ except (ValueError, TypeError):
196
+ group = 0
197
+
198
+ try:
199
+ with transaction.atomic():
200
+ user, created = User.objects.get_or_create(mobile=mobile_number, group=group)
201
+
202
+ except IntegrityError as e:
203
+ logger.warning("IntegrityError on get_or_create for mobile=%s, group=%s: %s", mobile_number, group, e)
204
+ time.sleep(0.05)
205
+ try:
206
+ user = User.objects.get(mobile=mobile_number, group=group)
207
+ created = False
208
+ except User.DoesNotExist:
209
+ logger.error("After IntegrityError, user still not exists for mobile=%s. Trace: %s", mobile_number, traceback.format_exc())
210
+ return Response({'error': 'Server error while creating user.'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
211
+ except OperationalError as e:
212
+ logger.error("OperationalError when accessing DB for mobile=%s: %s\n%s", mobile_number, e, traceback.format_exc())
213
+ return Response({'error': 'Database operational error, try again later.'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
214
+ except Exception as e:
215
+ logger.exception("Unexpected error in user get_or_create for mobile=%s: %s", mobile_number, e)
216
+ return Response({'error': 'An internal error occurred.'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
217
+
218
+
219
+
220
+ # user, created = User.objects.get_or_create(mobile=mobile_number, group=group)
191
221
  if user:
192
222
  auth_method = icheck['AUTH_METHOD']
193
223
  auth_service = icheck['AUTH_SERVICE']
@@ -206,9 +236,10 @@ class Authentication(APIView):
206
236
  raise
207
237
  except AssertionError as e:
208
238
  return Response({'error': str(e)}, status=HTTP_204_NO_CONTENT)
209
- except:
210
- pass
211
- return Response({'error': 'An error occurred while generating or sending the otpcode, please contact the www.chelseru.com support team.'}, status=HTTP_500_INTERNAL_SERVER_ERROR)
239
+ except Exception:
240
+ logger.exception("Error while creating tokens for user (mobile=%s). user object: %r", mobile_number, user)
241
+ return Response({'error': 'Token generation failed.'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
242
+ # return Response({'error': 'An error occurred while generating or sending the otpcode, please contact the www.chelseru.com support team.'}, status=HTTP_500_INTERNAL_SERVER_ERROR)
212
243
 
213
244
 
214
245
  class SessionList(ListAPIView):