django-chelseru 1.0.7__py3-none-any.whl → 1.0.9__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,14 +1,14 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: django-chelseru
3
- Version: 1.0.7
3
+ Version: 1.0.9
4
4
  Summary: Authentication system, online and real-time chat, SMS system for Iranian SMS services.
5
5
  Home-page: https://pipdjango.chelseru.com
6
- Author: Sobhan Bahman|Rashnu
6
+ Author: Sobhan Bahman Rashnu
7
7
  Author-email: bahmanrashnu@gmail.com
8
8
  Project-URL: Documentation, https://github.com/Chelseru/django-chelseru-lour/
9
9
  Project-URL: Telegram Group, https://t.me/bahmanpy
10
10
  Project-URL: Telegram Channel, https://t.me/ChelseruCom
11
- Keywords: djangochelseruchat djangochat drfchat online-chat online real-time chat iran chelseru lor lur bahman rashnu lour sms djangoauth auth ywt otpauth otp authentication djangootp djangoiransms iransms djangosms djangokavenegar djangomelipayamak sobhan چت سبحان بهمن رشنو چلسرو جنگو پایتون لر لور آنلاین ریل تایم
11
+ Keywords: djangochelseruchat djangochat drfchat online-chat online real-time chat iran chelseru lor lur bahman rashnu rashno lak lour sms djangoauth auth ywt otpauth otp authentication djangootp djangoiransms iransms djangosms djangokavenegar djangomelipayamak sobhan چت سبحان بهمن رشنو چلسرو جنگو پایتون لر لور آنلاین ریل تایم
12
12
  Classifier: Programming Language :: Python :: 3
13
13
  Classifier: Framework :: Django
14
14
  Classifier: License :: OSI Approved :: MIT License
@@ -1,14 +1,14 @@
1
- django_chelseru-1.0.7.dist-info/licenses/LICENSE,sha256=VupU5KV4NteHaNQb-WH31G_WZWezxXoomjiCIAHoQJo,1089
1
+ django_chelseru-1.0.9.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=8X67Sy8k5qQzZ4ifuJ_5O-UqVWby4uX53Iq-KNuODxM,948
4
4
  drfchelseru/apps.py,sha256=hOTTzFGLXiTPZeN8p_LLcSECLtsR2Q0SUo8zJzgM-qQ,211
5
- drfchelseru/consumers.py,sha256=x64hPCd5FViFsFMyDIcxPOh2OWVpeNq1BaOdhYk0HUI,2620
6
- drfchelseru/middlewares.py,sha256=adrhoJE7uo4WISfSIXK41XMQQzMaBshq3r61RblMPAQ,2570
5
+ drfchelseru/consumers.py,sha256=c8h9JYu5QUSKRREFrIrkjpkEQTzG5V8eg2lriaZODsc,2614
6
+ drfchelseru/middlewares.py,sha256=2GT9wTkqfQIUQyVkecul2V4hssvhkKjYpHErvVmvY14,3808
7
7
  drfchelseru/models.py,sha256=9Wa-_Xk28zpFQ4HoRbQdcboZpjUFqxKHpZd05Vx8xXs,6296
8
8
  drfchelseru/routing.py,sha256=shAlgzcIwVuVPlvKeWBLCqr6PuBTHyIrWNgHEfnqrxg,165
9
9
  drfchelseru/serializers.py,sha256=tM7dN362Vdx0UXq6OfNmYh6rTN1bwFoEgOn1MG4CZIY,1299
10
- drfchelseru/services.py,sha256=FkJlsFtTSiwwQ6g-nkSuV8XvY-dX-abAY_0WGbD0Ppw,10139
11
- drfchelseru/settings.py,sha256=ksiuFgjf1HZC6dajQXEra67WyUH6vYqjcQT81NdhELw,9051
10
+ drfchelseru/services.py,sha256=RAQsn95ByUoxUOnlRx-mVPr38mjwjP8Ff5tao_9t6YE,11550
11
+ drfchelseru/settings.py,sha256=wKWud5LVHpuNhjRrkg3tvN5FkhSmQ-z8mQwQ42xfERs,11497
12
12
  drfchelseru/signals.py,sha256=nmFv208GW9nir9PAB0a1050OMh4I9em0n60O6Mgfwec,2554
