From b27449ca971e8fb80861511b22b7474a3f0d7ce5 Mon Sep 17 00:00:00 2001 From: sukanta-nandi Date: Mon, 5 Apr 2021 16:02:15 +0530 Subject: [PATCH] added google login --- jumbocashapi/models.py | 2 +- jumbocashapi/urls.py | 1 + jumbocashbackend/settings.py | 44 ++++++++++++++++++++++++++++++++++++ jumbocashbackend/urls.py | 4 +++- 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/jumbocashapi/models.py b/jumbocashapi/models.py index 31dca4a..338509d 100644 --- a/jumbocashapi/models.py +++ b/jumbocashapi/models.py @@ -73,7 +73,7 @@ def create_superuser(self, email, password, **kwargs): class Retailer(AbstractBaseUser, PermissionsMixin): """ Model for Retailer users """ email = models.EmailField(max_length=255, unique=True) - mobile_no = models.CharField(max_length=10, unique=True) + mobile_no = models.CharField(max_length=10, blank=True) firstname = models.CharField(max_length=255) lastname = models.CharField(max_length=255, blank=True) business_name = models.CharField(max_length=255, blank=True) diff --git a/jumbocashapi/urls.py b/jumbocashapi/urls.py index ae1cf0a..edadec3 100644 --- a/jumbocashapi/urls.py +++ b/jumbocashapi/urls.py @@ -29,4 +29,5 @@ path('register', views.RetailerCreateView.as_view()), path('login/', obtain_auth_token) + ] diff --git a/jumbocashbackend/settings.py b/jumbocashbackend/settings.py index 077eefd..bf345da 100644 --- a/jumbocashbackend/settings.py +++ b/jumbocashbackend/settings.py @@ -49,9 +49,27 @@ 'rest_framework.authtoken', 'multiple_permissions', 'django_filters', + 'django.contrib.sites', #apps 'corsheaders', 'jumbocashapi', + + #all auth + + 'allauth', + 'allauth.account', + 'allauth.socialaccount', + 'allauth.socialaccount.providers.google', +] + + +AUTHENTICATION_BACKENDS = [ + + # Needed to login by username in Django admin, regardless of `allauth` + 'django.contrib.auth.backends.ModelBackend', + + # `allauth` specific authentication methods, such as login by e-mail + 'allauth.account.auth_backends.AuthenticationBackend', ] @@ -172,3 +190,29 @@ CORS_ORIGIN_ALLOW_ALL = True # If this is used then `CORS_ORIGIN_WHITELIST` will not have any effect CORS_ALLOW_CREDENTIALS = True + + +SITE_ID = 2 + +# Provider specific settings +SOCIALACCOUNT_PROVIDERS = { + 'google': { + # For each OAuth based provider, either add a ``SocialApp`` + # (``socialaccount`` app) containing the required client + # credentials, or list them here: + 'APP': { + 'client_id': '868441464956-tokq3gth8g2h25oqi34fuabpan1f5u6l.apps.googleusercontent.com', + 'secret': 'fnJJNF7BLSpYi3LI6qDRbI9p', + 'key': '' + } + } +} + +# Allauth settings +ACCOUNT_AUTHENTICATION_METHOD = 'email' +ACCOUNT_EMAIL_REQUIRED = True +ACCOUNT_UNIQUE_EMAIL = True +ACCOUNT_USERNAME_REQUIRED = False +ACCOUNT_USER_MODEL_USERNAME_FIELD = None +LOGIN_REDIRECT_URL = '/retailers/profile/' +ACCOUNT_LOGOUT_REDIRECT_URL ='/accounts/login/' \ No newline at end of file diff --git a/jumbocashbackend/urls.py b/jumbocashbackend/urls.py index dc92170..0519a02 100644 --- a/jumbocashbackend/urls.py +++ b/jumbocashbackend/urls.py @@ -18,5 +18,7 @@ urlpatterns = [ path('admin/', admin.site.urls), - path('', include('jumbocashapi.urls')) + path('', include('jumbocashapi.urls')), + path('accounts/', include('allauth.urls')), + ]