diff --git a/apps/users/models.py b/apps/users/models.py index ff86751..2e205b9 100644 --- a/apps/users/models.py +++ b/apps/users/models.py @@ -12,7 +12,7 @@ from rest_framework.exceptions import APIException import uuid from apps.users.constans import MAX_OTP_TRY, DEVELOPMENT_PHONE_NUMBERS -from utils.notification_client import notification_client +from utils.service_client import service_client class UserManager(BaseUserManager): @@ -170,7 +170,7 @@ class User(AbstractUser): self.notify(sms_body) def notify(self, body, notification_type='sms'): - notification_client.notify(phone_number=self.phone_number, body=body) + service_client.notify(phone_number=self.phone_number, body=body) def __str__(self): diff --git a/deploy.sh b/deploy.sh index 42467af..a65ea63 100644 --- a/deploy.sh +++ b/deploy.sh @@ -1,8 +1,5 @@ #!/usr/bin/env bash # Deployment script -apt install libmysqlclient-dev -apt install libssl-dev -apt install libcrypto++-dev -apt install lsb-release +apt install libmysqlclient-dev libssl-dev libcrypto++-dev lsb-release python manage.py migrate diff --git a/gooyal_accounts/settings.py b/gooyal_accounts/settings.py index b5caa01..dcf1be3 100644 --- a/gooyal_accounts/settings.py +++ b/gooyal_accounts/settings.py @@ -176,7 +176,6 @@ MEDIA_URL = "/media/" STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATIC_URL = '/static/' -NOTIFICATIONS_SERVICE_URL = 'https://notifications.gooyal.com' -CLIENT_ID = 'wDGC6ZtKXxUvVMP0tUg8DYbtgAD0It8o3TCWjY05' -CLIENT_SECRET = 'NBmm8FCzKCYLhMIN3LQ7LoZ3nonnjLvQkVP96MYGAGc5LQSCmdOXbfWP8tdbPBihPOhqW3Fk96tpaQVM6NyJBQCS2qvigE9Vp2RaqKUPM6QhvGI3GT5itT6Rwv5iO4JX' -ACCESS_TOKEN = 'Px7WLUKoynua6qJq5IkIG8Fn5dPLXq' \ No newline at end of file +NOTIFICATIONS_SERVICE_URL = config('NOTIFICATIONS_SERVICE_URL') +CLIENT_ID = config('CLIENT_ID') +CLIENT_SECRET = config('CLIENT_SECRET') diff --git a/requirements.in b/requirements.in new file mode 100644 index 0000000..c2d79c1 --- /dev/null +++ b/requirements.in @@ -0,0 +1,31 @@ +# requirements.in +django +django-oauth-toolkit +djangorestframework +markdown +django-filter +django-cors-middleware + + +## + +pillow = "*" +django-model-utils = "*" +mysqlclient = "*" +django-mysql = "*" +python-decouple = "*" +gunicorn = "*" +gevent = "*" + + +pip-tools +python-decouple +django-cors-middleware +django-model-utils +mysqlclient +django-mysql +kavenegar +celery +mp-model-helper @ git+https://mgit.mparsict.com/utils/mp-model-helper.git +mp-api-helper @ git+https://mgit.mparsict.com/utils/mp-api-helper.git +redis \ No newline at end of file diff --git a/utils/notification_client.py b/utils/notification_client.py deleted file mode 100644 index 8472a6b..0000000 --- a/utils/notification_client.py +++ /dev/null @@ -1,28 +0,0 @@ -import requests -from django.conf import settings - - -class NotificationClient(): - def notify(self, phone_number, body): - data = { - 'phone_number': phone_number, - 'body': body - } - # data = json.dumps(data) - header = { - # "Content-Type": "application/json", - "charset": "utf-8" - } - header.setdefault("Authorization", f"Bearer {settings.ACCESS_TOKEN}", ) - return {} - response = requests.request('post', - f'{settings.NOTIFICATIONS_SERVICE_URL}/notifications/', - headers=header, - json=data) - try: - return response.json() - except: - return response.text - - -notification_client = NotificationClient() diff --git a/utils/service_client.py b/utils/service_client.py new file mode 100644 index 0000000..b811e50 --- /dev/null +++ b/utils/service_client.py @@ -0,0 +1,12 @@ +import requests +from django.conf import settings + +from service_clients import Client, AccountsClient + +service_client = Client( + client_id=settings.CLIENT_ID, + client_secret=settings.CLIENT_SECRET, + grant_type=AccountsClient.GRANT_CLIENT_CREDENTIALS +) +service_client.login(scopes=['notification.notification:submit']) +