13
13
  drfchelseru/tests.py,sha256=mrbGGRNg5jwbTJtWWa7zSKdDyeB4vmgZCRc2nk6VY-g,60
14
14
  drfchelseru/urls.py,sha256=2RllsBPgojGLxLkyaBsSGk7fU1q44nuA7I_VpeHCmbs,702
@@ -26,7 +26,7 @@ drfchelseru/migrations/0009_alter_chatroom_status.py,sha256=QaAEUpERV8rnN-ifimA-
26
26
  drfchelseru/migrations/0010_chatroom_banneds_chatroom_descriptions_chatroom_name_and_more.py,sha256=aeotKPmdFJSjeA2-9VGApLfpx-NJkOrRJI2j2mdkf1U,1198
27
27
  drfchelseru/migrations/0011_alter_chatroom_user_1_alter_chatroom_user_2.py,sha256=9R66LzIujkh_4BpWtobpOvx3NALsMKUmtI5GDZXoSxQ,971
28
28
  drfchelseru/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
- django_chelseru-1.0.7.dist-info/METADATA,sha256=j4E0jhdk4vn4nXDFIMzpDW7qD-1L8Qg0Al_3kjFMdjQ,10933
30
- django_chelseru-1.0.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
31
- django_chelseru-1.0.7.dist-info/top_level.txt,sha256=fsaO1F03W3j4AYi0TfDGv5Cjb_Qrh6RSkwkWqfqaMns,12
32
- django_chelseru-1.0.7.dist-info/RECORD,,
29
+ django_chelseru-1.0.9.dist-info/METADATA,sha256=sJiV6cXgiGsm0lYOZVWqr50BJPOtQI21aDJ6RoLzGXE,10944
30
+ django_chelseru-1.0.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
31
+ django_chelseru-1.0.9.dist-info/top_level.txt,sha256=fsaO1F03W3j4AYi0TfDGv5Cjb_Qrh6RSkwkWqfqaMns,12
32
+ django_chelseru-1.0.9.dist-info/RECORD,,
drfchelseru/consumers.py CHANGED
@@ -10,7 +10,7 @@ User = get_user_model()
10
10
  class ChatConsumer(AsyncWebsocketConsumer):
11
11
  @sync_to_async
12
12
  def is_user_in_chat_room(self, user, chat_room):
13
- if chat_room.users.filter(user__id=user.id).exists():
13
+ if chat_room.users.filter(id=user.id).exists():
14
14
  return True
15
15
  return user == chat_room.user_1 or user == chat_room.user_2
16
16
 
@@ -9,6 +9,8 @@ from rest_framework_simplejwt.tokens import AccessToken
9
9
  from django.contrib.auth import get_user_model
10
10
  from asgiref.sync import sync_to_async
11
11
 
12
+ from .settings import auth_init_check, AUTH_SERVICE_DJSESSION, AUTH_SERVICE_DJSESSION
13
+
12
14
 
13
15
  class TakeUserSessionMiddlaware:
14
16
  def __init__(self, get_response):
@@ -21,26 +23,55 @@ class TakeUserSessionMiddlaware:
21
23
  user_agent = request.META.get('HTTP_USER_AGENT', '')
22
24
  ip = self.get_client_ip(request)
23
25
 
