def send_otp(request):
    try:
        name = request.POST.get("name", "")
        username = ""
        if "username" in request.POST.keys():
            username = request.POST.get("username", "")
        email = request.POST.get("email", "")
        app_id = request.POST.get("app_id", "")
        device_id = request.POST.get("device_id", "")
        app_version = request.POST.get("app_version", "")
        if username:
            user = User.objects.filter(username=username)

            if not user:
                user = User.objects.create_user(str(username), str(email), str(username))
                user.first_name = name
                user.save()
                apikey = ApiKey.objects.get_or_create(user=user)
                UserProfile(
                    user=user, contact=int(username), app_id=app_id, app_version=app_version, device_id=device_id
                ).save()
            else:
                user = user[0]
                apikey = ApiKey.objects.get_or_create(user=user)
                if not UserProfile.objects.filter(user=user):
                    UserProfile(
                        user=user, contact=int(username), app_id=app_id, app_version=app_version, device_id=device_id
                    ).save()

            sms_send_otp.send_otp(user)
        else:
            print "not a valid username "
        return HttpResponse("Done", content_type="application/json")
    except Exception as error_in_function:
        print "send_otp: {0}".format(str(error_in_function))
def send_otp(request):
	data="Done"
	username = request.POST.get('userName','')
	contact=""
	if 'contact' in request.POST.keys():
		contact = request.POST.get('contact','')
	email = request.POST.get('email','')
	app_id = request.POST.get('app_id','')
	device_id = request.POST.get('device_id','')
	app_version = request.POST.get('app_version',"")
	user = User.objects.filter(username=contact)
	if user:
		user=user[0]
		userProfile =user.userprofile
		if userProfile:
			userProfile.app_version=app_version
			userProfile.app_id=app_id
			userProfile.device_id=device_id
			userProfile.save()
		else:
			UserProfile(user=user,contact=int(contact),app_id=app_id,app_version=app_version,device_id=device_id).save()
	else:
		user=User.objects.create_user(contact,email,contact)
		user.first_name=username
		user.save()
		UserProfile(user=user,contact=int(contact),app_id=app_id,app_version=app_version,device_id=device_id).save()

	if contact:
		sms_send_otp.send_otp(contact)

	return HttpResponse(data, content_type='application/json')