Ejemplo n.º 1
0
def generate_otp(request):
    if request.method == 'POST':
        try:
            username = request.POST['username']
            user = User.objects.get(username=username)
            phone_number = ''
            user_profile_obj = models.UserProfile.objects.filter(user=user)
            if user_profile_obj:
                phone_number = user_profile_obj[0].phone_number
                logger.info('OTP request received . username: {0}'.format(username))
                token = otp_handler.get_otp(user=user)
                message = get_template('SEND_OTP').format(token)
                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))
#             #Send email if email address exist
            if user.email:
                sent_otp_email(data=token, receiver=user.email, subject='Forgot Password')
        
            return HttpResponseRedirect('/aftersell/users/otp/validate?username='******'Invalid details, mobile {0}'.format(ex))
            return HttpResponseRedirect('/aftersell/users/otp/generate?details=invalid')    
    
    elif request.method == 'GET':
        return render(request, 'portal/get_otp.html')
 def send_otp_to_mail(self, phone_number, email):
     otp = otp_handler.get_otp(phone_number=phone_number, email=email)
     sent_otp_email(data=otp, receiver=email, subject='User registration')
     logger.info('OTP sent to email {0}'.format(email))
     return HttpResponse(json.dumps({'status':1, 'message' : 'OTP sent successfully'}),
                                     content_type='application/json')