django-chelseru 1.1.8__py3-none-any.whl → 2.0.1__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.
@@ -0,0 +1,475 @@
1
+ Metadata-Version: 2.4
2
+ Name: django-chelseru
3
+ Version: 2.0.1
4
+ Summary: Authentication system, online and real-time chat, SMS & BANK system for Iranian SMS services.
5
+ Home-page: https://pipdjango.chelseru.com
6
+ Author: Sobhan Bahman Rashnu
7
+ Author-email: bahmanrashnu@gmail.com
8
+ Project-URL: Documentation, https://github.com/Chelseru/django-chelseru-lour/
9
+ Project-URL: Telegram Group, https://t.me/bahmanpy
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 rashno lak lour sms djangoauth auth ywt otpauth otp authentication djangootp djangoiransms iransms djangosms djangokavenegar djangomelipayamak sobhan چت سبحان بهمن رشنو چلسرو جنگو پایتون لر لور آنلاین ریل تایم
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Framework :: Django
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Requires-Python: >=3.11
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: Django>=5.1.6
20
+ Requires-Dist: djangorestframework==3.15.2
21
+ Requires-Dist: djangorestframework_simplejwt==5.5.0
22
+ Requires-Dist: channels==4.2.2
23
+ Requires-Dist: channels_redis==4.2.1
24
+ Requires-Dist: daphne==4.1.2
25
+ Requires-Dist: zeep==4.3.1
26
+ Requires-Dist: user-agents==2.2.0
27
+ Dynamic: author
28
+ Dynamic: author-email
29
+ Dynamic: classifier
30
+ Dynamic: description
31
+ Dynamic: description-content-type
32
+ Dynamic: home-page
33
+ Dynamic: keywords
34
+ Dynamic: license-file
35
+ Dynamic: project-url
36
+ Dynamic: requires-dist
37
+ Dynamic: requires-python
38
+ Dynamic: summary
39
+
40
+ # django-chelseru Django Package
41
+
42
+ ## Overview
43
+
44
+ django-chelseru is a Django package developed by Sobhan Bahman Rashnu for real-time chatting via WebSocket, OTP-based SMS verification, and SMS sending with Iranian providers. It also supports payment integrations.
45
+
46
+ Useful for building applications requiring secure authentication, messaging, real-time chat, and online payments.
47
+
48
+ ## Features
49
+
50
+ - **Authentication**: OTP and PASSWD methods using rest_framework_simplejwt.
51
+ - **SMS Services**: PARSIAN_WEBCO_IR, MELI_PAYAMAK_COM, KAVENEGAR_COM.
52
+ - **Payment Gateways**: PAYPING_IR, ZARINPAL_COM.
53
+ - **Real-time Chat**: WebSocket/Channels for messaging.
54
+ - Session management and API endpoints for OTP, authentication, SMS, payments, and chat.
55
+
56
+ ## Requirements
57
+
58
+ - Python 3.8+
59
+ - Django 4.x
60
+ - django-rest-framework
61
+ - djangorestframework-simplejwt
62
+ - django-channels
63
+ - user-agents
64
+ - requests
65
+ - Other dependencies: See `requirements.txt`
66
+
67
+ ## Installation
68
+
69
+ 1. Install the package:
70
+
71
+ ```bash
72
+ pip install django-chelseru
73
+ ```
74
+ 2. Add to `INSTALLED_APPS` in `settings.py`:
75
+
76
+ ```python
77
+ INSTALLED_APPS = [
78
+ ...
79
+ 'rest_framework',
80
+ 'rest_framework_simplejwt',
81
+ 'channels',
82
+ 'drfchelseru',
83
+ ]
84
+ ```
85
+ 3. Configure middleware and ASGI in `settings.py`.
86
+ 4. Apply migrations:
87
+
88
+ ```bash
89
+ python manage.py makemigrations
90
+ python manage.py migrate
91
+ ```
92
+ 5. Run the server (use ASGI for WebSocket):
93
+
94
+ ```bash
95
+ daphne -b 0.0.0.0 -p 8000 project.asgi:application
96
+ ```
97
+
98
+ ## Project Structure
99
+
100
+ - **models.py**: Defines models for users, OTP codes, sessions, SMS messages, organizations, chat rooms, chat permissions, messages, wallets, and payments.
101
+ - **views.py**: Handles API endpoints for OTP authentication, SMS, payments, and chat.
102
+ - **urls.py**: Maps URL patterns to views for API routes.
103
+ - **consumers.py**: Implements WebSocket consumer for real-time chat.
104
+ - **middlewares.py**: Includes `TakeUserSessionMiddlaware` for session management and `JWTAuthMiddleware` for WebSocket authentication.
105
+
106
+ ## Models
107
+
108
+ - **User**: Extends Django's User model with mobile number and group.
109
+ - **OTPCode**: Stores OTP codes for authentication with expiration logic.
110
+ - **Session**: Tracks user sessions with IP, device, and browser info.
111
+ - **MessageSMS**: Logs SMS messages sent to users.
112
+ - **Organization**: Represents organizations owned by users.
113
+ - **ChatRoomPermissions**: Defines access levels for chat room actions.
114
+ - **ChatRoom**: Manages chat rooms with users, status, and permissions.
115
+ - **MessageChat**: Stores chat messages with sender and timestamp.
116
+ - **Wallet**: Tracks user wallet balances for payments.
117
+ - **Payment**: Manages payment transactions with gateway integration.
118
+
119
+ ## Configuration
120
+
121
+ Update your Django `settings.py`:
122
+
123
+ ```python
124
+ MIDDLEWARE = [
125
+ ...
126
+ 'drfchelseru.middlewares.TakeUserSessionMiddlaware',
127
+ ]
128
+
129
+ ASGI_APPLICATION = 'yourproject.asgi.application'
130
+
131
+ CHANNEL_LAYERS = {
132
+ 'default': {
133
+ 'BACKEND': 'channels_redis.core.RedisChannelLayer',
134
+ 'CONFIG': {
135
+ 'hosts': [('127.0.0.1', 6379)],
136
+ },
137
+ },
138
+ }
139
+
140
+ DJANGO_CHELSERU = {
141
+ 'AUTH': {
142
+ 'AUTH_METHOD': 'OTP',
143
+ 'AUTH_SERVICE': 'rest_framework_simplejwt',
144
+ 'OPTIONS': {
145
+ 'OTP_LENGTH': 8,
146
+ 'OTP_EXPIRE_PER_MINUTES': 4,
147
+ 'OTP_SMS_TEMPLATE_ID': 5,
148
+ }
149
+ },
150
+ 'SMS': {
151
+ 'SMS_SERVICE': 'PARSIAN_WEBCO_IR',
152
+ 'SETTINGS': {
153
+ 'PARSIAN_WEBCO_IR_API_KEY': '',
154
+ 'MELI_PAYAMAK_COM_USERNAME': '',
155
+ 'MELI_PAYAMAK_COM_PASSWORD': '',
156
+ 'MELI_PAYAMAK_COM_FROM': '',
157
+ 'KAVENEGAR_COM_API_KEY': '',
158
+ 'KAVENEGAR_COM_FROM': '',
159
+ },
160
+ 'TEMPLATES': {
161
+ 'T1': 1,
162
+ 'T2': 2,
163
+ 'T3': 3,
164
+ }
165
+ },
166
+ 'BANK': {
167
+ 'GATEWAY': 'PAYPING_IR',
168
+ 'SETTINGS': {
169
+ 'MERCHANT_ID': '',
170
+ 'CALLBACK_URL': '',
171
+ 'CURRENCY': 'IRT'
172
+ }
173
+ }
174
+ }
175
+ ```
176
+
177
+ ## API Endpoints
178
+
179
+ - **POST /drfchelseru/message/send/**: Send SMS.
180
+
181
+ - Request: `{ "mobile_number": "09211892425", "message_text": "Hello", "template_id": 1 }`
182
+ - Response: `{ "details": "The Message was sent correctly." }` (200 OK)
183
+
184
+ - **POST /drfchelseru/otp/send/**: Request OTP code.
185
+
186
+ - Request: `{ "mobile_number": "09211892425" }`
187
+ - Response: `{ "details": "The OTP code was sent correctly." }` (200 OK)
188
+
189
+ - **POST /drfchelseru/authenticate/**: Authenticate with OTP.
190
+
191
+ - Request: `{ "mobile_number": "09211892425", "code": "652479", "group": 0 }`
192
+ - Response: `{ "access": "<access_token>", "refresh": "<refresh_token>" }` (200 OK)
193
+
194
+ - **GET /drfchelseru/sessions/**: List user sessions (authenticated users only).
195
+
196
+ - Headers: `Authorization: Bearer <access_token>`
197
+ - Response: List of sessions (200 OK)
198
+
199
+ - **POST /drfchelseru/payment/create/**: Initiate payment.
200
+
201
+ - Request: `{ "order_id": "123", "amount": 1000.0, "description": "Test payment", "callback_url": "http://example.com/callback", "mobile": "09211892425", "email": "user@example.com", "currency": "IRT" }`
202
+ - Response: `{ "details": { "gateway_url": "<url>", ... } }` (200 OK)
203
+
204
+ - **GET/POST /drfchelseru/payment/verify/**: Verify payment.
205
+
206
+ - GET Query: `?Authority=<authority>&Status=OK`
207
+ - POST Body: `{ "paymentCode": "<code>", "paymentRefId": "<refid>", ... }`
208
+ - Response: `{ "details": { "is_pay": 1, ... } }` (200 OK)
209
+
210
+ - **/drfchelseru/chat/chatrooms/**: CRUD for chat rooms (authenticated users only).
211
+
212
+ - POST Request: `{ "user": 2 }` (to create room with user ID 2)
213
+ - Headers: `Authorization: Bearer <access_token>`
214
+ - Response: Chat room details (201 Created)
215
+
216
+ - **/drfchelseru/chat/messages/**: CRUD for chat messages (authenticated users only).
217
+
218
+ - POST Request: `{ "chat_room": 1, "text": "Hello" }`
219
+ - GET Query: `?chat_room=1`
220
+ - Headers: `Authorization: Bearer <access_token>`
221
+ - Response: Message details or list (200 OK / 201 Created)
222
+
223
+ ## WebSocket Usage
224
+
225
+ - Connect to a chat room for real-time messaging:
226
+
227
+ ```bash
228
+ wscat -c wss://<your-domain>/drfchelseru/chat/<chat_room_id>/?token=<jwt_token>
229
+ ```
230
+ - Example token: `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzYxMDE5NTY3LCJpYXQiOjE3NTU4MzU1NjcsImp0aSI6IjhhYTY1Y2I3ZDhmMjRmMzliYjFmNDFkZmJiYjcyYmVmIiwidXNlcl9pZCI6Mzl9.mHmIjbTl3X1cd3Ky5HFCD6gy4kGxMVcActo9JXtT9JQ`
231
+ - Replace `<chat_room_id>` (e.g., 17) with the desired room ID and provide a valid JWT token.
232
+
233
+ ## Middleware
234
+
235
+ - **TakeUserSessionMiddlaware**: Logs user session data (IP, user agent, device, browser) for HTTP requests.
236
+ - **JWTAuthMiddleware**: Authenticates WebSocket connections using JWT tokens.
237
+
238
+ ## Usage
239
+
240
+ - Access the API at `http://<your-domain>/drfchelseru/`.
241
+ - Connect to WebSocket at `ws://<your-domain>/drfchelseru/chat/<chat_room_id>/?token=<jwt_token>`.
242
+ - Admin panel: Create a superuser with `python manage.py createsuperuser`.
243
+
244
+ ## Contributing
245
+
246
+ 1. Fork the repository.
247
+ 2. Create a new branch (`git checkout -b feature-branch`).
248
+ 3. Commit your changes (`git commit -m "Add feature"`).
249
+ 4. Push to the branch (`git push origin feature-branch`).
250
+ 5. Open a pull request.
251
+
252
+ ## License
253
+
254
+ MIT License
255
+
256
+
257
+
258
+ _______________________________________________________________________________________________________________________
259
+
260
+
261
+ # django-chelseru پکیج جنگو
262
+
263
+ ## بررسی اجمالی
264
+
265
+ django-chelseru یک پکیج جنگو است که توسط سبحان بهمن رشنو توسعه یافته برای گفتگوهای همزمان از راه وب‌سوکت، تایید پیامکی بر پایه OTP، و فرستادن پیامک با فراهم‌کنندگان ایرانی. همچنین از یکپارچگی پرداخت پشتیبانی می‌کند.
266
+
267
+ کاربردی برای ساخت برنامه‌هایی که نیاز به تایید امن، پیام‌رسانی، گفتگو همزمان، و پرداخت برخط دارند.
268
+
269
+ ## ویژگی‌ها
270
+
271
+ - **تایید**: روش‌های OTP و PASSWD با بهره‌گیری از rest_framework_simplejwt.
272
+ - **خدمات پیامک**: PARSIAN_WEBCO_IR، MELI_PAYAMAK_COM، KAVENEGAR_COM.
273
+ - **درگاه‌های پرداخت**: PAYPING_IR، ZARINPAL_COM.
274
+ - **گفتگو همزمان**: وب‌سوکت/کانال‌ها برای پیام‌رسانی.
275
+ - مدیریت نشست و نقاط پایانی API برای OTP، تایید، پیامک، پرداخت‌ها، و گفتگو.
276
+
277
+ ## نیازمندی‌ها
278
+
279
+ - Python 3.8+
280
+ - Django 4.x
281
+ - django-rest-framework
282
+ - djangorestframework-simplejwt
283
+ - django-channels
284
+ - user-agents
285
+ - requests
286
+ - دیگر وابستگی‌ها: ببینید `requirements.txt`
287
+
288
+ ## نصب
289
+
290
+ 1. پکیج را نصب کنید:
291
+
292
+ ```bash
293
+ pip install django-chelseru
294
+ ```
295
+ 2. به `INSTALLED_APPS` در `settings.py` بیفزایید:
296
+
297
+ ```python
298
+ INSTALLED_APPS = [
299
+ ...
300
+ 'rest_framework',
301
+ 'rest_framework_simplejwt',
302
+ 'channels',
303
+ 'drfchelseru',
304
+ ]
305
+ ```
306
+ 3. میان‌گیر و ASGI را در `settings.py` پیکربندی کنید.
307
+ 4. مهاجرت‌ها را اعمال کنید:
308
+
309
+ ```bash
310
+ python manage.py makemigrations
311
+ python manage.py migrate
312
+ ```
313
+ 5. کارساز را اجرا کنید (برای وب‌سوکت از ASGI بهره ببرید):
314
+
315
+ ```bash
316
+ daphne -b 0.0.0.0 -p 8000 project.asgi:application
317
+ ```
318
+
319
+ ## ساختار پروژه
320
+
321
+ - **models.py**: مدل‌ها را برای کاربران، کدهای OTP، نشست‌ها، پیامک‌ها، سازمان‌ها، اتاق‌های گفتگو، دسترسی‌های اتاق گفتگو، پیام‌ها، کیف‌پول‌ها، و پرداخت‌ها تعریف می‌کند.
322
+ - **views.py**: نقاط پایانی API برای تایید OTP، پیامک، پرداخت‌ها، و گفتگو را مدیریت می‌کند.
323
+ - **urls.py**: الگوهای URL را به نما‌ها برای مسیرهای API نگاشت می‌کند.
324
+ - **consumers.py**: مصرف‌کننده وب‌سوکت را برای گفتگو همزمان پیاده‌سازی می‌کند.
325
+ - **middlewares.py**: شامل `TakeUserSessionMiddlaware` برای مدیریت نشست و `JWTAuthMiddleware` برای تایید وب‌سوکت.
326
+
327
+ ## مدل‌ها
328
+
329
+ - **User**: مدل کاربر جنگو را با شماره همراه و گروه گسترش می‌دهد.
330
+ - **OTPCode**: کدهای OTP را برای تایید با منطق انقضا ذخیره می‌کند.
331
+ - **Session**: نشست‌های کاربر را با IP، دستگاه، و داده‌های مرورگر پیگیری می‌کند.
332
+ - **MessageSMS**: پیامک‌های فرستاده‌شده به کاربران را ثبت می‌کند.
333
+ - **Organization**: سازمان‌هایی را که مالک کاربران هستند نشان می‌دهد.
334
+ - **ChatRoomPermissions**: سطوح دسترسی برای کارهای اتاق گفتگو را تعریف می‌کند.
335
+ - **ChatRoom**: اتاق‌های گفتگو را با کاربران، وضعیت، و دسترسی‌ها مدیریت می‌کند.
336
+ - **MessageChat**: پیام‌های گفتگو را با فرستنده و زمان‌نگار ذخیره می‌کند.
337
+ - **Wallet**: مانده کیف‌پول کاربران را برای پرداخت‌ها پیگیری می‌کند.
338
+ - **Payment**: تراکنش‌های پرداخت را با یکپارچگی درگاه مدیریت می‌کند.
339
+
340
+ ## پیکربندی
341
+
342
+ `settings.py` جنگو را به‌روزرسانی کنید:
343
+
344
+ ```python
345
+ MIDDLEWARE = [
346
+ ...
347
+ 'drfchelseru.middlewares.TakeUserSessionMiddlaware',
348
+ ]
349
+
350
+ ASGI_APPLICATION = 'yourproject.asgi.application'
351
+
352
+ CHANNEL_LAYERS = {
353
+ 'default': {
354
+ 'BACKEND': 'channels_redis.core.RedisChannelLayer',
355
+ 'CONFIG': {
356
+ 'hosts': [('127.0.0.1', 6379)],
357
+ },
358
+ },
359
+ }
360
+
361
+ DJANGO_CHELSERU = {
362
+ 'AUTH': {
363
+ 'AUTH_METHOD': 'OTP',
364
+ 'AUTH_SERVICE': 'rest_framework_simplejwt',
365
+ 'OPTIONS': {
366
+ 'OTP_LENGTH': 8,
367
+ 'OTP_EXPIRE_PER_MINUTES': 4,
368
+ 'OTP_SMS_TEMPLATE_ID': 5,
369
+ }
370
+ },
371
+ 'SMS': {
372
+ 'SMS_SERVICE': 'PARSIAN_WEBCO_IR',
373
+ 'SETTINGS': {
374
+ 'PARSIAN_WEBCO_IR_API_KEY': '',
375
+ 'MELI_PAYAMAK_COM_USERNAME': '',
376
+ 'MELI_PAYAMAK_COM_PASSWORD': '',
377
+ 'MELI_PAYAMAK_COM_FROM': '',
378
+ 'KAVENEGAR_COM_API_KEY': '',
379
+ 'KAVENEGAR_COM_FROM': '',
380
+ },
381
+ 'TEMPLATES': {
382
+ 'T1': 1,
383
+ 'T2': 2,
384
+ 'T3': 3,
385
+ }
386
+ },
387
+ 'BANK': {
388
+ 'GATEWAY': 'PAYPING_IR',
389
+ 'SETTINGS': {
390
+ 'MERCHANT_ID': '',
391
+ 'CALLBACK_URL': '',
392
+ 'CURRENCY': 'IRT'
393
+ }
394
+ }
395
+ }
396
+ ```
397
+
398
+ ## نقاط پایانی API
399
+
400
+ - **POST /drfchelseru/message/send/**: فرستادن پیامک.
401
+
402
+ - درخواست: `{ "mobile_number": "09211892425", "message_text": "Hello", "template_id": 1 }`
403
+ - پاسخ: `{ "details": "The Message was sent correctly." }` (200 OK)
404
+
405
+ - **POST /drfchelseru/otp/send/**: درخواست کد OTP.
406
+
407
+ - درخواست: `{ "mobile_number": "09211892425" }`
408
+ - پاسخ: `{ "details": "The OTP code was sent correctly." }` (200 OK)
409
+
410
+ - **POST /drfchelseru/authenticate/**: تایید با OTP.
411
+
412
+ - درخواست: `{ "mobile_number": "09211892425", "code": "652479", "group": 0 }`
413
+ - پاسخ: `{ "access": "<access_token>", "refresh": "<refresh_token>" }` (200 OK)
414
+
415
+ - **GET /drfchelseru/sessions/**: فهرست نشست‌های کاربر (فقط کاربران تاییدشده).
416
+
417
+ - سرآیندها: `Authorization: Bearer <access_token>`
418
+ - پاسخ: فهرست نشست‌ها (200 OK)
419
+
420
+ - **POST /drfchelseru/payment/create/**: آغاز پرداخت.
421
+
422
+ - درخواست: `{ "order_id": "123", "amount": 1000.0, "description": "Test payment", "callback_url": "http://example.com/callback", "mobile": "09211892425", "email": "user@example.com", "currency": "IRT" }`
423
+ - پاسخ: `{ "details": { "gateway_url": "<url>", ... } }` (200 OK)
424
+
425
+ - **GET/POST /drfchelseru/payment/verify/**: تایید پرداخت.
426
+
427
+ - جستجوی GET: `?Authority=<authority>&Status=OK`
428
+ - بدنه POST: `{ "paymentCode": "<code>", "paymentRefId": "<refid>", ... }`
429
+ - پاسخ: `{ "details": { "is_pay": 1, ... } }` (200 OK)
430
+
431
+ - **/drfchelseru/chat/chatrooms/**: CRUD برای اتاق‌های گفتگو (فقط کاربران تاییدشده).
432
+
433
+ - درخواست POST: `{ "user": 2 }` (برای ساخت اتاق با شناسه کاربر 2)
434
+ - سرآیندها: `Authorization: Bearer <access_token>`
435
+ - پاسخ: جزئیات اتاق گفتگو (201 Created)
436
+
437
+ - **/drfchelseru/chat/messages/**: CRUD برای پیام‌های گفتگو (فقط کاربران تاییدشده).
438
+
439
+ - درخواست POST: `{ "chat_room": 1, "text": "Hello" }`
440
+ - جستجوی GET: `?chat_room=1`
441
+ - سرآیندها: `Authorization: Bearer <access_token>`
442
+ - پاسخ: جزئیات پیام یا فهرست (200 OK / 201 Created)
443
+
444
+ ## بهره‌گیری از وب‌سوکت
445
+
446
+ - پیوستن به اتاق گفتگو برای پیام‌رسانی همزمان:
447
+
448
+ ```bash
449
+ wscat -c wss://<your-domain>/drfchelseru/chat/<chat_room_id>/?token=<jwt_token>
450
+ ```
451
+ - نمونه نشانه: `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzYxMDE5NTY3LCJpYXQiOjE3NTU4MzU1NjcsImp0aSI6IjhhYTY1Y2I3ZDhmMjRmMzliYjFmNDFkZmJiYjcyYmVmIiwidXNlcl9pZCI6Mzl9.mHmIjbTl3X1cd3Ky5HFCD6gy4kGxMVcActo9JXtT9JQ`
452
+ - &lt;chat_room_id&gt; (مانند 17) را با شناسه اتاق دلخواه جایگزین کنید و نشانه JWT معتبر فراهم کنید.
453
+
454
+ ## میان‌گیرها
455
+
456
+ - **TakeUserSessionMiddlaware**: داده‌های نشست کاربر (IP، عامل کاربر، دستگاه، مرورگر) را برای درخواست‌های HTTP ثبت می‌کند.
457
+ - **JWTAuthMiddleware**: اتصال‌های وب‌سوکت را با نشانه‌های JWT تایید می‌کند.
458
+
459
+ ## بهره‌گیری
460
+
461
+ - به API در `http://<your-domain>/drfchelseru/` دسترسی یابید.
462
+ - به وب‌سوکت در `ws://<your-domain>/drfchelseru/chat/<chat_room_id>/?token=<jwt_token>` وصل شوید.
463
+ - پنل مدیر: ابرکاربر را با `python manage.py createsuperuser` بسازید.
464
+
465
+ ## همکاری
466
+
467
+ 1. مخزن را فورک کنید.
468
+ 2. شاخه نو بسازید (`git checkout -b feature-branch`).
469
+ 3. تغییرات را کامیت کنید (`git commit -m "Add feature"`).
470
+ 4. به شاخه بفرستید (`git push origin feature-branch`).
471
+ 5. درخواست کشیدن باز کنید.
472
+
473
+ ## پروانه
474
+
475
+ MIT License
@@ -1,4 +1,4 @@
1
- django_chelseru-1.1.8.dist-info/licenses/LICENSE,sha256=VupU5KV4NteHaNQb-WH31G_WZWezxXoomjiCIAHoQJo,1089
1
+ django_chelseru-2.0.1.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
@@ -7,8 +7,8 @@ drfchelseru/middlewares.py,sha256=Ej_9GTlVPzfzYAUqxUn7VHJRdlywQmrbSIW43yK5q5U,38
7
7
  drfchelseru/models.py,sha256=jQ5IbS5q4GufZC9W_zgX1Qg8YU_f8V-Jusbh5hQYPhQ,11214
8
8
  drfchelseru/routing.py,sha256=shAlgzcIwVuVPlvKeWBLCqr6PuBTHyIrWNgHEfnqrxg,165
9
9
  drfchelseru/serializers.py,sha256=I3kS2NhzIprY8-WWhjQPShAom6R7epg7do7RnDkpnys,1421
10
- drfchelseru/services.py,sha256=9sHlY-_Prd1Wl1WTddT-e1nE7rYKlDjFaYl6FGjwvTA,27142
11
- drfchelseru/settings.py,sha256=zzOKwaciRMOhf5tQM4jAT4_80nggTwl_HqCby7TCUaE,11385
10
+ drfchelseru/services.py,sha256=muVnZKyfIYm39uE8MrH_CykyxATUT4lqOkLtReZfNc0,28851
11
+ drfchelseru/settings.py,sha256=LhdRLmUJnNlET0JYnHqRdFzmBD_nEX18qU1C1j0qN0E,11466
12
12
  drfchelseru/signals.py,sha256=CI1mZR5RrdOddXBnPC1eMdt9iQkYFDypfgogtfTc2eQ,2714
13
13
  drfchelseru/tests.py,sha256=mrbGGRNg5jwbTJtWWa7zSKdDyeB4vmgZCRc2nk6VY-g,60
14
14
  drfchelseru/urls.py,sha256=qD3As2gSCEaNDxgU0ejIADLUt9t2EvoaTmqeiV1LRSA,898
@@ -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-1.1.8.dist-info/METADATA,sha256=OOjipNbIe83ImvKJ2ZWUihnIMfKSNcDPBBBAec9E5qY,10944
41
- django_chelseru-1.1.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
42
- django_chelseru-1.1.8.dist-info/top_level.txt,sha256=fsaO1F03W3j4AYi0TfDGv5Cjb_Qrh6RSkwkWqfqaMns,12
43
- django_chelseru-1.1.8.dist-info/RECORD,,
40
+ django_chelseru-2.0.1.dist-info/METADATA,sha256=sZb0bGzoD5ahEIE1buM-ORJuDn1VBqr2r2AFitVxL-s,18242
41
+ django_chelseru-2.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
42
+ django_chelseru-2.0.1.dist-info/top_level.txt,sha256=fsaO1F03W3j4AYi0TfDGv5Cjb_Qrh6RSkwkWqfqaMns,12
43
+ django_chelseru-2.0.1.dist-info/RECORD,,
drfchelseru/services.py CHANGED
@@ -116,10 +116,37 @@ class KavenegarCom:
116
116
 
117
117
  def __init__(self, mobile, options, *args, **kwargs):
118
118
  self.RECEIVER = mobile
119
- if options and 'api_key' in options and 'from' in options:
119
+ if options and 'api_key' in options:
120
120
  self.API_KEY = options['api_key']
121
- self.SENDER = options['from']
121
+ if 'from' in options:
122
+ self.SENDER = options['from']
123
+
124
+ def send_message_lookup(self, message, template_id, **kwargs):
125
+ try:
126
+ api_url = f'https://api.kavenegar.com/v1/{self.API_KEY}/verify/lookup.json'
127
+ data = {
128
+ 'receptor': self.RECEIVER,
129
+ 'template': template_id,
130
+ 'token': message.strip(),
131
+ }
132
+ if kwargs.get('token2'):
133
+ data['token2'] = kwargs.get('token2').strip()
134
+
135
+ if kwargs.get('token3'):
136
+ data['token3'] = kwargs.get('token3').strip()
137
+
138
+ if kwargs.get('token10'):
139
+ data['token10'] = kwargs.get('token10')
122
140
 
141
+ if kwargs.get('token20'):
142
+ data['token20'] = kwargs.get('token20')
143
+
144
+ response = requests.post(url=api_url, data=data)
145
+ return response
146
+
147
+ except Exception as e:
148
+ print(str(e))
149
+ return False
123
150
 
124
151
  def send_message(self, message):
125
152
  try:
@@ -148,7 +175,8 @@ class KavenegarCom:
148
175
  418 Your credit is not sufficient.
149
176
  451 Excessive calls within a specific time period are restricted to IP addresses.
150
177
  """
151
- except:
178
+ except Exception as e:
179
+ print(str(e))
152
180
  return False
153
181
 
154
182
 
@@ -213,7 +241,25 @@ def send_message(mobile_number, message_text, data=None, template_id=None):
213
241
  elif sms_service == 'KAVENEGAR_COM':
214
242
  service = KavenegarCom(mobile=mobile_number, options=options)
215
243
  try:
216
- response = service.send_message(message=message_text)
244
+ if template_id or data.get('template_id'):
245
+ if not template_id:
246
+ template_id = data.get('template_id')
247
+
248
+ _data = {}
249
+ if 'token2' in data:
250
+ _data['token2'] = data.get('token2')
251
+ if 'token3' in data:
252
+ _data['token3'] = data.get('token3')
253
+ if 'token10' in data:
254
+ _data['token10'] = data.get('token10')
255
+ if 'token20' in data:
256
+ _data['token20'] = data.get('token20')
257
+
258
+ response = service.send_message_lookup(message=message_text, template_id=template_id, **_data)
259
+ else:
260
+ response = service.send_message(message=message_text)
261
+
262
+ print(response.json())
217
263
  response_json = response.json()
218
264
  entries = response_json.get('entries', [])
219
265
  _return = response_json.get('return', {})
drfchelseru/settings.py CHANGED
@@ -187,11 +187,13 @@ def sms_init_check():
187
187
  options['api_key'] = api_key
188
188
 
189
189
  _from = getattr(settings, SERVICE_NAME).get('SMS').get('SETTINGS').get('KAVENEGAR_COM_FROM')
190
- if not _from:
191
- raise ImproperlyConfigured(f'KAVENEGAR_COM_FROM must be defined in {SERVICE_NAME}: SMS: SETTINGS, To send an SMS, the sender`s number is required.')
192
-
193
- else:
190
+ if _from:
194
191
  options['from'] = _from
192
+ # if not _from:
193
+ # raise ImproperlyConfigured(f'KAVENEGAR_COM_FROM must be defined in {SERVICE_NAME}: SMS: SETTINGS, To send an SMS, the sender`s number is required.')
194
+
195
+ # else:
196
+
195
197
 
196
198
  return {'SMS_SERVICE': sms_service, 'SETTINGS': options, 'TEMPLATES': templates}
197
199
  except ImproperlyConfigured as e:
@@ -1,312 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: django-chelseru
3
- Version: 1.1.8
4
- Summary: Authentication system, online and real-time chat, SMS system for Iranian SMS services.
5
- Home-page: https://pipdjango.chelseru.com
6
- Author: Sobhan Bahman Rashnu
7
- Author-email: bahmanrashnu@gmail.com
8
- Project-URL: Documentation, https://github.com/Chelseru/django-chelseru-lour/
9
- Project-URL: Telegram Group, https://t.me/bahmanpy
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 rashno lak lour sms djangoauth auth ywt otpauth otp authentication djangootp djangoiransms iransms djangosms djangokavenegar djangomelipayamak sobhan چت سبحان بهمن رشنو چلسرو جنگو پایتون لر لور آنلاین ریل تایم
12
- Classifier: Programming Language :: Python :: 3
13
- Classifier: Framework :: Django
14
- Classifier: License :: OSI Approved :: MIT License
15
- Classifier: Operating System :: OS Independent
16
- Requires-Python: >=3.11
17
- Description-Content-Type: text/markdown
18
- License-File: LICENSE
19
- Requires-Dist: Django>=5.1.6
20
- Requires-Dist: djangorestframework==3.15.2
21
- Requires-Dist: djangorestframework_simplejwt==5.5.0
22
- Requires-Dist: channels==4.2.2
23
- Requires-Dist: channels_redis==4.2.1
24
- Requires-Dist: daphne==4.1.2
25
- Requires-Dist: zeep==4.3.1
26
- Requires-Dist: user-agents==2.2.0
27
- Dynamic: author
28
- Dynamic: author-email
29
- Dynamic: classifier
30
- Dynamic: description
31
- Dynamic: description-content-type
32
- Dynamic: home-page
33
- Dynamic: keywords
34
- Dynamic: license-file
35
- Dynamic: project-url
36
- Dynamic: requires-dist
37
- Dynamic: requires-python
38
- Dynamic: summary
39
-
40
- # django-chelseru
41
-
42
- بستهٔ جنگویی برای **گپ‌زنی همزمان (WebSocket)**، **راستی‌آزمایی پیامکی (OTP)** و **فرستادن پیامک** با یاری‌دهنده‌های ایرانی.
43
-
44
- **نویسنده:** Sobhan Bahman Rashnu
45
-
46
- ---
47
-
48
- ## فهرست مطالب
49
-
50
- - [ویژگی‌ها](#ویژگیها)
51
- - [نصب](#نصب)
52
- - [پیش‌نیازها و افزودن به تنظیمات](#پیشنیازها-و-افزودن-به-تنظیمات)
53
- - [پیکربندی](#پیکربندی)
54
- - [تعریف آدرس‌ها (URLs)](#تعریف-آدرسها-urls)
55
- - [نقطه‌های پایانی API](#نقطههای-پایانی-api)
56
- - [/api/otp/send/ — فرستادن رمز یک‌بارمصرف](#apiotpsend--فرستادن-رمز-یکبارمصرف)
57
- - [/api/authenticate/ — راستی‌آزمایی با OTP و دریافت JWT](#apiauthenticate--راستیآزمایی-با-otp-و-دریافت-jwt)
58
- - [/api/message/send/ — فرستادن پیامک](#apimessagesend--فرستادن-پیامک)
59
- - [/api/sessions/ — فهرست نشست‌های فعال](#apisessions--فهرست-نشستهای-فعال)
60
- - [مدل‌ها](#مدلها)
61
-
62
- ---
63
-
64
- ## ویژگی‌ها
65
-
66
- - 📱 **راستی‌آزمایی پیامکی (OTP):** تولید و فرستادن رمز یک‌بارمصرف و اعتبارسنجی امن.
67
- - 💬 **گپ‌زنی همزمان:** پیام‌رسانی همزمان بر پایهٔ **WebSocket/Channels**.
68
- - ✉️ **فرستادن پیامک:** پشتیبانی از یاری‌دهنده‌های نام‌آشنای ایرانی.
69
-
70
- ---
71
-
72
- ## نصب
73
-
74
- ```bash
75
- pip install django-chelseru
76
- ```
77
-
78
- ---
79
-
80
- ## پیش‌نیازها و افزودن به تنظیمات
81
-
82
- `INSTALLED_APPS` را در `settings.py` به‌روز کنید:
83
-
84
- ```python
85
- INSTALLED_APPS = [
86
- # ...
87
- 'channels',
88
- 'rest_framework',
89
- 'rest_framework_simplejwt',
90
- 'drfchelseru',
91
- # ...
92
- ]
93
- ```
94
-
95
- > نکته: برای قابلیت‌های همزمان (WebSocket) پروژهٔ شما باید با **ASGI** اجرا شود (مانند `daphne` یا `uvicorn`).
96
-
97
- ---
98
-
99
- ## پیکربندی
100
-
101
- واژه‌نامهٔ `DJANGO_CHELSERU` را در `settings.py` بیفزایید و بر اساس نیاز خود سفارشی‌سازی کنید:
102
-
103
- ```python
104
- DJANGO_CHELSERU = {
105
- 'AUTH': {
106
- 'AUTH_METHOD': 'OTP', # روش‌های پشتیبانی‌شده: OTP, PASSWD
107
- 'AUTH_SERVICE': 'rest_framework_simplejwt', # فعلاً: rest_framework_simplejwt
108
- 'OPTIONS': {
109
- 'OTP_LENGTH': 8, # پیش‌فرض: 8
110
- 'OTP_EXPIRE_PER_MINUTES': 4, # پیش‌فرض: 4
111
- 'OTP_SMS_TEMPLATE_ID': 1, # شناسهٔ قالب پیامکی OTP
112
- },
113
- },
114
- 'SMS': {
115
- 'SMS_SERVICE': 'PARSIAN_WEBCO_IR', # PARSIAN_WEBCO_IR, MELI_PAYAMAK_COM, KAVENEGAR_COM
116
- 'SETTINGS': {
117
- 'PARSIAN_WEBCO_IR_API_KEY': '',
118
- 'MELI_PAYAMAK_COM_USERNAME': '',
119
- 'MELI_PAYAMAK_COM_PASSWORD': '',
120
- 'MELI_PAYAMAK_COM_FROM': '',
121
- 'KAVENEGAR_COM_API_KEY': 'YOUR_KAVENEGAR_API_KEY',
122
- 'KAVENEGAR_COM_FROM': 'YOUR_KAVENEGAR_FROM_NUMBER',
123
- },
124
- 'TEMPLATES': {
125
- 'T1': 1,
126
- 'T2': 2,
127
- # ...
128
- },
129
- },
130
- }
131
- ```
132
-
133
- **راهنما:**
134
-
135
- - `AUTH_METHOD`: روش راستی‌آزمایی (برای پیامکی از `'OTP'` استفاده کنید).
136
- - `OTP_LENGTH`: طول رمز یک‌بارمصرف.
137
- - `OTP_EXPIRE_PER_MINUTES`: مدت اعتبار رمز (به دقیقه).
138
- - `OTP_SMS_TEMPLATE_ID`: شناسهٔ قالب پیامکی که برای OTP بهره‌گیری می‌شود.
139
- - `SMS_SERVICE`: انتخاب یاری‌دهندهٔ پیامکی.
140
- - `SETTINGS`: مقادیر دسترسی یاری‌دهندهٔ انتخاب‌شده.
141
- - `TEMPLATES`: نگاشت کلیدهای دلخواه به شناسهٔ قالب‌ها.
142
-
143
- ---
144
-
145
- ## تعریف آدرس‌ها (URLs)
146
-
147
- در `urls.py`:
148
-
149
- ```python
150
- from django.urls import path, include
151
-
152
- urlpatterns = [
153
- # ...
154
- path('api/', include('drfchelseru.urls')),
155
- # ...
156
- ]
157
- ```
158
-
159
- ---
160
-
161
- ## نقطه‌های پایانی API
162
-
163
- | مسیر | شرح | روش |
164
- | -------------------- | -------------------------------------------------- | ---- |
165
- | `/api/otp/send/` | فرستادن رمز یک‌بارمصرف به شمارهٔ همراه | POST |
166
- | `/api/authenticate/` | راستی‌آزمایی کاربر با OTP و دریافت توکن‌های JWT | POST |
167
- | `/api/sessions/` | فهرست و مدیریت نشست‌های فعال کاربر (نیازمند احراز) | GET |
168
- | `/api/message/send/` | فرستادن پیامک با یاری‌دهندهٔ پیکربندی‌شده | POST |
169
-
170
- ---
171
-
172
- ### `/api/otp/send/` — فرستادن رمز یک‌بارمصرف
173
-
174
- **روش:** `POST`\
175
- **شرح:** یک OTP به شمارهٔ همراه کاربر فرستاده می‌شود.
176
-
177
- **بدنهٔ درخواست:**
178
-
179
- | فیلد | نوع | شرح | نمونه |
180
- | --------------- | ----- | ------------------ | ------------- |
181
- | `mobile_number` | `str` | شمارهٔ همراه کاربر | `09121234567` |
182
-
183
- **نمونهٔ درخواست:**
184
-
185
- ```http
186
- POST /api/otp/send/ HTTP/1.1
187
- Content-Type: application/json
188
-
189
- {
190
- "mobile_number": "09121234567"
191
- }
192
- ```
193
-
194
- **پاسخ‌های ممکن:**
195
-
196
- - `200 OK`
197
- ```json
198
- { "details": "The OTP code was sent correctly." }
199
- ```
200
- - `400 Bad Request` — ساختار نادرست `mobile_number`
201
- - `409 Conflict`
202
- ```json
203
- { "details": "An OTP code has already been sent. Please wait X seconds before trying again." }
204
- ```
205
- - `500 Internal Server Error` — خطا در کارگذار
206
-
207
- ---
208
-
209
- ### `/api/authenticate/` — راستی‌آزمایی با OTP و دریافت JWT
210
-
211
- **روش:** `POST`\
212
- **شرح:** اعتبارسنجی کاربر با OTP؛ در صورت موفقیت، توکن‌های `access` و `refresh` بازگردانده می‌شود.
213
-
214
- **بدنهٔ درخواست:**
215
-
216
- | فیلد | نوع | شرح | نمونه |
217
- | --------------- | ----- | --------------------------- | ------------- |
218
- | `mobile_number` | `str` | شمارهٔ همراه کاربر | `09121234567` |
219
- | `code` | `str` | رمز یک‌بارمصرف دریافت‌شده | `12345678` |
220
- | `group` | `int` | (اختیاری) شناسهٔ گروه کاربر | `1` |
221
-
222
- **نمونهٔ درخواست:**
223
-
224
- ```http
225
- POST /api/authenticate/ HTTP/1.1
226
- Content-Type: application/json
227
-
228
- {
229
- "mobile_number": "09121234567",
230
- "code": "12345678",
231
- "group": 1
232
- }
233
- ```
234
-
235
- **پاسخ‌های ممکن:**
236
-
237
- - `200 OK`
238
- ```json
239
- { "access": "...", "refresh": "..." }
240
- ```
241
- - `401 Unauthorized`
242
- ```json
243
- { "error": "The code sent to this mobile number was not found." }
244
- ```
245
- - `400 Bad Request` — فیلدهای الزامی ناپیدا/نامعتبر
246
- - `500 Internal Server Error` — خطا در کارگذار
247
-
248
- ---
249
-
250
- ### `/api/message/send/` — فرستادن پیامک
251
-
252
- **روش:** `POST`\
253
- **شرح:** فرستادن پیامک سفارشی با یاری‌دهندهٔ پیکربندی‌شده.
254
-
255
- **بدنهٔ درخواست:**
256
-
257
- | فیلد | نوع | شرح | نمونه |
258
- | --------------- | ----- | ---------------------------------------------- | --------------- |
259
- | `mobile_number` | `str` | شمارهٔ همراه گیرنده | `09121234567` |
260
- | `message_text` | `str` | متن پیام (حداکثر ۲۹۰ نویسه) | `Hello, World!` |
261
- | `template_id` | `int` | (برای برخی یاری‌دهنده‌ها مانند پارسیان الزامی) | `1` |
262
-
263
- **نمونهٔ درخواست:**
264
-
265
- ```http
266
- POST /api/message/send/ HTTP/1.1
267
- Content-Type: application/json
268
-
269
- {
270
- "mobile_number": "09121234567",
271
- "message_text": "Hello, World!",
272
- "template_id": 1
273
- }
274
- ```
275
-
276
- **پاسخ‌های ممکن:**
277
-
278
- - `200 OK`
279
- ```json
280
- { "details": "The Message was sent correctly." }
281
- ```
282
- - `400 Bad Request` — خطاهای اعتبارسنجی فیلدها
283
- - `401 Unauthorized` — احراز انجام نشده
284
- - `500 Internal Server Error` — خطا در کارگذار
285
- - `502 Bad Gateway` — خطای بازگشتی از یاری‌دهندهٔ پیامکی
286
-
287
- ---
288
-
289
- ### `/api/sessions/` — فهرست نشست‌های فعال
290
-
291
- **روش:** `GET`\
292
- **شرح:** همهٔ نشست‌های فعال کاربر را برمی‌گرداند. نیازمند **احراز هویت** (`IsAuthenticated`).
293
-
294
- **سربرگ‌های لازم:**
295
-
296
- | سربرگ | مقدار |
297
- | --------------- | ---------------------------- |
298
- | `Authorization` | `Bearer <your_access_token>` |
299
-
300
- **نمونهٔ درخواست:**
301
-
302
- ```http
303
- GET /api/sessions/ HTTP/1.1
304
- Authorization: Bearer <your_access_token>
305
- ```
306
-
307
- ---
308
-
309
- ## مدل‌ها
310
-
311
- این بسته یک مدل **Session** برای مدیریت نشست‌های فعال کاربران فراهم می‌کند.\
312
- از طریق نقطهٔ پایانی `/api/sessions/` می‌توانید نشست‌ها را مشاهده/مدیریت کنید.