From 4537f1f4facf7f115770267c080f84cdbdfa270e Mon Sep 17 00:00:00 2001 From: jain Date: Tue, 27 Jun 2023 16:45:42 +0530 Subject: [PATCH 1/3] changes --- zod_bank/Dockerfile => Dockerfile | 0 .../docker-compose.yml => docker-compose.yml | 0 zod_bank/requirements.txt => requirements.txt | 0 zod_bank/account/urls.py | 3 ++- zod_bank/account/views.py | 4 ++++ zod_bank/zod_bank/settings.py | 20 ++++++++++++------- 6 files changed, 19 insertions(+), 8 deletions(-) rename zod_bank/Dockerfile => Dockerfile (100%) rename zod_bank/docker-compose.yml => docker-compose.yml (100%) rename zod_bank/requirements.txt => requirements.txt (100%) diff --git a/zod_bank/Dockerfile b/Dockerfile similarity index 100% rename from zod_bank/Dockerfile rename to Dockerfile diff --git a/zod_bank/docker-compose.yml b/docker-compose.yml similarity index 100% rename from zod_bank/docker-compose.yml rename to docker-compose.yml diff --git a/zod_bank/requirements.txt b/requirements.txt similarity index 100% rename from zod_bank/requirements.txt rename to requirements.txt diff --git a/zod_bank/account/urls.py b/zod_bank/account/urls.py index 0df4826..8462378 100644 --- a/zod_bank/account/urls.py +++ b/zod_bank/account/urls.py @@ -5,13 +5,14 @@ from rest_framework.decorators import api_view """Third party import""" from rest_framework import routers from .views import (UserLogin, SendPhoneOtp, UserPhoneVerification, UserEmailVerification, ReSendEmailOtp, - ForgotPasswordAPIView, ResetPasswordAPIView, ChangePasswordAPIView) + ForgotPasswordAPIView, ResetPasswordAPIView, ChangePasswordAPIView, GoogleLoginAPIViewset) """Router""" router = routers.SimpleRouter() """API End points with router""" router.register('user', UserLogin, basename='user') router.register('admin', UserLogin, basename='admin') +router.register('google-login', GoogleLoginAPIViewset, basename='admin') router.register('send-phone-otp', SendPhoneOtp, basename='send-phone-otp') router.register('user-phone-verification', UserPhoneVerification, basename='user-phone-verification') router.register('user-email-verification', UserEmailVerification, basename='user-email-verification') diff --git a/zod_bank/account/views.py b/zod_bank/account/views.py index 80a1e1a..5e73a14 100644 --- a/zod_bank/account/views.py +++ b/zod_bank/account/views.py @@ -21,6 +21,10 @@ from rest_framework.response import Response from rest_framework.permissions import IsAuthenticated from templated_email import send_templated_mail +class GoogleLoginAPIViewset(viewsets.ModelViewSet): + """Google Login""" + serializer_class = SocialSignInSerializer + class ChangePasswordAPIView(views.APIView): permission_classes = [IsAuthenticated] diff --git a/zod_bank/zod_bank/settings.py b/zod_bank/zod_bank/settings.py index 79eaeeb..e1527a4 100644 --- a/zod_bank/zod_bank/settings.py +++ b/zod_bank/zod_bank/settings.py @@ -173,12 +173,18 @@ https://docs.djangoproject.com/en/3.0/howto/static-files/""" # Email settings -EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' -EMAIL_HOST = 'smtp.gmail.com' -EMAIL_PORT = 587 -EMAIL_USE_TLS = True -EMAIL_HOST_USER = 'infozodbank@gmail.com' -# Replace with your Gmail email password or App password -EMAIL_HOST_PASSWORD = 'ghwdmznwwslvchga' +# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' +# EMAIL_HOST = 'smtp.gmail.com' +# EMAIL_PORT = 587 +# EMAIL_USE_TLS = True +# EMAIL_HOST_USER = 'infozodbank@gmail.com' +# # Replace with your Gmail email password or App password +# EMAIL_HOST_PASSWORD = 'ghwdmznwwslvchga' + +EMAIL_USE_TLS = os.getenv('EMAIL_USE_TLS') +EMAIL_HOST = os.getenv('EMAIL_HOST') +EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER') +EMAIL_HOST_PASSWORD = os.getenv('EMAIL_HOST_PASSWORD') +EMAIL_PORT = os.getenv('EMAIL_PORT') STATIC_URL = '/static/' From 019d028cb64d582db7ff57554a838e7d6b1ae21e Mon Sep 17 00:00:00 2001 From: jain Date: Tue, 27 Jun 2023 17:22:59 +0530 Subject: [PATCH 2/3] jira-5 google login --- zod_bank/account/serializers.py | 15 +++++++++++++++ zod_bank/account/views.py | 21 +++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/zod_bank/account/serializers.py b/zod_bank/account/serializers.py index 2f18213..4ee88c4 100644 --- a/zod_bank/account/serializers.py +++ b/zod_bank/account/serializers.py @@ -13,6 +13,21 @@ from rest_framework.decorators import action from django.contrib.auth import authenticate, login from rest_framework_simplejwt.tokens import RefreshToken +class GoogleSignInSerializer(serializers.Serializer): + """Google login Serializer""" + + def create(self, validated_data): + """Create or update user model""" + with transaction.atomic(): + print() + if User.objects.filter(email__iexact=self.validated_data['email']).exists(): + return User.objects.get(email__iexact=self.validated_data['email']) + + if not User.objects.filter(email__iexact=self.validated_data['email']).exists(): + instance = User.objects.create(username=self.validated_data['email'], + email=self.validated_data['email']) + return instance + class ResetPasswordSerializer(serializers.Serializer): """Reset Password after verification""" diff --git a/zod_bank/account/views.py b/zod_bank/account/views.py index 5e73a14..a8f25ab 100644 --- a/zod_bank/account/views.py +++ b/zod_bank/account/views.py @@ -8,7 +8,8 @@ from junior.models import Junior from account.models import UserProfile, UserPhoneOtp, UserEmailOtp from django.contrib.auth.models import User from .serializers import (SuperUserSerializer, GuardianSerializer, JuniorSerializer, EmailVerificationSerializer, - ForgotPasswordSerializer, ResetPasswordSerializer, ChangePasswordSerializer) + ForgotPasswordSerializer, ResetPasswordSerializer, ChangePasswordSerializer, + GoogleSignInSerializer) from rest_framework_simplejwt.tokens import RefreshToken from base.messages import ERROR_CODE, SUCCESS_CODE from guardian.tasks import generate_otp @@ -23,7 +24,23 @@ from templated_email import send_templated_mail class GoogleLoginAPIViewset(viewsets.ModelViewSet): """Google Login""" - serializer_class = SocialSignInSerializer + serializer_class = GoogleSignInSerializer + + def create(self, request, *args, **kwargs): + """ + Override default behaviour of create method + """ + provider_type = [] + serializer = self.get_serializer(data=request.data) + if serializer.is_valid(raise_exception=True): + provider = self.get_provider_view(request.data.get('provider')) + # if User is not authenticated then send error message + if not provider.is_authenticated(request): + return custom_error_response({}, status.HTTP_400_BAD_REQUEST) + + user = serializer.save() + if User.objects.filter(email__iexact=user.email).exists(): + class ChangePasswordAPIView(views.APIView): From d208e5252c7961e7420cfe4563240b735e01afb0 Mon Sep 17 00:00:00 2001 From: jain Date: Tue, 27 Jun 2023 19:32:57 +0530 Subject: [PATCH 3/3] jira-13 update country name --- .../migrations/0003_guardian_country_name.py | 18 ++++++++++++++++++ guardian/models.py | 1 + guardian/serializers.py | 1 + junior/migrations/0002_junior_country_name.py | 18 ++++++++++++++++++ junior/models.py | 1 + junior/serializers.py | 1 + 6 files changed, 40 insertions(+) create mode 100644 guardian/migrations/0003_guardian_country_name.py create mode 100644 junior/migrations/0002_junior_country_name.py diff --git a/guardian/migrations/0003_guardian_country_name.py b/guardian/migrations/0003_guardian_country_name.py new file mode 100644 index 0000000..ea9858b --- /dev/null +++ b/guardian/migrations/0003_guardian_country_name.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.2 on 2023-06-27 13:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('guardian', '0002_remove_guardian_junior_code'), + ] + + operations = [ + migrations.AddField( + model_name='guardian', + name='country_name', + field=models.CharField(blank=True, default=None, max_length=30, null=True), + ), + ] diff --git a/guardian/models.py b/guardian/models.py index f135bae..d9228b7 100644 --- a/guardian/models.py +++ b/guardian/models.py @@ -13,6 +13,7 @@ class Guardian(models.Model): """Contact details""" country_code = models.IntegerField(blank=True, null=True) phone = models.CharField(max_length=31, null=True, blank=True, default=None) + country_name = models.CharField(max_length=30, null=True, blank=True, default=None) """Personal info""" family_name = models.CharField(max_length=50, null=True, blank=True, default=None) gender = models.CharField(choices=GENDERS, max_length=15, null=True, blank=True, default=None) diff --git a/guardian/serializers.py b/guardian/serializers.py index e2bd807..c4dcfca 100644 --- a/guardian/serializers.py +++ b/guardian/serializers.py @@ -99,6 +99,7 @@ class CreateGuardianSerializer(serializers.ModelSerializer): guardian.phone = validated_data.get('phone', guardian.phone) guardian.country_code = validated_data.get('country_code', guardian.country_code) guardian.passcode = validated_data.get('passcode', guardian.passcode) + guardian.country_name = validated_data.get('country_name', guardian.country_name) guardian.referral_code_used = validated_data.get('referral_code_used', guardian.referral_code_used) """Complete profile of the junior if below all data are filled""" complete_profile_field = all([guardian.phone, guardian.gender, guardian.family_name, diff --git a/junior/migrations/0002_junior_country_name.py b/junior/migrations/0002_junior_country_name.py new file mode 100644 index 0000000..0dd74bd --- /dev/null +++ b/junior/migrations/0002_junior_country_name.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.2 on 2023-06-27 13:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('junior', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='junior', + name='country_name', + field=models.CharField(blank=True, default=None, max_length=30, null=True), + ), + ] diff --git a/junior/models.py b/junior/models.py index 732bb66..b389e3a 100644 --- a/junior/models.py +++ b/junior/models.py @@ -14,6 +14,7 @@ class Junior(models.Model): """Contact details""" phone = models.CharField(max_length=31, null=True, blank=True, default=None) country_code = models.IntegerField(blank=True, null=True) + country_name = models.CharField(max_length=30, null=True, blank=True, default=None) """Personal info""" gender = models.CharField(max_length=10, choices=GENDERS, null=True, blank=True, default=None) dob = models.DateField(max_length=15, null=True, blank=True, default=None) diff --git a/junior/serializers.py b/junior/serializers.py index 5d6df77..54d6fac 100644 --- a/junior/serializers.py +++ b/junior/serializers.py @@ -72,6 +72,7 @@ class CreateJuniorSerializer(serializers.ModelSerializer): junior.guardian_code = validated_data.get('guardian_code', junior.guardian_code) junior.dob = validated_data.get('dob',junior.dob) junior.passcode = validated_data.get('passcode', junior.passcode) + junior.country_name = validated_data.get('country_name', junior.country_name) """Update country code and phone number""" junior.phone = validated_data.get('phone', junior.phone) junior.country_code = validated_data.get('country_code', junior.country_code)