diff --git a/apps/users/models.py b/apps/users/models.py index 48d8cad..288bed1 100644 --- a/apps/users/models.py +++ b/apps/users/models.py @@ -12,6 +12,7 @@ from rest_framework.exceptions import APIException import uuid from apps.users.constans import MAX_OTP_TRY, DEVELOPMENT_PHONE_NUMBERS +from utils.notifications_client import notification_client class UserManager(BaseUserManager): @@ -169,7 +170,7 @@ class User(AbstractUser): self.notify(sms_body) def notify(self, body, notification_type='sms'): - pass + notification_client.notify(phone_number=self.phone_number, body=body) def __str__(self): diff --git a/deploy.sh b/deploy.sh index 3d19968..42467af 100644 --- a/deploy.sh +++ b/deploy.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash # Deployment script -sudo apt-get install libmariadbclient-dev +apt install libmysqlclient-dev +apt install libssl-dev +apt install libcrypto++-dev +apt install lsb-release python manage.py migrate diff --git a/gooyal_accounts/settings.py b/gooyal_accounts/settings.py index 0939e1d..c21244b 100644 --- a/gooyal_accounts/settings.py +++ b/gooyal_accounts/settings.py @@ -153,3 +153,8 @@ 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 diff --git a/utils/__init__.py b/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/utils/notifications_client.py b/utils/notifications_client.py new file mode 100644 index 0000000..fdb99b4 --- /dev/null +++ b/utils/notifications_client.py @@ -0,0 +1,28 @@ +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}", ) + + 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()