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
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'):
print('request send sms')
# send_notification.delay(phone_number=self.phone_number,
# title=title,
# body=body,
# user_uuid=self.uuid,
# notification_type=1,
# )
# TODO: enable celery
send_notification(phone_number=self.phone_number,
title=title,
body=body,
user_uuid=self.uuid,
notification_type=1,
)
def __str__(self):
return f"{self.pk} - {self.username}"

View file

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