24
- if not request.session.session_key:
25
- request.session.create()
26
-
27
- session_key = request.session.session_key
28
-
29
- session, created = Session.objects.get_or_create(
30
- user = request.user,
31
- session_key = session_key,
32
- defaults = {
33
- 'user_agent': user_agent,
34
- 'ip_address': ip,
35
- 'device': user_agents.parse(user_agent).device.family,
36
- 'browser': user_agents.parse(user_agent).browser.family,
37
- }
38
- )
39
-
40
- session.user_agent = user_agent
41
- session.ip_address = ip
42
- session.last_seen = datetime.now()
43
- session.save()
26
+ icheck = auth_init_check()
27
+ session = None
28
+
29
+ if icheck['AUTH_SERVICE'] == AUTH_SERVICE_DJSESSION:
30
+ if not request.session.session_key:
31
+ request.session.create()
32
+ session_key = request.session.session_key
33
+
34
+ try:
35
+ # get session
36
+ session = Session.objects.get(session_key=session_key)
37
+
38
+ except Session.DoesNotExist:
39
+ # create
40
+ session = Session.objects.create(
41
+ user = request.user,
42
+ session_key = session_key,
43
+ )
44
+
45
+ elif icheck['AUTH_SERVICE'] == AUTH_SERVICE_JWT:
46
+ try:
47
+ session = Session.objects.get(user=request.user)
48
+ except Session.DoesNotExist:
49
+ pass
50
+
51
+ if session:
52
+ session.user_agent = user_agent
53
+ session.ip_address = ip_address
54
+ session.device = user_agents.parse(user_agent).device.family
55
+ session.browser = user_agents.parse(user_agent).browser.family
56
+ session.last_seen = datetime.now()
57
+
58
+ session.save()
59
+
60
+ # session, created = Session.objects.get_or_create(
61
+ # user = request.user,
62
+ # session_key = session_key,
63
+ # defaults = {
64
+ # 'user_agent': user_agent,
65
+ # 'ip_address': ip,
66
+ # 'device': user_agents.parse(user_agent).device.family,
67
+ # 'browser': user_agents.parse(user_agent).browser.family,
68
+ # }
69
+ # )
70
+
71
+ # session.user_agent = user_agent
72
+ # session.ip_address = ip
73
+ # session.last_seen = datetime.now()
74
+ # session.save()
44
75
 
45
76
  return response
46
77
 
drfchelseru/services.py CHANGED
@@ -5,7 +5,7 @@ from zeep import Client
5
5
  from rest_framework.status import HTTP_200_OK, HTTP_204_NO_CONTENT, HTTP_500_INTERNAL_SERVER_ERROR, HTTP_502_BAD_GATEWAY, HTTP_401_UNAUTHORIZED, HTTP_400_BAD_REQUEST
6
6
 
7
7
 
8
- from .settings import sms_init_check
8
+ from .settings import sms_init_check, bank_init_check
9
9
 
10
10
 
11
11
  class ParsianWebcoIr:
@@ -237,3 +237,51 @@ def send_message(mobile_number, message_text, data=None, template_id=None):
237
237
  return False, {'details': 'Invalid response structure.', 'error': str(e)}
238
238
 
239
239
  return response_bool, {'data': response_data, 'obj_status': obj_status, 'status': response_status_code}
240
+
241
+
242
+
243
+
244
+ class ZarinpalCom:
245
+ """
246
+ merchant_id
247
+ currency
248
+ """
249
+ def __init__(self, merchant_id):
250
+ self.merchant_id = merchant_id
251
+
252
+ def create_payment(self, amount, callback_url, description, order_id=None, mobile=None, email=None, currency=None, **metadata):
253
+ '''
254
+ curl -X POST \
255
+ https://payment.zarinpal.com/pg/v4/payment/request.json \
256
+ -H 'accept: application/json' \
257
+ -H 'content-type: application/json' \
258
+ -d '{
259
+ "merchant_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
260
+ "amount": 1000,
261
+ "callback_url": "http://your-site.com/verify",
262
+ "description": "Transaction description.",
263
+ "metadata": {"mobile": "09121234567","email": "info.test@gmail.com"}
264
+ }
265
+ ___
266
+
267
+ {
268
+ "data": {
269
+ "code": 100,
270
+ "message": "Success",
271
+ "authority": "A0000000000000000000000000000wwOGYpd",
272
+ "fee_type": "Merchant",
273
+ "fee": 100
274
+ },
275
+ "errors": []
276
+ }
277
+ '''
278
+ try:
279
+ icheck = bank_init_check()
280
+ if not icheck:
281
+ raise ImproperlyConfigured('Configure Bank in DJANGO_CHELSERU.')
282
+
283
+ except ImproperlyConfigured as e:
284
+ raise
285
+ except:
286
+ pass
287
+ pass
drfchelseru/settings.py CHANGED
@@ -29,6 +29,14 @@ DJANGO_CHELSERU = {
29
29
  'T7': 7,
30
30
  'T8': 8,
31
31
  'T9': 9,
32
+ },
33
+ },
34
+ 'BANK': {
35
+ 'GATEWAY': 'ZARINPAL_COM',
36
+ 'SETTINGS': {
37
+ 'MERCHANT_ID': '',
38
+ 'CALLBACK_URL': '',
39
+ 'CURRENCY': 'IRT', # IRR, IRT
32
40
  }
33
41
  }
