diff --git a/accounts/settings.py b/accounts/settings.py index ad94a78..dcc43f6 100644 --- a/accounts/settings.py +++ b/accounts/settings.py @@ -51,10 +51,8 @@ INSTALLED_APPS = [ # local apps 'apps.users', - 'apps.wallet', - 'apps.accounts_oauth2', - 'apps.superapp', -] + 'apps.gooyal_oauth2', + ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', @@ -69,20 +67,20 @@ MIDDLEWARE = [ ] # Tell Django OAuth Toolkit to use the Gooyal Application model -OAUTH2_PROVIDER_ID_TOKEN_MODEL = 'accounts_oauth2.IDToken' -OAUTH2_PROVIDER_APPLICATION_MODEL = 'accounts_oauth2.Application' -OAUTH2_PROVIDER_ACCESS_TOKEN_MODEL = 'accounts_oauth2.AccessToken' -OAUTH2_PROVIDER_GRANT_MODEL = 'accounts_oauth2.Grant' -OAUTH2_PROVIDER_REFRESH_TOKEN_MODEL = 'accounts_oauth2.RefreshToken' +OAUTH2_PROVIDER_ID_TOKEN_MODEL = 'gooyal_oauth2.IDToken' +OAUTH2_PROVIDER_APPLICATION_MODEL = 'gooyal_oauth2.Application' +OAUTH2_PROVIDER_ACCESS_TOKEN_MODEL = 'gooyal_oauth2.AccessToken' +OAUTH2_PROVIDER_GRANT_MODEL = 'gooyal_oauth2.Grant' +OAUTH2_PROVIDER_REFRESH_TOKEN_MODEL = 'gooyal_oauth2.RefreshToken' OAUTH2_PROVIDER = { # this is the list of available scopes - 'SCOPES_BACKEND_CLASS': 'apps.accounts_oauth2.scopes.Scopes', + 'SCOPES_BACKEND_CLASS': 'apps.gooyal_oauth2.scopes.Scopes', 'SCOPES': {'read': 'Read scope', 'write': 'Write scope', 'groups': 'Access to your groups', 'introspection': 'Introspect token scope'}, - 'OAUTH2_VALIDATOR_CLASS': 'apps.accounts_oauth2.validators.OAuth2Validator', + 'OAUTH2_VALIDATOR_CLASS': 'apps.gooyal_oauth2.validators.OAuth2Validator', # "INTROSPECTION_USER_CREATE_METHOD": 'apps.users.models.create_user_in_introspection', } diff --git a/accounts/urls.py b/accounts/urls.py index 513a567..54ddd9b 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -22,9 +22,7 @@ from rest_framework import permissions from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView -# from apps.accounts_oauth2.views.introspect import introspect_token -from apps.wallet.views import TransactionList, TransactionDetail, TransactionPay, TransactionReceipt, \ - WithdrawVerify, WithdrawSubmit, DepositSubmit, DepositVerify +# from apps.gooyal_oauth2.views.introspect import introspect_token from django.contrib.auth import urls as auth_urls @@ -34,9 +32,7 @@ urlpatterns = [ path('swagger/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'), path('admin/', admin.site.urls), - path('wallet/', include('apps.wallet.urls')), path('users/', include('apps.users.urls')), - path('superapp/', include('apps.superapp.urls')), path('oauth2/', include('oauth2_provider.urls', namespace='oauth2_provider')), diff --git a/apps/accounts_oauth2/__init__.py b/apps/gooyal_oauth2/__init__.py similarity index 100% rename from apps/accounts_oauth2/__init__.py rename to apps/gooyal_oauth2/__init__.py diff --git a/apps/accounts_oauth2/admin.py b/apps/gooyal_oauth2/admin.py similarity index 100% rename from apps/accounts_oauth2/admin.py rename to apps/gooyal_oauth2/admin.py diff --git a/apps/accounts_oauth2/apps.py b/apps/gooyal_oauth2/apps.py similarity index 67% rename from apps/accounts_oauth2/apps.py rename to apps/gooyal_oauth2/apps.py index 527c34d..08ad008 100755 --- a/apps/accounts_oauth2/apps.py +++ b/apps/gooyal_oauth2/apps.py @@ -2,4 +2,4 @@ from django.apps import AppConfig class GooyalOauthConfig(AppConfig): - name = 'apps.accounts_oauth2' + name = 'apps.gooyal_oauth2' diff --git a/apps/accounts_oauth2/forms.py b/apps/gooyal_oauth2/forms.py similarity index 100% rename from apps/accounts_oauth2/forms.py rename to apps/gooyal_oauth2/forms.py diff --git a/apps/accounts_oauth2/migrations/0001_initial.py b/apps/gooyal_oauth2/migrations/0001_initial.py similarity index 98% rename from apps/accounts_oauth2/migrations/0001_initial.py rename to apps/gooyal_oauth2/migrations/0001_initial.py index 3ef40b3..7e76893 100644 --- a/apps/accounts_oauth2/migrations/0001_initial.py +++ b/apps/gooyal_oauth2/migrations/0001_initial.py @@ -117,7 +117,7 @@ class Migration(migrations.Migration): ('description', models.TextField(help_text='A brief description of the scope. This text is displayed to users when authorising access for the scope.')), ('is_default', models.BooleanField(default=False, help_text='Indicates if this scope should be included in the default scopes.')), ('application', models.ForeignKey(blank=True, help_text='The application to which the scope belongs.', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='scopes', to=settings.OAUTH2_PROVIDER_APPLICATION_MODEL)), - ('resource', models.ForeignKey(blank=True, help_text='The resource of scope.', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='scopes', to='accounts_oauth2.resource')), + ('resource', models.ForeignKey(blank=True, help_text='The resource of scope.', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='scopes', to='gooyal_oauth2.resource')), ], ), ] diff --git a/apps/accounts_oauth2/migrations/0002_initial.py b/apps/gooyal_oauth2/migrations/0002_initial.py similarity index 97% rename from apps/accounts_oauth2/migrations/0002_initial.py rename to apps/gooyal_oauth2/migrations/0002_initial.py index bb55815..933612f 100644 --- a/apps/accounts_oauth2/migrations/0002_initial.py +++ b/apps/gooyal_oauth2/migrations/0002_initial.py @@ -10,7 +10,7 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ('accounts_oauth2', '0001_initial'), + ('gooyal_oauth2', '0001_initial'), migrations.swappable_dependency(settings.AUTH_USER_MODEL), ] @@ -58,7 +58,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='application', name='resource', - field=models.OneToOneField(blank=True, help_text='The resource of application.', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='application', to='accounts_oauth2.resource'), + field=models.OneToOneField(blank=True, help_text='The resource of application.', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='application', to='gooyal_oauth2.resource'), ), migrations.AddField( model_name='application', diff --git a/apps/accounts_oauth2/migrations/0003_application_allowed_origins_and_more.py b/apps/gooyal_oauth2/migrations/0003_application_allowed_origins_and_more.py similarity index 96% rename from apps/accounts_oauth2/migrations/0003_application_allowed_origins_and_more.py rename to apps/gooyal_oauth2/migrations/0003_application_allowed_origins_and_more.py index e3a4a5c..b3e78b1 100644 --- a/apps/accounts_oauth2/migrations/0003_application_allowed_origins_and_more.py +++ b/apps/gooyal_oauth2/migrations/0003_application_allowed_origins_and_more.py @@ -6,7 +6,7 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('accounts_oauth2', '0002_initial'), + ('gooyal_oauth2', '0002_initial'), ] operations = [ diff --git a/apps/accounts_oauth2/migrations/__init__.py b/apps/gooyal_oauth2/migrations/__init__.py similarity index 100% rename from apps/accounts_oauth2/migrations/__init__.py rename to apps/gooyal_oauth2/migrations/__init__.py diff --git a/apps/accounts_oauth2/models.py b/apps/gooyal_oauth2/models.py similarity index 100% rename from apps/accounts_oauth2/models.py rename to apps/gooyal_oauth2/models.py diff --git a/apps/accounts_oauth2/rest_framework.py b/apps/gooyal_oauth2/rest_framework.py similarity index 100% rename from apps/accounts_oauth2/rest_framework.py rename to apps/gooyal_oauth2/rest_framework.py diff --git a/apps/accounts_oauth2/scopes.py b/apps/gooyal_oauth2/scopes.py similarity index 100% rename from apps/accounts_oauth2/scopes.py rename to apps/gooyal_oauth2/scopes.py diff --git a/apps/accounts_oauth2/settings.py b/apps/gooyal_oauth2/settings.py similarity index 100% rename from apps/accounts_oauth2/settings.py rename to apps/gooyal_oauth2/settings.py diff --git a/apps/accounts_oauth2/signals.py b/apps/gooyal_oauth2/signals.py similarity index 100% rename from apps/accounts_oauth2/signals.py rename to apps/gooyal_oauth2/signals.py diff --git a/apps/accounts_oauth2/validators.py b/apps/gooyal_oauth2/validators.py similarity index 100% rename from apps/accounts_oauth2/validators.py rename to apps/gooyal_oauth2/validators.py diff --git a/apps/superapp/__init__.py b/apps/superapp/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/apps/superapp/admin.py b/apps/superapp/admin.py deleted file mode 100644 index 3110802..0000000 --- a/apps/superapp/admin.py +++ /dev/null @@ -1,4 +0,0 @@ -from django.contrib import admin -from .models import App -# Register your models here. -admin.site.register(App) \ No newline at end of file diff --git a/apps/superapp/apps.py b/apps/superapp/apps.py deleted file mode 100644 index 6c4bff2..0000000 --- a/apps/superapp/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class SuperappConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'apps.superapp' diff --git a/apps/superapp/migrations/0001_initial.py b/apps/superapp/migrations/0001_initial.py deleted file mode 100644 index ea041da..0000000 --- a/apps/superapp/migrations/0001_initial.py +++ /dev/null @@ -1,27 +0,0 @@ -# Generated by Django 4.1 on 2022-09-03 20:02 - -from django.db import migrations, models -import uuid - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='App', - fields=[ - ('uuid', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), - ('title', models.CharField(blank=True, max_length=30, verbose_name='title')), - ('description', models.TextField(blank=True, null=True, verbose_name='description')), - ('order', models.IntegerField(blank=True, null=True, verbose_name='order')), - ('logo', models.ImageField(blank=True, null=True, upload_to='apps_logo')), - ('type', models.IntegerField(blank=True, choices=[(0, 'internal'), (1, 'external')], null=True, verbose_name='app type')), - ('link', models.URLField(blank=True, null=True, verbose_name='link')), - ], - ), - ] diff --git a/apps/superapp/migrations/0002_remove_app_link_app_url.py b/apps/superapp/migrations/0002_remove_app_link_app_url.py deleted file mode 100644 index 83c7b31..0000000 --- a/apps/superapp/migrations/0002_remove_app_link_app_url.py +++ /dev/null @@ -1,22 +0,0 @@ -# Generated by Django 4.1 on 2022-09-03 20:16 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('superapp', '0001_initial'), - ] - - operations = [ - migrations.RemoveField( - model_name='app', - name='link', - ), - migrations.AddField( - model_name='app', - name='url', - field=models.CharField(blank=True, max_length=30, verbose_name='url'), - ), - ] diff --git a/apps/superapp/migrations/__init__.py b/apps/superapp/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/apps/superapp/models.py b/apps/superapp/models.py deleted file mode 100644 index 1626a0d..0000000 --- a/apps/superapp/models.py +++ /dev/null @@ -1,25 +0,0 @@ -import uuid -from django.db import models -from django.utils import timezone -from django.utils.translation import gettext_lazy as _ - - -# Create your models here. -class App(models.Model): - class AppTypeChoices(models.IntegerChoices): - INTERNAL = 0, _('internal') - EXTERNAL = 1, _('external') - - uuid = models.UUIDField(primary_key=True, editable=False, default=uuid.uuid4, unique=True, db_index=True) - title = models.CharField(_('title'), max_length=30, blank=True) - description = models.TextField(_('description'), null=True, blank=True) - order = models.IntegerField(_("order"), blank=True, null=True) - logo = models.ImageField(upload_to='apps_logo', null=True, blank=True) - type = models.IntegerField(_("app type"), choices=AppTypeChoices.choices, blank=True, null=True) - url = models.CharField(_('url'), max_length=30, blank=True) - - def get_uuid(self): - return str(self.uuid) - - def __str__(self): - return self.title \ No newline at end of file diff --git a/apps/superapp/serializers.py b/apps/superapp/serializers.py deleted file mode 100755 index 277499f..0000000 --- a/apps/superapp/serializers.py +++ /dev/null @@ -1,19 +0,0 @@ -from rest_framework import serializers -from rest_framework.exceptions import APIException - -from apps.users.serializers import PublicUserSerializer -from .models import App - - -class AppSerializer(serializers.ModelSerializer): - class Meta: - model = App - fields = ( - 'uuid', - 'title', - 'description', - 'order', - "logo", - "type", - 'url', - ) diff --git a/apps/superapp/tests.py b/apps/superapp/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/apps/superapp/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/apps/superapp/urls.py b/apps/superapp/urls.py deleted file mode 100644 index a08640f..0000000 --- a/apps/superapp/urls.py +++ /dev/null @@ -1,11 +0,0 @@ -from django.urls import path -from .views import AppListView, AppDetailView, AppListAPIView, AppDetailAPIView - -app_name = "superapp" - -urlpatterns = [ - path('api/applications/', AppListAPIView.as_view(), name='app_list_api'), - path('api/applications/', AppDetailAPIView.as_view(), name='app_detail_api'), - path('', AppListView.as_view(), name='app_list'), - path('', AppDetailView.as_view(), name='app_detail'), -] \ No newline at end of file diff --git a/apps/superapp/views.py b/apps/superapp/views.py deleted file mode 100644 index 20bb40c..0000000 --- a/apps/superapp/views.py +++ /dev/null @@ -1,48 +0,0 @@ -from django.contrib.auth.decorators import login_required -from django.shortcuts import render -from django.utils.decorators import method_decorator -from django.views.generic import ListView, DetailView -from rest_framework import generics - -from .models import App -from .serializers import AppSerializer -from ..accounts_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements - - -@method_decorator(login_required, name='dispatch') -class AppListView(ListView): - model = App - template_name = 'superapp/app_list.html'\ - - -@method_decorator(login_required, name='dispatch') -class AppDetailView(DetailView): - model = App - template_name = 'superapp/app_detail.html' - pk_url_kwarg = 'uuid' - - # def get_queryset(self): - # return App.objects.filter(type=App.AppTypeChoices.EXTERNAL) - - -class AppListAPIView(generics.ListAPIView): - permission_classes = [IsAuthenticatedOrTokenMatchesOASRequirements] - serializer_class = AppSerializer - required_alternate_scopes = { - "GET": [['superapp.applications:list']], - } - - def get_queryset(self): - return App.objects.all() - - -class AppDetailAPIView(generics.RetrieveAPIView): - permission_classes = [IsAuthenticatedOrTokenMatchesOASRequirements] - serializer_class = AppSerializer - lookup_field = 'uuid' - required_alternate_scopes = { - "GET": [['superapp.applications:retrieve']], - } - - def get_queryset(self): - return App.objects.all() diff --git a/apps/users/views.py b/apps/users/views.py index a2b5431..a364032 100644 --- a/apps/users/views.py +++ b/apps/users/views.py @@ -11,7 +11,7 @@ from rest_framework import generics, status, permissions from rest_framework.response import Response from rest_framework.views import APIView -from apps.accounts_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements +from apps.gooyal_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements from apps.users.forms import OTPAuthenticationForm, ProfileUpdateForm from apps.users.models import User from apps.users.provinces_and_cities import State diff --git a/apps/wallet/views.py b/apps/wallet/views.py index b85931d..c2f26de 100755 --- a/apps/wallet/views.py +++ b/apps/wallet/views.py @@ -9,7 +9,7 @@ from oauth2_provider.contrib.rest_framework import TokenHasScope, IsAuthenticate from rest_framework import generics, permissions from rest_framework.response import Response -from apps.accounts_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements +from apps.gooyal_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements from apps.wallet.models import Transaction from apps.wallet.serializers import TransactionSerializer, DepositSerializer, WithdrawSerializer, WalletSerializer from .constans import StateChoices diff --git a/templates/superapp/app_detail.html b/templates/superapp/app_detail.html deleted file mode 100644 index 787212e..0000000 --- a/templates/superapp/app_detail.html +++ /dev/null @@ -1,15 +0,0 @@ -{% extends "base_generic.html" %} - -{% block content %} - -
- - - Error: Embedded data could not be displayed. - -
- -

www.google.com

- - link -{% endblock %} \ No newline at end of file diff --git a/templates/superapp/app_list.html b/templates/superapp/app_list.html deleted file mode 100644 index 00f9f05..0000000 --- a/templates/superapp/app_list.html +++ /dev/null @@ -1,12 +0,0 @@ -{% extends "base_generic.html" %} - -{% block content %} - {% for app in object_list %} - {% if app.type == app.AppTypeChoices.EXTERNAL %} - {{ app }}
- {% else %} - {{ app }}
- {% endif %} - {% endfor %} - -{% endblock %} \ No newline at end of file diff --git a/templates/wallet/transaction_detail.html b/templates/wallet/transaction_detail.html deleted file mode 100644 index 3358b93..0000000 --- a/templates/wallet/transaction_detail.html +++ /dev/null @@ -1,25 +0,0 @@ -{% extends "base_generic.html" %} - -{% block content %} - - {% if object.payee == request.user %} - دریافت مبلغ {{ object.amount }}از: {{ object.payer }} در وضعیت {{ object.get_state_display }} - {% else %} - پرداخت مبلغ {{ object.amount }} به: {{ object.payee }} - {% endif %} - -
- {% csrf_token %} - {% if object.state == object.state_choices.created %} -
- -
- {% elif object.state == object.state_choices.delayed %} -
- -
- {% endif %} -
- - -{% endblock %} \ No newline at end of file diff --git a/templates/wallet/transaction_list.html b/templates/wallet/transaction_list.html deleted file mode 100644 index 687780b..0000000 --- a/templates/wallet/transaction_list.html +++ /dev/null @@ -1,19 +0,0 @@ -{% extends "base_generic.html" %} - -{% block content %} - {% for transaction in object_list %} - {% if transaction.payee == request.user %} - - {{ transaction.amount }} - - از: {{ transaction.payer }} در وضعیت {{ transaction.get_state_display }} - {% else %} - - {{ transaction.amount }} - - به: {{ transaction.payee }} در وضعیت {{ transaction.get_state_display }} - {% endif %} -
- {% endfor %} - -{% endblock %} \ No newline at end of file diff --git a/utils/broker.py b/utils/broker.py index 853e88e..6f89b01 100644 --- a/utils/broker.py +++ b/utils/broker.py @@ -96,8 +96,8 @@ def handle_request(requet_bytes, handler): "PATH_INFO": urlparse(request_data.uri).path, "CONTENT_LENGTH": request_data.headers.get('Content-Length', 0), "CONTENT_TYPE": request_data.headers.get('Content-Type', 'application/json'), - # "SERVER_NAME": 'kafka', - # "SERVER_PORT": '0', + "SERVER_NAME": 'kafka', + "SERVER_PORT": '0', # "HTTP_X_FORWARDED_PORT": '0', "wsgi.input": BytesIO(request_data.body) } diff --git a/utils/rpc_client.py b/utils/rpc_client.py index b1bb4b2..32272d9 100644 --- a/utils/rpc_client.py +++ b/utils/rpc_client.py @@ -62,8 +62,9 @@ request = Request(method=method, url=url, json={'key_1': 'requests_lib'}) rpc = RpcClient() print(" [x] Requesting ...") -for i in range(1000): - response = rpc.call(request) - # print(response.decode()) +# for i in range(1000): +response = rpc.call(request) +print(response.decode()) # print(type(response.decode())) - print(i) \ No newline at end of file + +# print(i) \ No newline at end of file