示例#1
0
 def mutate(self, info, email=None):
     user = info.context.user
     if email is not None:
         if user.email != email and User.objects.filter(
                 email=email).exists():
             raise APIException('An account with this email already exist.',
                                code='EMAIL_IN_USE')
         user.email = email
         user.isEmailVerified = False
         user.save()
     else:
         if user.isEmailVerified:
             raise APIException('Email already verified',
                                code='EMAIL_ALREADY_VERIFIED')
     code = generate_otp()
     try:
         entry = UserVerificationOTP.objects.get(user=user,
                                                 isPhoneOTP=False)
         if entry.timestamp + timedelta(minutes=1) > timezone.now():
             raise APIException('Try after 1 minute', code='TRY_LATER')
         entry.code = code
         entry.timestamp = timezone.now()
         entry.save()
     except UserVerificationOTP.DoesNotExist:
         UserVerificationOTP.objects.create(code=code,
                                            user=user,
                                            isPhoneOTP=False)
     send_email_confirmation_email(user=user, code=code)
     return True
示例#2
0
 def mutate(self, info, email=None):
     try:
         user = User.objects.get(email=email)
         try:
             entry = UserVerificationOTP.objects.get(user=user,
                                                     isPhoneOTP=False)
             entry.delete()
         except UserVerificationOTP.DoesNotExist:
             pass
         code = generate_otp()
         UserVerificationOTP.objects.create(code=code,
                                            user=user,
                                            isPhoneOTP=False)
         send_password_reset_email(user=user, code=code)
         return True
     except User.DoesNotExist:
         raise APIException(
             'This email is not associated with any accounts',
             code='INVALID_EMAIL')
示例#3
0
 def mutate(self, info,
            input: UserCreationInput) -> AccountMutationResponse:
     if User.objects.filter(email=input.email).exists():
         raise APIException('An account with this email already exist.',
                            code='EMAIL_IN_USE')
     else:
         user = User.objects.create(name=input.name,
                                    email=input.email,
                                    username=generate_username_from_email(
                                        input.email),
                                    UTMSource=input.UTMSource)
         user.set_password(input.password)
         user.save()
         code = generate_otp()
         UserVerificationOTP.objects.create(code=code,
                                            user=user,
                                            isPhoneOTP=False)
         send_email_confirmation_email(user=user,
                                       code=code,
                                       eventID=input.eventID)
         return AccountMutationResponse(success=True, returning=user)
示例#4
0
 def mutate(self, info, phone: str = None):
     user = info.context.user
     if user.country == 'India':
         if phone is not None:
             if (not len(phone) == 13) or (not phone.startswith('+91')):
                 raise APIException('Invalid phone number',
                                    code='INVALID_PHONE_NO')
             if user.phone != phone and User.objects.filter(
                     phone=phone).exists():
                 raise APIException(
                     'An account with this phone already exist.',
                     code='PHONE_IN_USE')
             user.phone = phone
             user.isPhoneVerified = False
             user.save()
         else:
             if user.isPhoneVerified:
                 raise APIException('Phone already verified',
                                    code='PHONE_ALREADY_VERIFIED')
         code = generate_otp()
         try:
             entry = UserVerificationOTP.objects.get(user=user,
                                                     isPhoneOTP=True)
             if entry.timestamp + timedelta(minutes=1) > timezone.now():
                 raise APIException('Try after ' + str(
                     (entry.timestamp + timedelta(minutes=1) -
                      timezone.now()).seconds) + ' seconds',
                                    code='TRY_LATER')
             entry.code = code
             entry.timestamp = timezone.now()
             entry.save()
         except UserVerificationOTP.DoesNotExist:
             UserVerificationOTP.objects.create(code=code,
                                                user=user,
                                                isPhoneOTP=True)
         send_otp_to_number(code, number=phone)
     return True