34
42
  }
@@ -39,9 +47,15 @@ from django.core.exceptions import ImproperlyConfigured
39
47
 
40
48
  SERVICE_NAME = 'DJANGO_CHELSERU'
41
49
 
50
+ AUTH_SERVICE_JWT = 'rest_framework_simplejwt'
51
+ AUTH_SERVICE_DJSESSION = 'django_session'
52
+
42
53
  AUTH_METHOD = [(0, 'OTP'), (1, 'PASSWD')]
43
- AUTH_SERVICES = [(0, 'rest_framework_simplejwt')]
54
+ AUTH_SERVICES = [(0, AUTH_SERVICE_JWT)]
44
55
  SMS_SERVICES = [(0, 'PARSIAN_WEBCO_IR'),(1, 'MELI_PAYAMAK_COM') ,(2, 'KAVENEGAR_COM')]
56
+ GATEWAYS = ((0, 'ZARINPAL_COM'),)
57
+ CURRENCIES = ((0, 'IRT'), (1, 'IRR'))
58
+
45
59
 
46
60
  def auth_init_check():
47
61
  try:
@@ -185,3 +199,61 @@ def sms_init_check():
185
199
  return False
186
200
 
187
201
 
202
+ def bank_init_check():
203
+ gateway = None
204
+ options = {
205
+ 'currency': 'IRT',
206
+ }
207
+ try:
208
+ if not hasattr(settings, SERVICE_NAME):
209
+ raise ImproperlyConfigured(f'{SERVICE_NAME} must be defined in settings.py.')
210
+
211
+ else:
212
+ bank = getattr(settings, SERVICE_NAME).get('BANK')
213
+ if not bank:
214
+ raise ImproperlyConfigured(f'BANK key must be defined in {SERVICE_NAME}')
215
+ else:
216
+ gateway = bank.get('GATEWAY')
217
+ if gateway not in list(map(lambda x: x[1], GATEWAYS)):
218
+ raise ImproperlyConfigured(f'GATEWAY must be choice between {list(map(lambda x:x[1], GATEWAYS))}.')
219
+
220
+ else:
221
+ _settings = bank.get('SETTINGS')
222
+ if not _settings:
223
+ raise ImproperlyConfigured(f'SETTINGS key must be defined in BANK')
224
+ else:
225
+ _merchant_id = _settings.get('MERCHANT_ID')
226
+ _callback_url = _settings.get('CALLBACK_URL')
227
+ _currency = _settings.get('CORRENCY')
228
+
229
+ if not _merchant_id:
230
+ raise ImproperlyConfigured(f'MERCHANT_ID key must be defined in SETTINGS.')
231
+ if not _callback_url:
232
+ raise ImproperlyConfigured(f'CALLBACK_URL key must be defined in SETTINGS.')
233
+
234
+ options['merchant_id'] = _merchant_id
235
+ options['callback_url'] = _callback_url
236
+
237
+ if _currency:
238
+ options['currency'] = _currency
239
+
240
+ return {'gateway': gateway, 'settings': options}
241
+ except ImproperlyConfigured as e:
242
+ print(f"Configuration Error: {e}")
243
+ raise
244
+ except:
245
+ pass
246
+
247
+ return False
248
+
249
+
250
+ '''
251
+ 'BANK': {
252
+ 'GATEWAY': 'ZARINPAL_COM',
253
+ 'SETTINGS': {
254
+ 'MERCHANT_ID': '',
255
+ 'CALLBACK_URL': '',
256
+ 'CURRENCY': 'IRT', # IRR, IRT
257
+ }
258
+ }
259
+ '''