def sent_otp_user_phone_number(self, request, **kwargs):
        '''
        Send OTP to user's phone on successfull registration
        Args : phone number
        Returns : OTP is sent to user's phone number
        '''
        if request.method != 'POST':
            return HttpResponse(json.dumps({"message":"method not allowed"}), content_type="application/json",status=401)
        try:
            load = json.loads(request.body)
        except:
            return HttpResponse(content_type="application/json", status=404)
        phone_number = load.get('phone_number')
        if not phone_number:
            return HttpBadRequest("phone_number is required.")
        try:
            otp = otp_handler.get_otp(phone_number=phone_number)
            message = afterbuy_utils.get_template('SEND_OTP').format(otp)
            send_job_to_queue(send_otp, {'phone_number':phone_number, 'message':message, 'sms_client':settings.SMS_CLIENT})
            logger.info('OTP sent to mobile {0}'.format(phone_number))
            data = {'status': 1, 'message': "OTP sent_successfully"}

        except Exception as ex:
            logger.error('Invalid details, mobile {0} and exception {1}'.format(request.POST.get('phone_number', ''),ex))
            data = {'status': 0, 'message': ex}
        return HttpResponse(json.dumps(data), content_type="application/json")
 def user_registration_phone(self, request, **kwargs):
     '''
     Register user with valid phone number
     Args : phone number
     Returns : OTP is sent to user's phone on successful registration
     
     '''
     if request.method != 'POST':
         return HttpResponse(json.dumps({"message":"method not allowed"}), content_type="application/json",status=401)
     try:
         load = json.loads(request.body)
     except:
         return HttpResponse(content_type="application/json", status=404)
     phone_number = load.get('phone_number')
     if not phone_number:
         return HttpBadRequest("Enter phone number")
     try:
         consumer_obj = get_model('Consumer', settings.BRAND).objects.get(phone_number=phone_number,
                                                                          user__is_active=True)
         data = {'status': 1, 'message': 'phone number already registered'}
     except Exception as ObjectDoesNotExist:
         logger.info('Exception while registering user - {0}'.format(phone_number))
         try:
             user_obj = self.create_user(True, phone_number=phone_number)
             consumer_obj = user_obj['consumer_obj']
             data = {'status':1, 'message': 'Phone number registered successfully'}
         except Exception as ex:
             logger.info("Exception while registering user with phone number - {0}".format(ex))
             return HttpBadRequest("Phone number could not be registered")
     try:
         otp = otp_handler.get_otp(phone_number=phone_number)
         message = afterbuy_utils.get_template('SEND_OTP').format(otp)
         send_job_to_queue(send_otp, {'phone_number': phone_number,
                                          'message': message,'sms_client': settings.SMS_CLIENT})
         consumer_obj.is_phone_verified = False
         consumer_obj.save()
         logger.info('OTP sent to mobile {0}'.format(phone_number))
         return HttpResponse(json.dumps(data), content_type="application/json")
     except Exception as ex:
         logger.info('Exception while generating OTP - {0}'.format(ex))
         return HttpBadRequest("OTP could not be generated")
 def authenticate_user_send_otp(self, request, **kwargs):
     if request.method != 'POST':
         return HttpResponse(json.dumps({"message":"method not allowed"}), content_type="application/json",status=401)
     try:
         load = json.loads(request.body)
     except:
         return HttpResponse(content_type="application/json", status=404)
     email = load.get('email_id')
     phone_number = load.get('phone_number')
     if not phone_number and not email:
         return HttpBadRequest("phone_number or email is required")
     try:
         if phone_number:
             phone_number = format_phone_number(phone_number)
             logger.info('OTP request received. Mobile: {0}'.format(phone_number))
             user_obj = afterbuy_model.Consumer.objects.get(phone_number=phone_number).user
             otp = otp_handler.get_otp(user=user_obj)
             message = afterbuy_utils.get_template('SEND_OTP').format(otp)
             send_job_to_queue('send_otp', {'phone_number': phone_number,
                                            'message': message, "sms_client": settings.SMS_CLIENT})
             logger.info('OTP sent to mobile {0}'.format(phone_number))
             data = {'status': 1, 'message': "OTP sent_successfully"}
             #Send email if email address exist
         if email:
             try:
                 consumer_obj = afterbuy_model.Consumer.objects.get(user__email=email, is_email_verified=True)
                 site = RequestSite(request)
                 afterbuy_model.EmailToken.objects.create_email_token(consumer_obj, email, site, trigger_mail='forgot-password')
                 data = {'status': 1, 'message': "Password reset link sent successfully"}
                 return HttpResponse(json.dumps(data), content_type="application/json")
             except Exception as ex:
                     log_message = "new user :{0}".format(ex)
                     logger.info(log_message)
                     data = {'status': 0, 'message': "Either your email is not verified or its not exist"}
     except Exception as ex:
         logger.error('Invalid details, mobile {0} and exception {1}'.format(request.POST.get('phone_number', ''),ex))
         data = {'status': 0, 'message': "inavlid phone_number/email_id"}
     return HttpResponse(json.dumps(data), content_type="application/json")