sync send sms

This commit is contained in:
mahdavi 2020-11-01 23:54:09 +03:30
parent 200f1f9541
commit 0e994d7f7a
2 changed files with 19 additions and 22 deletions

View file

@ -166,16 +166,16 @@ class User(AbstractUser):
return result return result
def send_otp(self): def send_otp(self):
self.notify(body=str(self.otp), title='OTP ') self.notify(body=str(self.otp), title='OTP')
def notify(self, body, title=None, notification_type='sms'): def notify(self, body, title=None, notification_type='sms'):
print('request send sms') # TODO: enable celery
# send_notification.delay(phone_number=self.phone_number, send_notification(phone_number=self.phone_number,
# title=title, title=title,
# body=body, body=body,
# user_uuid=self.uuid, user_uuid=self.uuid,
# notification_type=1, notification_type=1,
# ) )
def __str__(self): def __str__(self):
return f"{self.pk} - {self.username}" return f"{self.pk} - {self.username}"

View file

@ -10,17 +10,14 @@ def send_notification(phone_number=None,
user_uuid=None, user_uuid=None,
email=None, email=None,
notification_type=1): notification_type=1):
print('sms sent') SCOPES = ['notifications.notification:submit']
# service_client = Client( client = Client(client_id=settings.CLIENT_ID,
# client_id=settings.CLIENT_ID, client_secret=settings.CLIENT_SECRET,
# client_secret=settings.CLIENT_SECRET, scopes=SCOPES,
# grant_type=AccountsClient.GRANT_CLIENT_CREDENTIALS grant_type=AccountsClient.GRANT_CLIENT_CREDENTIALS)
# ) data = {
# service_client.login(scopes=['notification.notification:submit']) 'phone_number': phone_number,
# service_client.notification.submit_notification(phone_number=phone_number, "body": f'{title}:\n{body}'
# title=title, }
# body=body, print(client.request(required_scopes=SCOPES, url=f'{settings.BASE_NOTIFICATION_URL}/notifications/', data=data,
# user_uuid=user_uuid, method='post').text)
# notification_type=notification_type,
# email=email
# )