From b819a11ba8c3cdda041a52a6629bf7a19c130c31 Mon Sep 17 00:00:00 2001 From: mahdavi Date: Tue, 10 Mar 2020 11:03:50 +0330 Subject: [PATCH] DEBUG from env --- apps/users/models.py | 5 +++-- client.py | 11 ++++++++++- gooyal_accounts/settings.py | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/users/models.py b/apps/users/models.py index 71861f6..2c9a355 100644 --- a/apps/users/models.py +++ b/apps/users/models.py @@ -1,6 +1,7 @@ import random from datetime import timedelta +from django.conf import settings from django.contrib.auth.base_user import BaseUserManager from django.contrib.auth.models import AbstractUser from django.contrib.auth.validators import UnicodeUsernameValidator @@ -110,9 +111,9 @@ class User(AbstractUser): objects = UserManager() def set_otp(self): - self.otp = '12345' - if self.phone_number in DEVELOPMENT_PHONE_NUMBERS: + if settings.DEBUG or self.phone_number in DEVELOPMENT_PHONE_NUMBERS: self.otp = '12345' + else: self.otp = ''.join(random.choice('0123456789') for _ in range(5)) diff --git a/client.py b/client.py index f2e74a8..448d164 100644 --- a/client.py +++ b/client.py @@ -22,7 +22,7 @@ class ApiClient(): "grant_type": "password", "username": phone_number, "password": password, - "scope": 'read write groups', + "scope": 'read write groups introspection', "auth_gateway": 'phone_number:otp' } auth = (OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET) @@ -145,3 +145,12 @@ class ApiClient(): def receipt_transaction(self, code): path = f'transactions/{code}/receipt' return self._request(path=path) + + def get_introspection(self): + path = 'oauth2/introspect/' + access_token = self.auth_data.get('access_token', '') + data = { + 'token': access_token, + } + return self._request(path=path, data=data) + diff --git a/gooyal_accounts/settings.py b/gooyal_accounts/settings.py index 107e65d..0939e1d 100644 --- a/gooyal_accounts/settings.py +++ b/gooyal_accounts/settings.py @@ -24,7 +24,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = 'tm9-y*5r=n028ii8iny#u1p3&mdjqf-#kj!z^fg%sbussj@r+o' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = config('DEBUG', False, cast=bool) ALLOWED_HOSTS = ['*']