Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.http import HttpResponse, JsonResponse
- from django.views.decorators.csrf import csrf_exempt
- # from django.conf.urls import url
- from middleware import JWTMiddleware, TokenValidatorMiddleware, RequestValidatorMiddleware
- from models import *
- from wrap_core import *
- from html_strings import *
- import json
- import ast
- import boto
- from boto.s3.key import Key
- # import urlparse
- # from urllib.parse import urlparse, parse_qs
- from urlparse import urlparse
- m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
- from random import randint
- import requests
- from mailin import Mailin
- import time
- import uuid
- import hmac
- import csv
- import cgi
- from HTMLParser import HTMLParser
- import pyrebase
- import config
- import base64
- import hashlib
- import binascii
- import random, string
- from Crypto.Cipher import AES
- import pyotp
- import sys, os
- # import middleware
- # from rest_framework_swagger.views import get_swagger_view
- # schema_view = get_swagger_view(title='Token baazar API')
- # urlpatterns = [
- # url(r'^$', schema_view)
- # ]
- if config.prod is False:
- REGION_HOST = 's3.us-east-2.amazonaws.com'
- bucket_name = 'bubblo-kyc-data'
- else:
- REGION_HOST = 's3.eu-west-2.amazonaws.com'
- bucket_name = 'otc-data'
- if config.staging is False:
- token_baazar_media_url = '/home/parin/Documents/ico_with_bid/media/'
- service_account_json = "/home/parin/Documents/ico_with_bid/media/token baazar-f215172e741e.json"
- else:
- token_baazar_media_url = '/var/www/ico_with_bid/media/'
- service_account_json = "/var/www/ico_with_bid/media/token baazar-f215172e741e.json"
- service_account_json = get_firebase_config()
- s3_conn = boto.connect_s3(host=REGION_HOST)
- bucket = s3_conn.get_bucket("bubblo-kyc-data")
- # firebase_user_id = get_firebase_user_id
- # print 'firebase user authenticated:::s %s' %firebase_user_id
- firebase_config = {
- "apiKey": "AIzaSyBMsLUf7d6anHBiOTYzrQUaOhI-g8EhBH4",
- "authDomain": "proud-parity-131813.firebaseapp.com",
- "databaseURL": "https://proud-parity-131813.firebaseio.com",
- "projectId": "proud-parity-131813",
- "storageBucket": "proud-parity-131813.appspot.com",
- "messagingSenderId": "829650100337",
- # "serviceAccount": service_account_json
- }
- firebase = pyrebase.initialize_app(firebase_config)
- db = firebase.database()
- auth = firebase.auth()
- aes_key = 'd57c3965685720958cef68af53f6ba219e0eb1ddf163c649ebc8ec653c47fe8d'
- # Create your views here.
- if config.prod is False:
- eth_user = 'bubblo'
- eth_token = '2399038c8873444177469b4c4095baa2adf4fc'
- auxpay_user = 'bubblo'
- auxpay_token = '0d16df905b404a40a83af5aa837b6074d6140e6b71d245f4a090f2fc85990fab'
- multisig_address_url = 'http://207.154.234.187/get_key/' + auxpay_user + '?token=' + auxpay_token
- # multisig_address_url = 'http://159.203.125.112/get_key/' + auxpay_user+'?token='+ auxpay_token
- # multisig_address_url = 'http://127.0.0.1:5000/get_key/' + auxpay_user+'?token='+ auxpay_token
- btc_address_url = 'http://207.154.234.187/get_key/' + auxpay_user + '?token=' + auxpay_token + '¬ify_count=1'
- # btc_address_url = 'http://159.203.125.112/get_key/' + auxpay_user + '?token=' + auxpay_token + '¬ify_count=1'
- eth_address_url = 'http://138.197.111.208:8003/eth_auxpay/api/get_eth_address?user=' + eth_user + '&token=' + eth_token
- btc_fee_url = 'http://207.154.234.187/get_fees'
- # btc_fee_url = 'http://159.203.125.112/get_fees'
- eth_fee_url = 'http://138.197.111.208:8003/eth_auxpay/api/get_fee?user=' + eth_user + '&token' + eth_token
- btc_get_balance_url = 'http://207.154.234.187/get_balance'
- # btc_get_balance_url = 'http://159.203.125.112/get_balance'
- forward_btc_url = 'http://159.203.125.112/forward_btc'
- forward_eth_url = 'http://138.197.111.208:8003/eth_auxpay/api/forward_eth'
- hd_address_url = 'http://207.154.234.187/get_key/' + auxpay_user + '?token=' + auxpay_token + '&isInternal=false¬ify_count=1&conf_limit=10&type=HD&seed_hash='
- # hd_address_url = 'http://159.203.125.112/get_key/' + auxpay_user + '?token=' + auxpay_token + '&isInternal=false¬ify_count=1&conf_limit=10&type=HD&seed_hash='
- init_hd_seed_url = 'http://159.203.125.112/initialise_seed/' + auxpay_user + '?token=' + auxpay_token + '&type=HD'
- btc_withdraw_address = 'mpRvRkW2NeUgRJW9PWUuEVKh9hZ9kPJh76'
- eth_withdraw_address = ''
- eth_payout_address = '0x73e97a483381b16b6208d6c9eb8a85e6adf90d2d'
- cas_payout_address = '0xa95fef2fa0264e119d8ffe6136aa08bf7ab2d285'
- cas_withdraw_url = 'https://127.0.0.1:1234/cas/withdraw-cas/'
- else:
- eth_user = 'cashaa_otc'
- eth_token = '092a318a169b4c4095baa2adf4fc5c1af'
- auxpay_user = 'bubblo'
- auxpay_token = '0d16df905b404a40a83af5aa837b6074d6140e6b71d245f4a090f2fc85990fab'
- multisig_address_url = 'http://207.154.234.187/get_key/' + auxpay_user
- # multisig_address_url = 'http://127.0.0.1:5000/get_key/' + auxpay_user
- btc_address_url = 'http://207.154.234.187/get_key/' + auxpay_user + '?token=' + auxpay_token + '¬ify_count=1'
- eth_address_url = 'http://159.89.14.24:8003/eth_auxpay/api/get_eth_address?user=' + eth_user + '&token=' + eth_token
- btc_fee_url = 'http://207.154.234.187/get_fees'
- eth_fee_url = 'http://159.89.14.24:8003/eth_auxpay/api/get_fee?user=' + eth_user + '&token=' + eth_token
- btc_get_balance_url = 'http://207.154.234.187/get_balance'
- forward_btc_url = 'http://207.154.234.187/forward_btc'
- forward_eth_url = 'http://159.89.14.24:8003/eth_auxpay/api/forward_eth'
- hd_address_url = 'http://207.154.234.187/get_key/' + auxpay_user + '?token=' + auxpay_token + '&isInternal=false¬ify_count=1&conf_limit=10&type=HD&seed_hash='
- init_hd_seed_url = 'http://207.154.234.187/initialise_seed/' + auxpay_user + '?token=' + auxpay_token + '&type=HD'
- btc_withdraw_address = '14ZZ4YybZF7ggT2yDucNACfWizTFEJ2Gbb'
- eth_withdraw_address = '0x1e7d5667bf73f8a666d87fe3a3ae5ed52747fb4c'
- eth_payout_address = '0x0ba7ebb60e19d85f5c1bba88a765a1b4eeff9a7a'
- cas_withdraw_url = 'https://127.0.0.1:1234/cas/withdraw-cas'
- def _decrypt(edata, password):
- def pad(data):
- BLOCK_SIZE = 16
- pad = BLOCK_SIZE - len(data) % BLOCK_SIZE
- return data + pad * chr(pad)
- def unpad(padded):
- pad = ord(padded[-1])
- return padded[:-pad]
- try:
- edata = base64.urlsafe_b64decode(str(edata))
- m = hashlib.md5()
- m.update(password)
- key = m.hexdigest()
- m = hashlib.md5()
- m.update(password + key)
- iv = m.hexdigest()
- aes = AES.new(key, AES.MODE_CBC, iv[:16])
- str1 = str(unpad(aes.decrypt(edata)))
- str1 = unicode(str1, errors='replace')
- print 'unpadded final', str1
- return str1
- except Exception as e:
- print "Decrypt failed. Error: ", e.message
- return None
- @csrf_exempt
- # @TokenValidatorMiddleware
- # @RequestValidatorMiddleware
- def sign_up(request):
- """abcd abcd"""
- print 'bbb %s,%s, aaa %s' % (request.body, type(request.body), request.POST)
- data = json.loads(request.body)
- print 'ppppp %s,%s' % (data, type(data))
- if request.method == 'POST':
- email = data['email']
- exists_flag = user_exists_model(email)
- password_flag = password_exists_model(email)
- if exists_flag is None or password_flag is None:
- return JsonResponse({"code": 200, 'type': 'new'})
- else:
- forgot_token = str(randint(111111, 999999))
- otp_session('forgot_password_' + email, forgot_token)
- return JsonResponse({"code": 200, 'type': 'old', 'forgot_token': forgot_token})
- return JsonResponse({'response': 'get request'})
- @csrf_exempt
- def android_sign_in(request):
- print 'hitted android sign_up0'
- data = json.loads(request.body)
- email = data['email']
- password = data['password']
- flag = validate_user(email, password)
- if flag:
- forgot_token = str(randint(111111, 999999))
- otp_session('forgot_password_' + email, forgot_token)
- return JsonResponse({"code": 200, 'type': 'old', 'forgot_token': forgot_token})
- else:
- return JsonResponse({'code': 401, 'msg': 'invalid_user'})
- @csrf_exempt
- @TokenValidatorMiddleware
- @RequestValidatorMiddleware
- def init_forgot_password(request):
- data = json.loads(request.body)
- email = data['email']
- forgot_token = data['forgot_token']
- flag = otp_verification('forgot_password_' + email, forgot_token)
- if flag == 1:
- url = data['url']
- send_forgot_password_email(email, url)
- name = get_user_name(email)
- return JsonResponse({"code": 200, 'msg': 'link_sent', 'name': name})
- else:
- return JsonResponse({"code": 400, "err": "invalid_forgot_token"})
- def send_forgot_password_email(email, url):
- data = { "id" : 43,
- "to" : {email: email},
- "replyto" : "support@auxledger.org",
- "attr" : {"url": str(url)},
- "headers" : {"Content-Type": "text/html;charset=iso-8859-1"}
- }
- result = m.send_transactional_template(data)
- @csrf_exempt
- @TokenValidatorMiddleware
- @RequestValidatorMiddleware
- def forgot_password(request):
- data = json.loads(request.body)
- email = data['email']
- forgot_token = data['forgot_token']
- flag = otp_verification('forgot_password_' + email, forgot_token)
- if flag == 1:
- password = data['password']
- if len(password) > 7 and password.isalpha() == False and password.isdigit() == False:
- update_password_model(email, password)
- res = user_exists_model(email)
- if res.__contains__('tnc'):
- unique_id = create_jwt(email)
- # unique_id = str(uuid.uuid4()) + str(uuid.uuid4()) + str(uuid.uuid4())
- save_uuid(unique_id, email)
- if res.__contains__('kyc'):
- return JsonResponse({'code': 200, 'tnc': True, 'kyc': res['kyc']['status'], 'token': unique_id})
- else:
- return JsonResponse({'code': 200, 'tnc': True, 'kyc': False, 'token': unique_id})
- else:
- return JsonResponse({'code': 200, 'tnc': False, 'kyc': False})
- else:
- return JsonResponse({"code": 400, 'msg': 'invalid_password'})
- else:
- return JsonResponse({"code": 400, "err": "invalid_forgot_token"})
- @csrf_exempt
- @TokenValidatorMiddleware
- def new_user_password(request):
- data = json.loads(request.body)
- email = data['email']
- password = data['password']
- # exists_flag = user_exists_model(email)
- password_flag = password_exists_model(email)
- if password_flag:
- return JsonResponse({'code': 400, 'msg': 'already_exists'})
- if len(password) > 7 and password.isalpha() == False and password.isdigit() == False:
- user_existance(email, password)
- otp = str(randint(111111, 999999))
- data = {"id": 36,
- "to": {email: email},
- "replyto": "support@auxledger.org",
- "attr": {"otp": str(otp)},
- "headers": {"Content-Type": "text/html;charset=iso-8859-1"}
- }
- result = m.send_transactional_template(data)
- if result['code'] == "success":
- otp_session(email, otp)
- return JsonResponse({'code': 200, 'msg': 'password_set_successfully'})
- else:
- return JsonResponse({"code": 400, 'msg': 'invalid_password'})
- @csrf_exempt
- @TokenValidatorMiddleware
- def verify_otp(request): ##email and otp is taken from front end
- data = json.loads(request.body)
- email = data['email']
- otp_ = data['otp']
- flag = otp_verification(email, otp_)
- if flag == 1:
- res = user_exists_model(email)
- if res.__contains__('tnc'):
- # if res['kyc']['status'] == 'pending':
- # return JsonResponse({'code':200,'tnc':True,'kyc':'pending'})
- # elif res['kyc']['status'] == 'rejected':
- # return JsonResponse({"code":200,'tnc':True,'kyc':'rejected'})
- # else:
- unique_id = create_jwt(email)
- save_uuid(unique_id, email)
- if res.__contains__('kyc'):
- return JsonResponse({'code': 200, 'tnc': True, 'kyc': res['kyc']['status'], 'token': unique_id})
- else:
- return JsonResponse({'code': 200, 'tnc': True, 'kyc': False, 'token': unique_id})
- # elif res.__contains__('tnc') and not res.__contains__('kyc'):
- # return JsonResponse({'code':200,'tnc':True,'kyc':False})
- else:
- res1 = enter_signup_in_user_timeline(email)
- return JsonResponse({'code': 200, 'tnc': False, 'kyc': False})
- else:
- return JsonResponse({"code": 400, "otp": "not_verified"})
- @csrf_exempt
- # @TokenValidatorMiddleware
- # @JWTMiddleware
- def logout(request):
- data = json.loads(request.body)
- email = data['email']
- unique_id = data["token"]
- uuid_flag = 1
- if uuid_flag == 1:
- del_uuid_from_redis(unique_id)
- return JsonResponse({"code": 200, "success": True})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- def verify_password(request):
- data = json.loads(request.body)
- email = data['email']
- password = data['password']
- res = verify_password_model(email, password)
- if res:
- res = check_2fa_status(email)
- if res:
- return JsonResponse({"code": 200, "password_match": True, '2fa_enabled': True})
- else:
- send_otp_mail(email)
- return JsonResponse({"code": 200, "password_match": True, '2fa_enabled': False})
- else:
- return JsonResponse({"code": 400, "password_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def change_password(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- password = data['current_password']
- new_password = data['new_password']
- res = verify_password_model(email, password)
- if res:
- if len(new_password) > 7 and new_password.isalpha() == False and new_password.isdigit() == False:
- update_password_model(email, new_password)
- return JsonResponse({'code': 200, 'msg': 'password_set_successfully'})
- else:
- return JsonResponse({"code": 400, 'msg': 'invalid_password'})
- else:
- return JsonResponse({"code": 400, "password_match": False})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- def resent_otp(request):
- data = json.loads(request.body)
- email = data['email']
- otp = str(randint(111111, 999999))
- otp_session(email, otp)
- m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
- data = {"id": 36,
- "to": {email: email},
- "replyto": "support@auxledger.org",
- "attr": {"otp": str(otp)},
- "headers": {"Content-Type": "text/html;charset=iso-8859-1"}
- }
- result = m.send_transactional_template(data)
- exists_flag = user_exists_model(email)
- password_flag = password_exists_model(email)
- if exists_flag is None or password_flag is None:
- return JsonResponse({"code": 200, 'type': 'new'})
- else:
- forgot_token = str(randint(111111, 999999))
- otp_session('forgot_password_' + email, forgot_token)
- return JsonResponse({"code": 200, 'type': 'old', 'forgot_token': forgot_token})
- def send_otp_mail(email):
- print "_-------------------into send_otp_mail_____-----------------"
- otp = str(randint(111111, 999999))
- otp_session(email, otp)
- m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
- data = {"id": 36,
- "to": {email: email},
- "replyto": "support@auxledger.org",
- "attr": {"otp": str(otp)},
- "headers": {"Content-Type": "text/html;charset=iso-8859-1"}
- }
- result = m.send_transactional_template(data)
- print 'opt email status for email ::: %s, is:::: %s' % (email, result)
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def get_otp_qr_code(request):
- data = json.loads(request.body)
- email = data['email']
- unique_id = data['token']
- uuid_flag = uuid_verification(unique_id, email)
- if uuid_flag == 1:
- res = get_otp_str_model(email)
- if res:
- qr_code_str = pyotp.TOTP(res['otp_str']).provisioning_uri("Auxledger Tokensale", issuer_name="Auxledger")
- return JsonResponse({'code': 200, 'msg': 'new_user', 'qr_code_str': qr_code_str})
- else:
- otp_str = pyotp.random_base32()
- insert_in_otp(email, otp_str)
- qr_code_str = pyotp.TOTP(otp_str).provisioning_uri("Auxledger Tokensale", issuer_name="Auxledger")
- return JsonResponse({'code': 200, 'msg': '2fa_already_done', 'qr_code_str': qr_code_str})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- def enable_google_authenticator(request):
- data = json.loads(request.body)
- email = data['email']
- unique_id = data['token']
- uuid_flag = uuid_verification(unique_id, email)
- if uuid_flag == 1:
- otp = data['otp']
- res = get_otp_str(email)
- if res:
- otp_str = res['otp_str']
- totp = pyotp.TOTP(otp_str)
- otp_flag = totp.verify(otp)
- if otp_flag is True:
- update_current_otp_flag(email)
- return JsonResponse({'code': 200, 'msg': 'enabled_2fa'})
- else:
- return JsonResponse({'code': 400, 'msg': 'otp_verification_false'})
- else:
- return JsonResponse({'code': 400, 'error': '2fa_already_enabled'})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def disable_google_authenticator(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- otp = data['otp']
- res = get_otp_str(email, True)
- if res:
- otp_str = res['otp_str']
- totp = pyotp.TOTP(otp_str)
- otp_flag = totp.verify(otp)
- if otp_flag is True:
- disable_current_otp_flag(email)
- return JsonResponse({'code': 200, 'msg': 'disable_2fa'})
- else:
- return JsonResponse({'code': 400, 'msg': 'otp_verification_false'})
- else:
- return JsonResponse({'code': 400, 'error': '2fa_already_disabled'})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- def tnc(request):
- if request.method == "POST":
- data = json.loads(request.body)
- name = data['name']
- email = data['email']
- user_ref_id = get_ref_id(email)
- if data.__contains__('ref_id'):
- if data['ref_id'] is None:
- print '11'
- insert_parent_ref_id(user_ref_id, None)
- else:
- print '22'
- ref_id = data['ref_id']
- ref_id_flag = validate_ref_id(ref_id)
- if ref_id_flag is None:
- return JsonResponse({'code': 400, 'error': 'invalid_ref_id'})
- insert_parent_ref_id(user_ref_id, ref_id)
- push_child_ref_id(user_ref_id, ref_id)
- else:
- insert_parent_ref_id(user_ref_id, None)
- res = user_exists_model(email)
- # print res
- # unique_id = str(uuid.uuid4()) + str(uuid.uuid4()) + str(uuid.uuid4())
- unique_id = create_jwt(email)
- save_uuid(unique_id, email)
- if res.__contains__("tnc"):
- print("----------->")
- if config.development:
- path = "/home/parin/Documents/ico_with_bid/Kyc_tier2_approved_userlist.csv"
- else:
- path = "/var/www/ico_with_bid/Kyc_tier2_approved_userlist.csv"
- with open(path, 'rb') as f:
- reader = csv.reader(f)
- for row in reader:
- if email == row[0]:
- pre_approve_kyc(email)
- return JsonResponse(
- {"code": 400, 'status': 'already_done', "tnc": True, "kyc": True, "token": unique_id})
- if res.__contains__('kyc'):
- if res['kyc']['status'] == 'pending':
- return JsonResponse(
- {"code": 400, 'status': 'already_done', "tnc": True, "kyc": 'pending', "token": unique_id})
- elif res['kyc']['status'] == 'rejected':
- return JsonResponse(
- {"code": 400, 'status': 'already_done', "tnc": True, "kyc": 'rejected', "token": unique_id})
- else:
- return JsonResponse(
- {"code": 400, 'status': 'already_done', "tnc": True, "kyc": True, "token": unique_id})
- else:
- return JsonResponse(
- {"code": 400, 'status': 'already_done', "tnc": True, "kyc": False, "token": unique_id})
- else:
- tnc_model(name, email)
- with open('/var/www/ico_with_bid/Kyc_tier2_approved_userlist.csv', 'rb') as f:
- reader = csv.reader(f)
- for row in reader:
- if email == row[0]:
- pre_approve_kyc(email)
- return JsonResponse(
- {"code": 200, 'status': 'accepted', "tnc": True, "kyc": True, "token": unique_id})
- return JsonResponse({"code": 200, 'status': 'accepted', "tnc": True, "kyc": False, "token": unique_id})
- from django.core.files.storage import FileSystemStorage
- @csrf_exempt
- # @TokenValidatorMiddleware
- # @JWTMiddleware
- def kyc(request):
- email = request.POST.get('email')
- aadhar_card_obj = request.FILES.get('idproofs')
- pan_card_obj = request.FILES.get('pan_card')
- aadhar_name = email + "_" + "_" + aadhar_card_obj.name
- pan_name = email + "_" + pan_card_obj.name
- fs = FileSystemStorage(location="/var/www/ico_with_bid/media/kyc")
- fs.save(aadhar_name, aadhar_card_obj)
- fs.save(pan_name, pan_card_obj)
- input_json = {"status": "pending", "aadhar_card_details": aadhar_name, "pan_card_details": pan_name}
- kyc_model(input_json, email)
- enter_kyc_submit_in_user_timeline(email)
- return JsonResponse({"code": 200, "tnc": True, 'kyc': 'pending'})
- # @csrf_exempt
- # @TokenValidatorMiddleware
- # @JWTMiddleware
- # def kyc(request):
- # data = json.loads(request.body)
- # email = data['email']
- # uuid_flag =1
- # if uuid_flag == 1:
- # id_proofs = data['idproofs']
- # aadhar_counter = 0
- # aadhar_card_details = []
- # valid_file_types = ['jpg','jpeg','png','pdf']
- # for id_data in id_proofs:
- # id_data['name'] = 'aadharcard_' + str(aadhar_counter) + '_' + hashlib.sha256(email).hexdigest() + '_' + str(int(time.time())) + '.' + id_data['filename'].split('.')[1]
- # id_data['filetype'] = id_data['filetype'].split('/')[1]
- # if id_data['filetype'] not in valid_file_types:
- # return JsonResponse({'code':401,'error':'invalid_file_type'})
- # id_data['path'] = token_baazar_media_url
- # aadhar_counter += 1
- # # with open(token_baazar_media_url + id_data['name'],'wb') as adh:
- # # adh.write(id_data['value'].decode('base64'))
- # aadhar_card_details.append(id_data)
- #
- # pan_card_details = data['pan_card']
- # pan_card_name = 'pancard_' + hashlib.sha256(email).hexdigest() + '_' + str(int(time.time())) + '.' + pan_card_details['filename'].split('.')[1]
- # # with open(token_baazar_media_url + pan_card_name,'wb') as fh:
- # # fh.write(pan_card_details['value'].decode('base64'))
- # pan_card_details['name'] = pan_card_name
- # pan_card_details['filetype'] = pan_card_details['filetype'].split('/')[1]
- # if pan_card_details['filetype'] not in valid_file_types:
- # return JsonResponse({'code':401,'error':'invalid_file_type'})
- # pan_card_details['path'] = token_baazar_media_url
- # k = Key(bucket)
- # k.set_contents_from_string(str(aadhar_card_details))
- # adhaar_id = k.key
- # k = Key(bucket)
- # k.set_contents_from_string(str(pan_card_details))
- # pan_status = k.key
- # input_json = {"status":"pending","aadhar_card_details":adhaar_id,"pan_card_details":pan_status}
- # kyc_model(input_json,email)
- # enter_kyc_submit_in_user_timeline(email)
- # return JsonResponse({"code":200,"tnc":True,'kyc':'pending'})
- # else:
- # return JsonResponse({"code":401,'reason':'unauthorized'})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def create_erc_address(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- erc_address = data['erc_address']
- erc_address_validation = validate_eth_address(erc_address)
- if erc_address_validation is False:
- return JsonResponse({'code': 401, 'address_validation': False})
- eth_wallet = data['eth_wallet']
- res = create_erc_address_model(email, erc_address, eth_wallet)
- return JsonResponse({'code': 200, 'address_validation': True})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def dashboard(request):
- print 'in dashboaard::: '
- data = json.loads(request.body)
- email = data['email']
- # unique_id = data['token']
- # uuid_flag = uuid_verification(unique_id,email)
- uuid_flag = 1
- if uuid_flag == 1:
- # flag = address_avaiblity(email)
- # res = user_exists_model(email)
- # if not res.__contains__('seed_hash'):
- # init_seed_res = requests.get(init_hd_seed_url)
- # # print 'aaaa %s,%s' % (init_seed_res.status_code, json.loads(init_seed_res.text))
- # if init_seed_res.status_code == 200:
- # init_seed_hash = json.loads(init_seed_res.text)['msg']['seedhash']
- # encrypted_phrase = json.loads(init_seed_res.text)['msg']['phrase']
- # key = hashlib.sha256(init_seed_hash).hexdigest()[0:16]
- # seeds = _decrypt(encrypted_phrase,key)
- # print 'seeds are::: %s' %seeds
- # res = save_seed_hash_model(email,init_seed_hash,seeds)
- # if not res.__contains__('btc_address') or not res.__contains__('eth_address'):
- # btc_address_res = requests.get(btc_address_url)
- # eth_address_res = requests.get(eth_address_url)
- # if btc_address_res.status_code == 200 and eth_address_res.status_code == 200:
- # btc_address = json.loads(btc_address_res.text)['msg']
- # eth_address = json.loads(eth_address_res.text)['msg']['address']
- # address_insertion_model(btc_address,eth_address,email)
- # # return JsonResponse({"code":200,"btc address":btc_address,"eth_address":eth_address})
- # else:
- # return JsonResponse({"code":500,"error":'unable_to_generate_btc_or_eth_address'})
- # else:
- # btc_address = res['btc_address']
- # eth_address = res['eth_address']
- user_details = user_exists_model(email)
- user_name = user_details['tnc']['name']
- if user_details.__contains__('kyc'):
- kyc_flag = user_details['kyc']['status']
- else:
- kyc_flag = None
- user_timeline_list = []
- tokens = 0.0
- timeline_res = get_user_timeline_model(email)
- for data in timeline_res:
- user_timeline_list.append(data)
- if data.__contains__('tokens_purchased'):
- tokens += float(data['tokens_purchased'])
- if data.__contains__('token_purchased'):
- tokens += float(data['token_purchased'])
- # cashaa_withdrawal_res = get_cashaa_withdrawal_details(email)
- # for data in cashaa_withdrawal_res:
- # tokens -= int(float(data['amount_withdrawn']))
- rates_list = []
- timestamp = int(time.time())
- # btc_rate = get_rate(timestamp,'btc')
- # eth_rate = get_rate(timestamp,'eth')
- # fiat_rate = get_rate(timestamp,'fiat')
- # rates_list.append({'btc':btc_rate})
- # rates_list.append({'eth':eth_rate})
- # rates_list.append({'fiat':fiat_rate})
- # min_cap,max_cap = get_cap(timestamp)
- two_fa_status = check_2fa_status(email)
- send_dict = {
- 'status': 200,
- 'user_timeline_list': user_timeline_list,
- # 'rates_list':rates_list,
- # 'min_cap':min_cap,
- # 'max_cap':max_cap,
- 'kyc': kyc_flag,
- 'tokens': round(tokens, 3),
- 'user_name': user_name,
- 'two_fa_status': two_fa_status
- }
- # print "*********************************************************%s" %send_dict["tokens"]
- return JsonResponse(send_dict)
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- def normal_graph_data(request):
- print 'send normal_graph_data'
- data = json.loads(request.body)
- email = data['email']
- # unique_id = data['token']
- uuid_flag = 1
- if uuid_flag == 1:
- from_timestamp = int(data['from_timestamp'])
- to_timestamp = int(data['to_timestamp'])
- graph_data = get_graph_data(from_timestamp, to_timestamp)
- return JsonResponse({"code": 200, 'graph_data': graph_data})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- def address_avaiblity(email):
- print email
- res = user_exists_model(email)
- print("----------->")
- print res
- if res.__contains__("btc_address") and res.__contains__("eth_address"):
- flag = 1
- else:
- flag = 0
- return flag
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def calculate_token_price(request):
- print 'calculating token pricce::: '
- data = json.loads(request.body)
- currency = data['currency']
- # token_amount = data['token_amount']
- email = data['email']
- # unique_id = data['token']
- uuid_flag = 1
- # uuid_flag = uuid_verification(unique_id,email)
- if uuid_flag == 1:
- rate = get_rate(int(time.time()), currency)
- # return_dict = {}
- print 'rate is:: %s' % rate
- # for key,value in rates_dict.iteritems():
- # return_dict[key] = float(float(token_amount)/float(value))
- return JsonResponse({currency: rate})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def fiat_currency_for_approval(request): # for user
- data = json.loads(request.body)
- email = data['email']
- exchange_rate = get_usd_rate()
- uuid_flag = 1
- if uuid_flag == 1:
- amount_deposited = data['amount_deposited']
- date = data['date']
- transaction_id = data['transaction_id']
- bank = data['deposit_bank']
- type = data['type']
- currency = data['currency']
- insert_fiat_transaction_for_approval(amount_deposited,date,transaction_id,bank,email,exchange_rate,type,currency)
- wire_insert_payment_initialization_in_user_timeline(email,amount_deposited,currency)
- try:
- send_fiat_pending_mail(email, amount_deposited, transaction_id, bank,currency)
- except Exception as e:
- print "mail error"
- return JsonResponse({'code': 200, 'success': True})
- else:
- return JsonResponse({"code": 400, "token_match": False})
- def send_fiat_pending_mail(email, amount_deposited, transaction_id, bank,currency):
- m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
- data = { "id" : 44,
- "to" : {email: email},
- "replyto" : "support@auxledger.org",
- "attr" : {"amount_deposited": str(amount_deposited), "currency": currency},
- "headers" : {"Content-Type": "text/html;charset=iso-8859-1"}
- }
- result = m.send_transactional_template(data)
- print result
- print result
- @csrf_exempt
- # @TokenValidatorMiddleware
- # @JWTMiddleware
- def get_pending_fiat_transactions(request): # show fiat data to admin
- data = json.loads(request.body)
- uuid_flag = 1
- if uuid_flag == 1:
- pending_fiat_transactions = get_pending_fiat_transactions_model()
- return_list = []
- for data in pending_fiat_transactions:
- temp_json = {}
- temp_json["date"] = str(data["date"])
- temp_json["bank"] = str(data["bank"])
- temp_json["payment_method"] = data["type"]
- temp_json["time"] = data["time"]
- temp_json["amount_deposited_according_to_user"] = data["amount_deposited_according_to_user"]
- temp_json["transaction_id"] = data["transaction_id"]
- temp_json["email"] = data["email"]
- return_list.append(temp_json)
- return JsonResponse({'code': 200, 'pending_fiat_transactions': return_list})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- def get_fiat_data_from_admin(request): ##call when user is approved
- data = json.loads(request.body)
- print data
- email = data['email']
- transaction_id = data["transaction_id"]
- update_json = {'email': data['email'], 'admin_receive_date': data['receive_date'],
- 'admin_receive_time': data['receive_time'], 'admin_received_amount': data['received_amount'],
- "admin_send_token": data['send_token'], "transaction_status": data['status']}
- update_fiat_transaction_admin(**update_json)
- if (data['status'] == "approve"):
- insert_fiat_transaction_in_transaction_details(email, transaction_id)
- # insert_payment_initialization_in_user_timeline(email,"usd",token_amount,price,amount_to_pay,bid_id)
- final_fiat_data = get_final_fiat_data(email, transaction_id)
- return JsonResponse({'code': 200, 'final_fiat_data': final_fiat_data})
- @csrf_exempt
- # @TokenValidatorMiddleware
- # @JWTMiddleware
- def fiat_confirmation_url(request):
- data = json.loads(request.body)
- print data
- _id = data['_id']
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- timestamp = data['timestamp']
- amount = float(data['amount'])
- res = update_fiat_transaction_flag(_id)
- erc_address = get_erc_address(email)
- erc_wallet = get_erc_wallet(email)
- insert_res = insert_fiat_transaction_in_transaction_details(_id, email, timestamp, amount, erc_address,
- erc_wallet)
- insert_successful_fiat_transaction_in_user_timeline(_id, timestamp, amount, email)
- ref_id, name = get_referral_details_model_fiat(_id)
- calc_referal_bonus(ref_id, insert_res, name, 'fiat')
- return JsonResponse({'success': True})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def fiat_rejection_url(request):
- data = json.loads(request.body)
- print 'rejecting fiat transaction::::: %s' % data
- _id = data['_id']
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- res = reject_fiat_transaction_flag(_id)
- insert_rejected_fiat_transaction_in_user_timeline(_id, email)
- return JsonResponse({'code': 200, 'success': True})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def pay_with_currency(request): ##not applicable for fiat
- print "_______-pay with currency___________-%s" % request.body
- data = json.loads(request.body)
- email = data['email']
- currency = data['currency']
- token_amount = data['token_amount']
- price_distribution, price = get_price(token_amount, currency)
- if currency == 'btc':
- btc_to_usd = get_current_bubblo_price_model('btc')
- amount_to_pay = round(float(price), 8)
- bid_id = None
- to_address, address_code = get_address_from_cashaa_pay(email, currency)
- redeem_script = "NA"
- to_address_json = {"dummy": "NA"}
- if address_code == 400:
- return JsonResponse({'code': 400, 'error': 'unable_to_generate_btc_address'})
- res = insert_pay_click_model_btc(email, currency, token_amount, amount_to_pay, price, price_distribution,
- to_address, btc_to_usd, bid_id, redeem_script, to_address_json)
- insert_payment_initialization_in_user_timeline(email, currency, token_amount, price, amount_to_pay, bid_id)
- return JsonResponse(
- {'code': 200, 'currency': currency, 'price': price, 'amount_to_pay': amount_to_pay, '_id': str(res),
- 'to_address': to_address, 'bid_id': bid_id})
- if currency == 'eth':
- print "Into currency = eth"
- eth_to_usd = get_current_bubblo_price_model('eth')
- amount_to_pay = round(float(price), 3)
- bid_id = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6))
- to_address, address_code = get_address_from_cashaa_pay(email, currency)
- if address_code == 400:
- return JsonResponse({'code': 400, 'error': 'unable_to_generate_eth_address'})
- insert_unverified_transaction(email, currency, token_amount, amount_to_pay, price, price_distribution,
- to_address, eth_to_usd, bid_id)
- insert_payment_initialization_in_user_timeline(email, currency, token_amount, price, amount_to_pay, bid_id)
- return JsonResponse({'code': 200, 'currency': currency, 'price': price, 'amount_to_pay': amount_to_pay,
- 'to_address': to_address, 'bid_id': bid_id, 'bid_id_hex': binascii.hexlify(bid_id)})
- def get_address_from_cashaa_pay(email, currency):
- code = 400
- address = "na"
- if currency == "btc" or currency == "BTC":
- address = "NA"
- print "into get_address_cashaa"
- url_wallet_id = "http://35.181.20.211/bank/account/setup"
- url_address = "http://35.181.20.211/bank/address/multisig/"
- header_content = {
- "token": "HfgF2bJVHHDb-heUBQRhUIL3e",
- "username": "auxledger",
- "Authorization": "Basic YXV4bGVkZ2VyOk5FZTNxVUlZVWdsbnJndlhFMGdMRGR1a2lGamIzNHJUbDBWTg=="
- }
- present = check_if_wallet_present(email, currency)
- if present:
- address = present
- return address, 200
- else:
- response = requests.post(url_wallet_id, headers=header_content)
- resp = response.json()
- resp_data = resp["data"]
- if int(resp["code"]) == 200:
- wallet_id = resp_data["walletId"]
- url_address = url_address + wallet_id
- response = requests.post(url_address, headers=header_content)
- resp = response.json()
- if int(resp["code"]) == 200:
- code = 200
- address = resp["address"]
- insert_address_in_cashaa_wallet(email, address, wallet_id, currency)
- add_btc_address_to_user_master_model(email, address)
- return address, code
- return address, code
- if currency == "eth" or currency == "ETH":
- code = 400
- eth_address_url_uat = "http://52.23.53.49:8003/v1/eth/singleton/address"
- eth_address_url_prod = "http://35.180.218.161:8003/v1/eth/singleton/address"
- user_address = check_if_wallet_present(email, currency)
- if user_address:
- return user_address, 200
- else:
- headers_content = {
- "x-app-key": "xal-auxledger",
- "x-secret-key": "ZUdGc0xXRjFlR3hsWkdkbGNpMWhkWGhsYzJseg==",
- }
- headers_content["x-app-wallet-id"] = email
- headers_content["x-app-user-id"] = email
- body_content = {
- "userpassword": email
- }
- try:
- response = requests.post(eth_address_url_prod, headers=headers_content, data=body_content)
- resp_json = response.json()
- print resp_json
- if resp_json["body"]["status"] == "success":
- address = resp_json["body"]["data"]["address"]
- wallet_id = email
- insert_address_in_cashaa_wallet(email, address, wallet_id, currency)
- add_eth_address_to_user_master_model(email, address)
- return address, 200
- except Exception as e:
- print e
- return address, code
- @csrf_exempt
- # @TokenValidatorMiddleware
- # @JWTMiddleware
- def cas_for_approval_from_user(request): # for user
- print "-----------into cas_for_approval_from_user----------"
- data = json.loads(request.body)
- email = data['email']
- txid = data['tx_id']
- _id = data['_id']
- res = update_txid_cas_model(_id, txid)
- return JsonResponse({'code': 200})
- def send_cas_admin_pending_mail(email, amount_deposited, transaction_id, bank):
- print 'sending email for fiat admin pending'
- m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
- email_dict = {
- "to": {email: email},
- "from": ["support@auxledger.org"],
- "subject": "Welcome at Auxledger ",
- "html": "Your payment of " + str(
- amount_deposited) + " CAS is registered with us. Please wait for admin approval."
- }
- result = m.send_email(email_dict)
- print 'res::: %s' % result
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def send_cashaa_withdrawal_otp(request):
- data = json.loads(request.body)
- email = data['email']
- # unique_id = data['token']
- uuid_flag = 1
- if uuid_flag == 1:
- res = get_otp_str(email, True)
- if not res:
- otp = str(randint(111111, 999999))
- user_name = get_user_name(email)
- m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
- print 'sending mail to admin::: '
- email_dict = {
- "to": {email: email},
- "from": ["support@auxledger.org"],
- "subject": "OTP for Auxledger token withdrawal",
- "html": get_html_send_cashaa_withdrawal_otp(user_name, str(otp))
- }
- result = m.send_email(email_dict)
- print 'res::: %s' % result
- if result['code'] == "success":
- otp_session('withdraw_cashaa_' + email, otp)
- # print 'mail sent response ::::::: %s' % result
- return JsonResponse({"code": 200, 'success': 'mail sent'})
- else:
- return JsonResponse({"code": 400, 'failed': 'mail not sent'})
- else:
- return JsonResponse({"code": 200, 'success': 'mail sent'})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def verify_cashaa_withdraw_otp(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- print 'eeeeeeeeee %s' % email
- otp_ = data['otp']
- flag = otp_verification('withdraw_cashaa_' + email, otp_)
- if flag == 1:
- return JsonResponse({'code': 200, "otp": "verified"})
- else:
- return JsonResponse({"code": 400, "otp": "not_verified"})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def get_cashaa_withdrawals_for_admin(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- list_to_send = get_cashaa_withdrawals_for_admin_model()
- return JsonResponse({"code": 200, "withdrawal_list": list_to_send})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def approve_cashaa_withdrawal(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- _id = data['_id']
- res = get_withdraw_details(_id)
- to_address = res['to_address']
- token = res['amount_withdrawn']
- requests.packages.urllib3.disable_warnings()
- cas_res = requests.post(cas_withdraw_url, data={"token": token, "toaddress": to_address}, verify=False)
- print 'data sent to cas withdrawal url::::: %s, is :::::: %s, response status is::::: %s, text is:::::: %s' % (
- cas_withdraw_url, {"token": token, "to_address": to_address}, cas_res.status_code, cas_res.text)
- if cas_res.status_code == 200:
- cas_txt = json.loads(cas_res.text)
- if cas_txt['data']['data'][len(cas_txt['data']['data']) - 1].__contains__('hash'):
- txid = cas_txt['data']['data'][len(cas_txt['data']['data']) - 1]['hash']
- approve_cashaa_withdrawal_model(_id, txid)
- return JsonResponse({"code": 200, "success": True, "txid": txid})
- else:
- return JsonResponse({'code': 400, 'msg': 'transaction_falied'})
- else:
- return JsonResponse({"code": 400, "msg": 'transaction_falied'})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def reject_cashaa_withdrawal(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- _id = data['_id']
- reject_cashaa_withdrawal_model(_id)
- return JsonResponse({"code": 200, "success": True})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def request_cashaa_withdraw(request):
- print 'request_cashaa_withdraw hitted::: '
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- from_address = data['from_address']
- to_address = data['to_address']
- value = data['value']
- cas_bal = get_user_cas_bal(email)
- if float(value) > float(cas_bal):
- return JsonResponse({"code": 400, "error": "insufficient_funds"})
- insert_withdraw_in_cashaa_withdrawals(email, from_address, to_address, value)
- send_withdraw_init_mail(email, value)
- return JsonResponse({"code": 200, "success": True})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- def send_withdraw_init_mail(email, value):
- m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
- print 'sending mail to admin::: '
- email_dict = {
- "to": {email: email},
- "from": ["support@auxledger.org"],
- "subject": "Withdraw request initiated",
- "html": get_send_withdraw_init_mail_html(value)
- }
- result = m.send_email(email_dict)
- print 'res::: %s' % result
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def update_erc_address(request):
- print 'update_erc hitted:::: '
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- _id = data['_id']
- new_erc_address = data['new_erc_address']
- new_erc_wallet = data['new_erc_wallet']
- erc_address_validation = validate_eth_address(new_erc_address)
- if erc_address_validation is False:
- return JsonResponse({'code': 401, 'address_validation': False})
- currency = data['currency']
- refund_address = get_refund_address_using_mail(email, currency)
- update_unconfirmed_status_after_erc_review(_id)
- update_erc_in_user_master(email, new_erc_address, new_erc_wallet)
- res = update_pay_click_model(_id, new_erc_address, new_erc_wallet)
- return JsonResponse({'code': 200, 'success': True, 'refund_address': refund_address, 'currency': currency})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def review_erc_address(request):
- print 'review erc_address hitted::::: '
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- _id = data['_id']
- currency = data['currency']
- refund_address = get_refund_address_using_mail(email, currency)
- update_unconfirmed_status_after_erc_review(_id)
- return JsonResponse({'code': 200, 'success': True, 'refund_address': refund_address, 'currency': currency})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def update_refund_address(request):
- print 'update_refund hitted:::: '
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- _id = data['_id']
- currency = data['currency']
- new_refund_address = data['new_refund_address']
- if currency == 'btc':
- btc_address_validation = validate_btc_address(new_refund_address)
- if btc_address_validation is False:
- return JsonResponse({'code': 401, 'address_validation': False})
- else:
- eth_address_validation = validate_eth_address(new_refund_address)
- if eth_address_validation is False:
- return JsonResponse({'code': 401, 'address_validation': False})
- token_amount = data['token_amount']
- # rate = float(get_rate(int(time.time()),currency))
- # amount_to_pay = float(token_amount)/rate
- res = update_refund_address_in_unconfirmed_transaction(_id, new_refund_address)
- # generated_address = get_generated_address(email,currency)
- generated_address = eth_payout_address
- update_unconfirmed_status_after_refund_review(_id)
- update_refund_address_in_user_master(email, new_refund_address, currency)
- # obj_id = get_obj_id(email)
- send_dict = {
- 'code': 200,
- 'success': True,
- 'generated_address': generated_address,
- 'token_amount': token_amount,
- # 'rate':rate,
- # 'amount_to_pay':amount_to_pay,
- 'currency': currency
- }
- return JsonResponse(send_dict)
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def get_current_cashaa_price(request):
- print 'getting current cashaa price:::: '
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- currency = data['currency']
- current_cashaa_price = get_current_cashaa_price_model(currency)
- return JsonResponse({"code": 200, "current_cashaa_price": current_cashaa_price})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def review_refund_address(request):
- print 'review_refund_address hitted:::: '
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- _id = data['_id']
- currency = data['currency']
- token_amount = data['token_amount']
- # rate = float(get_rate(int(time.time()),currency))
- # amount_to_pay = float(token_amount)/rate
- generated_address = eth_payout_address
- update_unconfirmed_status_after_refund_review(_id)
- send_dict = {
- 'code': 200,
- 'success': True,
- 'generated_address': generated_address,
- 'token_amount': token_amount,
- # 'rate':rate,
- # 'amount_to_pay':amount_to_pay,
- 'currency': currency
- }
- return JsonResponse(send_dict)
- else:
- return JsonResponse({"code": 401, "token_match": False})
- # @csrf_exempt
- # def update_status_after_transaction(request):
- # print 'hit update_status_after_transaction:::: '
- # data = json.loads(request.body)
- # email = data['email']
- # unique_id = data['token']
- # uuid_flag = uuid_verification(unique_id,email)
- # if uuid_flag == 1:
- # _id = data['_id']
- # update_unconfirmed_status_after_transaction(_id)
- # return JsonResponse({'code':200,'success':True})
- # else:
- # return JsonResponse({"code":401,"token_match":False})
- # from urllib import parse as urlparse
- # from six.moves.urllib.parse import urlparse
- import urlparse
- import sys, os
- from . import models
- @csrf_exempt
- def btc_notification_url(request):
- try:
- print '------------------ in btc notification ------------------- '
- data = json.loads(request.body)
- print data
- address = data['to_address']
- value = float(data['amount'])
- from_address = data["from_address"]
- txid = data['txid']
- confirmations = int(data['confirmations'])
- email_id = get_email_id_model(address, 'btc')
- if confirmations == 0:
- print "0th confirmations"
- # update in transaction details
- update_transaction_details(address, from_address, value, txid, confirmations)
- no_of_token_allocated, exchange_rate = models.get_no_of_token_allocated(email_id, txid)
- send_mail_flag = insert_zero_confirmation_in_user_timeline(email_id, 'btc', no_of_token_allocated, value,
- None, txid)
- if send_mail_flag:
- print "sending 0 conf mail"
- try:
- send_zero_confirmation_mail(email_id, value, 'BTC', txid, exchange_rate)
- except Exception as e:
- print "send mail error"
- return HttpResponse('OK')
- else:
- proceed_flag = False
- old_confirmations = check_for_conformations(txid, email_id)
- # if missed 0th confirmations
- if not old_confirmations:
- print "txid doesnt exist in transcation details"
- update_transaction_details(address, from_address, value, txid, confirmations)
- if confirmations >= 1:
- proceed_flag = insert_btc_transaction_in_user_timeline(email_id, address, from_address, value, txid,
- confirmations)
- if proceed_flag:
- ref_id, name = get_referral_details_model(address, 'btc')
- calc_referal_bonus_auxledger(ref_id, value, name, 'btc', address, txid, email_id)
- no_of_token_allocated, exchange_rate = models.get_no_of_token_allocated(email_id, txid)
- print "sending received email"
- try:
- send_confirmation_mail(email_id, no_of_token_allocated, value, 'BTC')
- except Exception as e:
- print "sending mail error"
- return HttpResponse('OK')
- # else part
- else:
- print "txid exist in transcation details"
- print "old confirmations is %s new confirmations is %s" % (old_confirmations, confirmations)
- if old_confirmations < confirmations:
- update_transaction_details(address, from_address, value, txid, confirmations)
- proceed_flag = insert_btc_transaction_in_user_timeline(email_id, address, from_address, value, txid,
- confirmations)
- if proceed_flag:
- ref_id, name = get_referral_details_model(address, 'btc')
- calc_referal_bonus_auxledger(ref_id, value, name, 'btc', address, txid, email_id)
- no_of_token_allocated, exchange_rate = models.get_no_of_token_allocated(email_id, txid)
- print "sending email of positive confirmations"
- try:
- send_confirmation_mail(email_id, no_of_token_allocated, value, 'BTC')
- except Exception as e:
- print "sending mail error"
- return HttpResponse('OK')
- print "doing nothing"
- return HttpResponse('OK')
- except Exception as e:
- print "into exception"
- print e
- exc_type, exc_obj, exc_tb = sys.exc_info()
- fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
- error_stack = str(exc_type) + str(fname) + str(exc_tb.tb_lineno)
- print error_stack
- return JsonResponse({"code": 400, "msg": e})
- # except Exception as e:
- # print 'Exception in btc_notification::: %s' %e.message
- # return HttpResponse('ok')
- # else:
- # eth_refund_address = get_refund_address(to_address)
- # eth_fee_res = requests.get(eth_fee_url)
- # if value < min_cap:
- # if eth_fee_res.status_code == 200:
- # eth_fee = json.loads(eth_fee_res)['msg']['transaction_fee']
- # refund_amount = value
- # refund_eth(to_address,eth_refund_address,refund_amount,eth_fee,'less_than_cap')
- # else:
- # print 'eth_auxpay fee response error::: '
- # eth_refund_dict = {
- # 'from_address':to_address,
- # 'refund_address':eth_refund_address,
- # 'amount_to_refund':value,
- # 'timestamp':int(time.time()),
- # 'refund_type':'less_than_cap',
- # 'currency':'eth'
- # }
- # insert_unsuccessful_eth_refund(eth_refund_dict)
- # if value > max_cap:
- # if eth_fee_res.status_code == 200:
- # eth_fee = json.loads(eth_fee_res)['msg']['transaction_fee']
- # refund_amount = value - max_cap
- # refund_eth(to_address,eth_refund_address,refund_amount,eth_fee,'more_than_cap')
- # else:
- # print 'eth_auxpay fee response error::: '
- # eth_refund_dict = {
- # 'from_address':to_address,
- # 'refund_address':eth_refund_address,
- # 'amount_to_refund':value - max_cap,
- # 'timestamp':int(time.time()),
- # 'refund_type':'more_than_cap',
- # 'currency':'eth'
- # }
- # insert_unsuccessful_eth_refund(eth_refund_dict)
- # if confirmations == 0:
- # print 'inserting eth transaction::: %s' %request.POST
- # res = update_recieve_transaction_eth_model(to_address,from_address,max_cap,txid,confirmations)
- # email_id = get_email_id_model(to_address,'eth')
- # # transaction_details = get_transacation_details_model(txid)
- # firebase_json = {
- # 'email_id':email_id,
- # 'to_address':to_address,
- # 'from_address':from_address,
- # 'value':value,
- # 'txid':txid,
- # 'confirmations':0
- # }
- # results = db.child('bubblo_transaction_details').child(to_address).set(firebase_json,firebase_user_id)
- # print 'db update response after eth notification is::: %s' % res
- # return HttpResponse('ok')
- # else:
- # print 'update eth confirmations:::::, of txid::: %s, confirmations::: %s' %(txid,confirmations)
- # res = update_transaction_confirmations(txid)
- # email_id = get_email_id_model(to_address,'eth')
- # transaction_details = get_transacation_details_model(txid)
- # # firebase_json = {
- # # 'email_id':email_id,
- # # 'to_address':to_address,
- # # 'from_address':from_address,
- # # 'value':value,
- # # 'txid':txid,
- # # 'confirmations':transaction_details['confirmations'],
- # # 'currency':'eth'
- # # }
- # results = db.child('bubblo_transaction_details').child(to_address).update({'confirmations':transaction_details['confirmations']})
- # print 'db update response after updating eth confirmation is::: %s' % res
- # if confirmations == 3:
- # insert_eth_transaction_in_user_timeline(email_id,to_address, from_address, value, txid,confirmations)
- # return HttpResponse('ok')
- def calculate_btc_fee(address, btc_refund_address, refund_amount):
- bal_dict = {
- 'user_name': auxpay_user,
- 'token': auxpay_token,
- 'address_list': [address]
- }
- bal_res = requests.post(btc_get_balance_url, data=json.dumps(bal_dict))
- print 'json sent %s to bal_url %s' % (bal_dict, btc_get_balance_url)
- if bal_res.status_code == 200:
- print 'ba res::: %s,%s' % (json.loads(bal_res.text)[0], type(json.loads(bal_res.text)[0]))
- address_details = json.loads(bal_res.text)[0][address]
- address_btc_bal = address_details['confirmed']
- # address_btc_bal = 50.0
- # spent = address_details['spent']
- # unconfirmed = address_details['unconfirmed']
- # address_btc_bal = confirmed - spent + unconfirmed
- else:
- address_btc_bal = None
- fee_dict = {
- 'user_name': auxpay_user,
- 'token': auxpay_token,
- 'transactions': {
- 'input_address': [address],
- 'output_address': {
- btc_refund_address: round(refund_amount, 8),
- address: round(address_btc_bal - refund_amount, 8)
- }
- }
- }
- fee_res = requests.post(btc_fee_url, data=json.dumps(fee_dict))
- print 'json sent %s to fee_url %s' % (fee_dict, btc_fee_url)
- if fee_res.status_code == 200:
- recommended_rate = json.loads(fee_res.text)['recommended_rate']
- inputs = json.loads(fee_res.text)['nInputs']
- # transaction_fee = 0.00040335
- # transaction_fee = (148 inputs + 34 2 + 10) recommended_rate 0.001
- transaction_fee = - (json.loads(fee_res.text)['diff'])
- # btc_to_send = + transaction_fee
- else:
- transaction_fee = 0.00040335
- print 'fee_api_response:::::::::: %s,%s,%s' % (
- fee_res.text, fee_res.status_code, type(fee_res.status_code))
- return transaction_fee, address_btc_bal
- @csrf_exempt
- def eth_notification_url(request):
- print "_______into eth notification url_____________%s" % request.body
- data = json.loads(request.body)
- from_address = data['from_address']
- to_address = data['to_address']
- txid = data['txid']
- confirmations = int(data['confirmations'])
- value = float(data["amount"])
- email_id = get_email_id_from_to_address_model(to_address)
- if not email_id:
- return JsonResponse({"code": 400, "msg": "address not available"})
- erc_address = get_erc_address(email_id)
- erc_wallet = get_erc_wallet(email_id)
- if confirmations == 0:
- proceed_flag = update_recieve_transaction_eth_model(email_id, to_address, from_address, value, txid,
- confirmations, erc_address, erc_wallet)
- if proceed_flag:
- no_of_token_allocated, exchange_rate = models.get_no_of_token_allocated(email_id, txid)
- send_mail_flag = insert_zero_confirmation_in_user_timeline(email_id, 'eth', no_of_token_allocated, value,
- to_address, txid)
- if send_mail_flag:
- try:
- send_zero_confirmation_mail(email_id, value, 'ETH', txid, exchange_rate)
- except Exception as e:
- print "sending mail error"
- return HttpResponse('ok')
- else:
- old_confirmations = check_for_conformations(txid, email_id)
- # if missed 0th confirmations
- if old_confirmations is None:
- update_recieve_transaction_eth_model(email_id, to_address, from_address, value, txid, confirmations,
- erc_address, erc_wallet)
- if confirmations >= 1:
- send_mail_flag = insert_eth_transaction_in_user_timeline(email_id, to_address, from_address, value,
- txid, confirmations)
- if send_mail_flag:
- ref_id, name = get_referral_details_model(to_address, 'eth')
- calc_referal_bonus_auxledger(ref_id, value, name, 'eth', to_address, txid, email_id)
- no_of_token_allocated, exchange_rate = models.get_no_of_token_allocated(email_id, txid)
- print "sending received email"
- try:
- send_confirmation_mail(email_id, no_of_token_allocated, value, 'ETH')
- except Exception as e:
- print "send mail error"
- return HttpResponse('OK')
- else:
- print "txid exist in transcation details"
- print "old confirmations is %s new confirmations is %s" % (old_confirmations, confirmations)
- if old_confirmations < confirmations:
- update_recieve_transaction_eth_model(email_id, to_address, from_address, value, txid, confirmations,
- erc_address, erc_wallet)
- send_mail_flag = insert_eth_transaction_in_user_timeline(email_id, to_address, from_address, value,
- txid, confirmations)
- if send_mail_flag:
- ref_id, name = get_referral_details_model(to_address, 'eth')
- calc_referal_bonus_auxledger(ref_id, value, name, 'eth', to_address, txid, email_id)
- no_of_token_allocated, exchange_rate = models.get_no_of_token_allocated(email_id, txid)
- print "sending received email"
- try:
- send_confirmation_mail(email_id, no_of_token_allocated, value, 'ETH')
- except Exception as e:
- print "send mail error", e
- return HttpResponse('OK')
- print "doing nothing"
- return HttpResponse('ok')
- def refund_eth(from_address, to_address, amount, fee, refund_type):
- print 'refunding etherr from address::: %s, to address:: %s, amount::: %s, fee::: %s' % (
- from_address, to_address, amount, fee)
- timestamp = str(int(time.time()))
- signature = calculate_signature('token_baazar_staging', 'abcd', timestamp)
- eth_send_dict = {
- 'user': eth_user,
- 'token': eth_token,
- 'from_address': from_address,
- 'to_address': to_address,
- 'ethers': float(amount),
- 'timestamp': timestamp,
- 'signature': signature
- }
- eth_forward_res = requests.post(forward_eth_url, data=json.dumps(eth_send_dict))
- if eth_forward_res.status_code == 200:
- eth_transaction_details = json.loads(eth_forward_res.text)
- if eth_transaction_details['code'] == 200:
- print 'status code:: 200, eth transaction successful'
- txid = eth_transaction_details['transaction_hash']
- eth_refund_dict = {
- 'from_address': from_address,
- 'refund_address': to_address,
- 'txid': txid,
- 'transaction_fee': fee,
- 'amount_refunded': float(amount) - float(fee),
- 'timestamp': int(time.time()),
- 'refund_type': refund_type,
- 'currency': 'eth'
- }
- insert_successful_eth_refund(eth_refund_dict)
- else:
- print 'status not 200::: eth transaction unsuccessful'
- eth_refund_dict = {
- 'from_address': from_address,
- 'refund_address': to_address,
- 'amount_to_refund': amount,
- 'timestamp': int(time.time()),
- 'refund_type': refund_type,
- 'currency': 'eth'
- }
- insert_unsuccessful_eth_refund(eth_refund_dict)
- else:
- print 'eth_auxpay error::: '
- eth_refund_dict = {
- 'from_address': from_address,
- 'refund_address': to_address,
- 'amount_to_refund': amount,
- 'timestamp': int(time.time()),
- 'refund_type': refund_type,
- 'currency': 'eth'
- }
- insert_unsuccessful_eth_refund(eth_refund_dict)
- def calculate_signature(user, token, timestamp):
- salt = '007d8f8604acef969b08a2a63819ac0323b447bedd5d14596b86137db23be379'
- signature_json = {
- 'timestamp': timestamp,
- 'user': user,
- 'token': token,
- }
- tmp_list = []
- for param, value in signature_json:
- tmp_list.append(param + '=' + value)
- tmp_list.sort()
- signature_str = ''
- for key in tmp_list:
- signature_str += key + ','
- signature_str = signature_str[0:len(signature_str) - 1]
- signature = hmac.new(salt, signature_str, hashlib.sha256).hexdigest()
- return signature
- # Admin module
- @csrf_exempt
- def sign_in(request):
- print("---------admin_signIn-------->")
- data = json.loads(request.body)
- if request.method == 'POST':
- email = data['email']
- password = data['password']
- status = admin_vefificatoin(email, password)
- if status:
- # otp = str(randint(111111, 999999))
- # m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
- # print 'sending mail to admin::: '
- # email_dict = {
- # "to": {email: email},
- # "from": ["support@auxledger.org"],
- # "subject": "LOGIN OTP",
- # "html": "Admin OTP is " + otp
- # }
- # result = m.send_email(email_dict)
- # print 'email response %s' % result
- # if result['code'] == "success":
- # otp_session(email, otp)
- # print 'mail sent response ::::::: %s' % result
- return JsonResponse({"code": 200, 'success': 'mail sent'})
- else:
- return JsonResponse({'code': 400, 'failed': 'no data found'})
- return JsonResponse({'response': 'get request'})
- @csrf_exempt
- def verify_admin_otp(request): ##email and otp is taken from front end
- print "inside admin otp "
- data = json.loads(request.body)
- email = data['email']
- otp_ = data['otp']
- flag = otp_verification(email, otp_)
- if flag == 1:
- unique_id = create_jwt(email)
- save_uuid(unique_id, email)
- role = get_admin_role(email)
- return JsonResponse({"code": 200, "otp": "verified", 'token': unique_id, 'role': role})
- else:
- return JsonResponse({"code": 400, "otp": "not_verified"})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def admin_dashboard(request):
- try:
- data = json.loads(request.body)
- email = data['email']
- data = admin_dashboard_data()
- if data:
- data['code'] = 200
- return JsonResponse(data)
- else:
- return JsonResponse({'code':400,'msg':'server error'})
- except Exception as e:
- print e
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def get_withdrawal_details_admin(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- res = get_withdrawal_details_admin_model()
- list_to_send = []
- for data in res:
- data['_id'] = str(data['_id'])
- list_to_send.append(data)
- return JsonResponse({'code': 200, 'withdrawal_list': list_to_send})
- else:
- return JsonResponse({'code': 401, 'token_match': False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def user_verify(request):
- data = json.loads(request.body)
- user_email = data['useremail']
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- kyc_status_verify(user_email)
- enter_kyc_accept_in_user_time(email)
- return JsonResponse({"code": 200, "verified-documents": "true", 'status': 'accepted'})
- else:
- return JsonResponse({'code': 401, 'token_match': False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def user_reject(request): ##only update status:rejected
- data = json.loads(request.body)
- email = data['email']
- user_email = data['useremail']
- uuid_flag = 1
- if uuid_flag == 1:
- reason = data['reason']
- kyc_status_reject(user_email, reason)
- enter_kyc_reject_in_user_time(email)
- return JsonResponse({"code": 200, "verified-documents": "true", 'status': 'rejected'})
- else:
- return JsonResponse({'code': 401, 'token_match': False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def get_all_users(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- user_list = []
- res = get_all_users_model()
- for data in res:
- user_list.append(data)
- return JsonResponse({'code': 200, 'users_list': user_list})
- else:
- return JsonResponse({'code': 401, 'token_match': False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def display_pending(request): ##only update status:rejected
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- if data.__contains__('page'):
- page = int(data['page'])
- else:
- page = 1
- res, count = show_pending_model(page)
- return_list = []
- for data in res:
- pan_id = data['kyc']['pan_card_details']
- aadhar_id = data['kyc']['aadhar_card_details']
- # pan_card_details = ast.literal_eval(bucket.get_key(pan_id).get_contents_as_string())
- # aadhar_card_details = ast.literal_eval(bucket.get_key(aadhar_id).get_contents_as_string())
- file_loc = '/var/www/ico_with_bid/media/kyc/'
- get_user_details = user_kyc_details_model(0, **{"email": data['email']})
- return_list.append({'user_details': get_user_details, 'kyc': {'pan_card_details': file_loc+pan_id,
- 'aadhar_card_details': file_loc+aadhar_id},
- 'email': data['email']})
- # return_list.append(data['email'])
- return JsonResponse({'code': 200, 'kyc_list': return_list, 'total_pending': count})
- else:
- return JsonResponse({'code': 401, 'token_match': False})
- @csrf_exempt
- # @TokenValidatorMiddleware
- # @JWTMiddleware
- def user_kyc_details(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- kyc_details = get_user_kyc_details_model(email)
- pan_id = kyc_details['kyc']['pan_card_details']
- aadhar_id = kyc_details['kyc']['aadhar_card_details']
- # pan_card_details = ast.literal_eval(bucket.get_key(pan_id).get_contents_as_string())
- # aadhar_card_details = ast.literal_eval(bucket.get_key(aadhar_id).get_contents_as_string())
- get_user_details = user_kyc_details_model(0, **{"email": email})
- return JsonResponse({'code': 200, 'user_details': get_user_details, 'kyc_details': {
- 'kyc': {'pan_card_details': pan_id, 'aadhar_card_details': aadhar_id,
- 'status': kyc_details['kyc']['status']}}})
- else:
- return JsonResponse({'code': 401, 'token_match': False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def display_accepted(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- page = data['page']
- res, count = show_accepted_model(page)
- return_list = []
- for data in res:
- # print 'ddd:: %s' %data
- pan_id = data['kyc']['pan_card_details']
- aadhar_id = data['kyc']['aadhar_card_details']
- if pan_id and aadhar_id:
- pan_card_details = ast.literal_eval(bucket.get_key(pan_id).get_contents_as_string())
- aadhar_card_details = ast.literal_eval(bucket.get_key(aadhar_id).get_contents_as_string())
- # print '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ %s,%s,%s,%s' %(pan_id,aadhar_id,pan_card_details,aadhar_card_details)
- get_user_details = user_kyc_details_model(0, **{"email": email})
- return_list.append({'user_details': get_user_details, 'kyc': {'pan_card_details': pan_card_details,
- 'aadhar_card_details': aadhar_card_details},
- 'email': data['email']})
- # return_list.append(data['email'])
- return JsonResponse({'code': 200, 'kyc_list': return_list, "total_accepted": count})
- else:
- return JsonResponse({'code': 401, 'token_match': False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def display_rejected(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- page = data['page']
- res, count = show_rejected_model(page)
- return_list = []
- for data in res:
- # print 'ddd:: %s' %data
- pan_id = data['kyc']['pan_card_details']
- aadhar_id = data['kyc']['aadhar_card_details']
- pan_card_details = ast.literal_eval(bucket.get_key(pan_id).get_contents_as_string())
- aadhar_card_details = ast.literal_eval(bucket.get_key(aadhar_id).get_contents_as_string())
- get_user_details = user_kyc_details_model(0, **{"email": email})
- return_list.append({'user_details': get_user_details, 'kyc': {'pan_card_details': pan_card_details,
- 'aadhar_card_details': aadhar_card_details},
- 'email': data['email']})
- # return_list.append({'kyc':data['kyc'],'email':data['email']})
- # return_list.append(data['email'])
- return JsonResponse({'code': 200, 'kyc_list': return_list, "total_rejected_data": count})
- else:
- return JsonResponse({'code': 401, 'token_match': False})
- '''{
- "token":"asdfasdf",
- "admin_email":asdf
- "user_email":asdf
- }'''
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def show_single_kyc(request):
- data = json.loads(request.body)
- admin_email = data['admin_email']
- uuid_flag = 1
- if uuid_flag == 1:
- user_email = data['user_email']
- res = show_single_kyc_model(user_email)
- return_list = []
- for data in res:
- pan_id = data['kyc']['pan_card_details']
- aadhar_id = data['kyc']['aadhar_card_details']
- pan_card_details = ast.literal_eval(bucket.get_key(pan_id).get_contents_as_string())
- aadhar_card_details = ast.literal_eval(bucket.get_key(aadhar_id).get_contents_as_string())
- get_user_details = user_kyc_details_model(0, **{"email": user_email})
- return_list.append({'user_details': get_user_details, 'kyc': {'pan_card_details': pan_card_details,
- 'aadhar_card_details': aadhar_card_details},
- 'email': data['email']})
- return JsonResponse({'code': 200, 'kyc_list': return_list})
- # return JsonResponse({'kyc':{'pan_card_details':pan_card_details,'aadhar_card_details':aadhar_card_details},'email':data['email'],'code':200})
- else:
- return JsonResponse({'code': 500, 'response': 'uuid_failed_to_verify'})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def bank_transfer(request):
- if request.method == "POST":
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- method = data['deposit_method']
- amount_deposited = data['amount_deposited']
- bank_name = data['bank']
- trans_id = data['trans_id']
- admin_amount = data['admin_amount']
- date_time = data['date_time']
- transaction_list = {"payment_method": method, "amount_deposited": amount_deposited, "bank_name": bank_name,
- "trans_id": trans_id, "admin_amount": admin_amount, "date_time": date_time}
- bank_transfer_model(transaction_list)
- return JsonResponse({"code": 200, "status": 'success'})
- else:
- return JsonResponse({'code': 401, 'token_match': False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def bank_detail(request): ##this is for super users
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- bank_name = data['bank_name'] if data['bank_name'] else False
- account_holder_name = data['account_holder_name'] if data['account_holder_name'] else False
- ifsc = data['ifsc'] if data['ifsc'] else False
- account_no = data['account_no'] if data['account_no'] else False
- account_type = data['account_type'] if data['account_type'] else False
- bank_type = data["bank_type"] if data["bank_type"] else False
- swift_code = data["swift_code"] if data["swift_code"] else False
- iban_number = data["iban_number"] if data["iban_number"] else False
- bank_details = {"iban_number": iban_number, "swift_code": swift_code, "bank_type": bank_type,
- "bank_name": bank_name, "account_holder_name": account_holder_name, "ifsc": ifsc,
- "account_no": account_no, "account_type": account_type}
- bank_detail_model(bank_details)
- return JsonResponse({"code": 200, "status": 'success'})
- else:
- return JsonResponse({'code': 400, 'token_match': False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def fetch_bank_detail(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- db_resp = fetch_bank_detail_model()
- if db_resp:
- return JsonResponse({"code": 200, "bank_detail": db_resp})
- else:
- return JsonResponse({"code": 400, "status": "failure"})
- else:
- return JsonResponse({"code": 400, "message": "verification failed"})
- # @csrf_exempt
- # def rate_conversion(request): #udashi
- # if request.method =='POST':
- # data = json.loads(request.body)
- # btc_eqval = data['btc']
- # eth_eqval = data['eth']
- # fiat_eqval = data['fiat']
- # # token = data['token']
- # timestamp = int(time.time())
- # i=0
- # while i < 3:
- # if i == 0:
- # curr = "btc"
- # val = btc_eqval
- # elif i == 1:
- # curr = "eth"
- # val = eth_eqval
- # else:
- # curr = "fiat"
- # val = fiat_eqval
- # input_json = {"currency":curr,"value":val,"from_timestamp":timestamp,"current":True}
- # rate_conversion_model(input_json)
- # i += 1
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def set_default_rate(request):
- print 'setting default rate:::: '
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- default_btc = float(data['default_btc'])
- default_eth = float(data['default_eth'])
- default_fiat = float(data['default_fiat'])
- default_min_cap = float(data['default_min_cap'])
- default_max_cap = float(data['default_max_cap'])
- res = insert_default_rate(default_btc, default_eth, default_fiat)
- res = set_default_cap_model(default_min_cap, default_max_cap)
- return JsonResponse({'success': True})
- else:
- return JsonResponse({'code': 401, 'token_match': False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def update_default_rate(request):
- print 'updating default rate:::: '
- data = json.loads(request.body)
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- default_btc = float(data['default_btc'])
- default_eth = float(data['default_eth'])
- default_fiat = float(data['default_fiat'])
- default_min_cap = float(data['default_min_cap'])
- default_max_cap = float(data['default_max_cap'])
- res = update_default_rate_model(default_btc, default_eth, default_fiat)
- res = update_default_cap_model(default_min_cap, default_max_cap)
- return JsonResponse({'success': True})
- else:
- return JsonResponse({'code': 401, 'token_match': False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def set_rate(request):
- print 'setting rate:::: '
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- from_date = data['from_date']
- to_date = data['to_date']
- btc_value = data['btc_value']
- eth_value = data['eth_value']
- fiat_value = data['fiat_value']
- min_cap = data['min_fiat_amount']
- max_cap = data['max_fiat_amount']
- res = insert_set_rate_model(from_date, to_date, btc_value, eth_value, fiat_value)
- res1 = set_cap_model(from_date, to_date, min_cap, max_cap)
- return JsonResponse({'success': True})
- else:
- return JsonResponse({'code': 401, 'token_match': False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def return_rates(request):
- print 'return rates:::: '
- req_data = json.loads(request.body)
- email = req_data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- default_rates_list = []
- rates_list = []
- # default_caps_list = []
- # caps_list = []
- default_rates = get_default_rates()
- default_caps = get_default_caps()
- if default_rates is None:
- return JsonResponse({'error': 'default_rates_is_not_set'})
- default_dict = {
- 'btc': default_rates['default_btc'],
- 'eth': default_rates['default_eth'],
- 'fiat': default_rates['default_fiat'],
- 'min_cap': default_caps['default_min_cap'],
- 'max_cap': default_caps['default_max_cap']
- }
- default_rates_list.append(default_dict)
- rates = get_rates()
- for data in rates:
- append_dict = {
- 'id': str(data['_id']),
- 'from_date': data['from_date'],
- 'to_date': data['to_date'],
- 'btc': data['btc'],
- 'eth': data['eth'],
- 'fiat': data['fiat']
- }
- rates_list.append(append_dict)
- caps_list = []
- caps = get_caps()
- for data in caps:
- append_dict = {
- 'id': str(data['_id']),
- 'from_date': data['from_date'],
- 'to_date': data['to_date'],
- 'min_cap': data['min_cap'],
- 'max_cap': data['max_cap']
- }
- caps_list.append(append_dict)
- return JsonResponse({'default_list': default_rates_list, 'rates_list': rates_list, 'caps_list': caps_list})
- else:
- return JsonResponse({'code': 401, 'token_match': False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def delete_rates(request):
- data = json.loads(request.body)
- _id = data['_id']
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- res = remove_rate_model(_id)
- return JsonResponse({'success': True})
- else:
- return JsonResponse({'code': 401, 'token_match': False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def update_rates(request):
- data = json.loads(request.body)
- _id = data['_id']
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- update_dict = {}
- if 'new_from_date' in data:
- update_dict['from_date'] = data['new_from_date']
- if 'new_to_date' in data:
- update_dict['to_date'] = data['new_to_date']
- if 'new_btc' in data:
- update_dict['btc'] = data['new_btc']
- if 'new_eth' in data:
- update_dict['eth'] = data['new_eth']
- if 'new_fiat' in data:
- update_dict['fiat'] = data['new_fiat']
- res = update_rates_model(_id, update_dict)
- min_cap = data['min_fiat_amount']
- max_cap = data['max_fiat_amount']
- res1 = set_cap_model(min_cap, max_cap)
- return JsonResponse({'success': True})
- else:
- return JsonResponse({'code': 401, 'token_match': False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def set_cap(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- min_cap = data['min_fiat_amount']
- max_cap = data['max_fiat_amount']
- from_date = data['from_date']
- to_date = data['to_date']
- res = set_cap_model(from_date, to_date, min_cap, max_cap)
- return JsonResponse({'success': True})
- else:
- return JsonResponse({'code': 401, 'token_match': False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def update_cap(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- min_cap = data['min_fiat_amount']
- max_cap = data['max_fiat_amount']
- res = update_cap_model(min_cap, max_cap)
- return JsonResponse({'success': True})
- else:
- return JsonResponse({'code': 401, 'token_match': False})
- # @csrf_exempt
- # def validate_token_amount(request):
- # data = json.loads(request.body)
- # token_amount = data['token_amount']
- # email = data['email']
- # unique_id = data['token']
- # uuid_flag = uuid_verification(unique_id,email)
- # if uuid_flag == 1:
- # currency = data['currency']
- # fiat_rate = get_price(token_amount,currency)[1]
- # # return JsonResponse({'valid':True})
- # print 'ffff %s' %fiat_rate
- # if fiat_rate >= 20:
- # return JsonResponse({'valid':True})
- # else:
- # return JsonResponse({'valid':False})
- # else:
- # return JsonResponse({"code":401,"token_match":False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def validate_fiat_amount(request):
- data = json.loads(request.body)
- email = data['email']
- fiat_amount = data['fiat_amount']
- uuid_flag = 1
- if uuid_flag == 1:
- min_cap, max_cap = get_cap(int(time.time()))
- if fiat_amount >= min_cap and fiat_amount <= max_cap:
- return JsonResponse({'valid': True})
- else:
- return JsonResponse({'valid': False})
- else:
- return JsonResponse({'code': 401, 'token_match': False})
- def send_zero_confirmation_mail(email, value, currency, txid, exchange_rate):
- m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
- data = { "id" : 39,
- "to" : {email: email},
- "replyto" : "support@auxledger.org",
- "attr" : {"value": str(value), "currency": currency, "txid": txid, "exchange_rate": str(exchange_rate)},
- "headers" : {"Content-Type": "text/html;charset=iso-8859-1"}
- }
- result = m.send_transactional_template(data)
- print result
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def set_btc_refund_address(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- refund_btc_address = data['refund_btc_address']
- btc_address_validation = validate_btc_address(refund_btc_address)
- if btc_address_validation is False:
- return JsonResponse({'code': 401, 'address_validation': False})
- res = set_btc_refund_address_model(email, refund_btc_address)
- return JsonResponse({'code': 200, 'address_validation': True})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def set_btc_eth_refund_address(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- refund_btc_address = data['refund_btc_address']
- btc_address_validation = validate_btc_address(refund_btc_address)
- if btc_address_validation is False:
- return JsonResponse({'code': 400, 'btc_address_validation': False})
- res = set_btc_refund_address_model(email, refund_btc_address)
- refund_eth_address = data['refund_eth_address']
- eth_address_validation = validate_eth_address(refund_eth_address)
- if eth_address_validation is False:
- return JsonResponse({'code': 400, 'eth_address_validation': False})
- res = set_eth_refund_address_model(email, refund_eth_address)
- return JsonResponse({'code': 200, 'address_validation': True})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def set_eth_refund_address(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- refund_eth_address = data['refund_eth_address']
- eth_address_validation = validate_eth_address(refund_eth_address)
- if eth_address_validation is False:
- return JsonResponse({'code': 401, 'address_validation': False})
- res = set_eth_refund_address_model(email, refund_eth_address)
- return JsonResponse({'code': 200, 'address_validation': True})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- # @TokenValidatorMiddleware
- # @JWTMiddleware
- def get_confirmed_transactions(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- send_list = []
- res = get_confirmed_transaction_details()
- for data in res:
- send_list.append(data)
- return JsonResponse(
- {"code": 200, 'transaction_list': send_list, 'btc_usd': get_btc_to_usd(), 'eth_usd': get_eth_to_usd()})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- def get_total_tokens_sold(request):
- res = get_confirmed_transaction_details()
- sold_tokens = 0.0
- for data in res:
- if data.__contains__('no_of_tokens'):
- sold_tokens += float(data['no_of_tokens'])
- # current_rate = get_current_rate(sold_tokens)
- # sold_tokens = 21312
- return JsonResponse({'sold_tokens': round(sold_tokens,3)})
- '''
- ip:
- {
- "unique_id":"token",
- "from":"from_date", #epoch_format
- "to":"to-date",# #epoch_format
- "type":"detail/summary"
- }
- op:
- [{ "currency" : "usd", "email" : "parishilanrayamajhi@gmail.com", "epoch" : "1526807413", "no_of_tokens" : "23", "txid" : "sssssssssssssssss", "value" : "45" },{},{}]
- '''
- '''
- {
- "btc_value":512,
- "eth-value"4545,
- "btc_usd_eq":121,
- "btc_eth_eq":121,
- "cas_token":112
- }
- '''
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def graph_tokens_sold(request):
- try:
- data = json.loads(request.body)
- # print data
- # email = data['email']
- # unique_id = data['token']
- # uuid_flag = uuid_verification(unique_id,email)
- uuid_flag = 1
- if uuid_flag == 1:
- from_date = int(data["from"])
- to_date = int(data["to"])
- to_date += 86399
- res = get_confirmed_transaction_details_graph(from_date, to_date)
- for data in res:
- print data
- except Exception as e:
- exc_type, exc_obj, exc_tb = sys.exc_info()
- fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
- print(exc_type, fname, exc_tb.tb_lineno, e.message)
- return JsonResponse({"status_code": 400, "reach": "exception"})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def get_data_from_to_date(request):
- if request.method == "POST":
- try:
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- from_date = int(data["from"])
- to_date = int(data["to"])
- to_date += 86399
- type_ = data["type"] if data["type"] else "NA"
- if type_ == "detail":
- data = get_detail_data_from_to_date_model(from_date, to_date)
- # print data
- return JsonResponse({"detail_report": data, "code": 200})
- elif type_ == "summary":
- url = "https://api.coinmarketcap.com/v2/ticker/?convert=BTC&limit=5"
- resp = (requests.get(url)).json()
- btc_usd_rate = float(resp["data"]["1"]["quotes"]["USD"]["price"])
- eth_usd_rate = float(resp["data"]["1027"]["quotes"]["USD"]["price"])
- btc_value, eth_value, cas_token = get_summary_data_from_to_date_model(from_date, to_date)
- btc_usd_value = btc_usd_rate * btc_value
- eth_usd_value = eth_usd_rate * eth_value
- ret_json = {}
- ret_json["btc_value"] = btc_value
- ret_json["eth_value"] = eth_value
- ret_json["btc_usd_eq"] = btc_usd_value
- ret_json["btc_eth_eq"] = eth_usd_value
- ret_json["cas_token"] = cas_token
- return JsonResponse({"data": ret_json, "code": 200})
- else:
- return JsonResponse({"type": "not defined", "status": 500})
- else:
- return JsonResponse({"uuid_verification": "false"})
- except Exception as e:
- exc_type, exc_obj, exc_tb = sys.exc_info()
- fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
- print(exc_type, fname, exc_tb.tb_lineno, e.message)
- return JsonResponse({"status_code": 400, "reach": "exception"})
- else:
- return JsonResponse({"status": "bad_request"})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def init_withdraw(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- currency = data['currency']
- if currency == 'btc':
- pending_amount = get_pending_amount(email, 'btc')
- refund_address = get_refund_address_using_mail(email, 'btc')
- # fee = calculate_btc_fee(btc_withdraw_address,refund_address,pending_amount)[0]
- # fee = 0.0001
- fee = 0.00040335
- if fee is None:
- return JsonResponse({'code': 400, 'error': 'unable_to_calculate_fee'})
- # return JsonResponse({'code':400,'error':'withdrawal_closed'})
- amount_to_be_paid = pending_amount - fee
- else:
- pending_amount = get_pending_amount(email, 'eth')
- refund_address = get_refund_address_using_mail(email, 'eth')
- eth_fee_res = requests.get(eth_fee_url)
- fee = 0.0005
- # if eth_fee_res.status_code == 200:
- # fee = json.loads(eth_fee_res)['msg']['transaction_fee']
- amount_to_be_paid = pending_amount - fee
- # else:
- # return JsonResponse({'code':400,'error':'unable_to_calculate_fee'})
- send_dict = {
- 'pending_amount': pending_amount,
- 'withdraw_address': refund_address,
- 'fee': fee,
- 'amount_to_be_paid': amount_to_be_paid
- }
- return JsonResponse({'code': 200, 'data': send_dict})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def send_withdraw_otp(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- res = get_otp_str(email, True)
- if not res:
- otp = str(randint(111111, 999999))
- m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
- print 'sending mail to admin::: '
- email_dict = {
- "to": {email: email},
- "from": ["support@auxledger.org"],
- "subject": "OTP for Referral Earned Funds Withdrawal | Auxledger ",
- "html": get_send_withdraw_otp_html(str(otp))
- }
- result = m.send_email(email_dict)
- print 'res::: %s' % result
- if result['code'] == "success":
- otp_session('withdraw_' + email, otp)
- # print 'mail sent response ::::::: %s' % result
- return JsonResponse({"code": 200, 'success': 'mail sent'})
- else:
- return JsonResponse({"code": 200, 'success': 'mail sent'})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- def send_request_for_withdraw_apprroval_mail(email, res1, pending_amount, refund_address, currency):
- m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
- email_dict = {
- "to": {email: email},
- "from": ["support@auxledger.org"],
- "subject": "Referral Earned Funds Withdrawal Request Created | Team Auxledger", # Withdraw referral amount OTP
- "html": get_send_request_for_withdraw_apprroval_mail_html(str(res1), str(round(float(pending_amount), 6)),
- str(refund_address), currency)
- }
- result = m.send_email(email_dict)
- return result
- def send_withdraw_confirm_mail(email, txid, earned_amount, refund_address, currency):
- m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
- email_dict = {
- "to": {email: email},
- "from": ["support@auxledger.org"],
- "subject": "Successful Referral Earned Funds Withdrawal | Auxledger ", # Withdraw referral amount OTP
- "html": get_send_withdraw_confirm_mail_html(txid, earned_amount, refund_address, currency)
- }
- result = m.send_email(email_dict)
- return result
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def confirm_withdraw(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- input_otp = data['otp']
- otp_flag = otp_verification('withdraw_' + email, str(input_otp))
- print 'pppp %s,%s,%s' % (input_otp, type(input_otp), otp_flag)
- if otp_flag == 1:
- currency = data['currency']
- pending_amount = get_pending_amount(email, currency)
- res = get_docs_to_spend(email, currency)
- refund_address = get_refund_address_using_mail(email, currency)
- ref_id = get_ref_id(email)
- res1 = insert_into_admin(email, refund_address, currency, pending_amount, ref_id)
- update_spent_flag(res)
- if currency == 'btc':
- result = send_request_for_withdraw_apprroval_mail(email, str(res1), pending_amount, refund_address,
- ' BTC')
- else:
- result = send_request_for_withdraw_apprroval_mail(email, str(res1), pending_amount, refund_address,
- ' ETH')
- # if result['code'] == 'success'
- return JsonResponse({'code': 200, 'msg': 'sent_for_approval'})
- else:
- return JsonResponse({"code": 400, "error": 'otp_mismatch'})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def approve_withdrawal(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- _id = data['_id']
- withdraw_details = get_withdraw_details_from_admin_model(_id)
- currency = withdraw_details['currency']
- refund_address = withdraw_details['refund_address']
- pending_amount = withdraw_details['pending']
- user_email = withdraw_details['email']
- if currency == 'btc':
- fee, btc_bal = calculate_btc_fee(btc_withdraw_address, refund_address, pending_amount)
- print 'btc bal:::,btc fe::: %s,%s,%s' % (btc_bal, fee, pending_amount)
- txid = do_btc_transaction(pending_amount, fee, btc_bal, refund_address)
- if txid is not None:
- update_flag_in_admin_withdrawal(_id, txid)
- send_withdraw_confirm_mail(user_email, txid, pending_amount - fee, refund_address, ' BTC')
- return JsonResponse({'code': 200, 'success': True, 'txid': txid})
- else:
- return JsonResponse({'code': 400, 'error': 'transaction_failed'})
- else:
- eth_fee_res = requests.get(eth_fee_url)
- if eth_fee_res.status_code == 200:
- # fee = json.loads(eth_fee_res)['msg']['transaction_fee']
- fee = 0.0005
- txid = do_eth_transaction(refund_address, pending_amount, fee)
- if txid is not None:
- update_flag_in_admin_withdrawal(_id, txid)
- send_withdraw_confirm_mail(user_email, txid, pending_amount - fee, refund_address, ' ETH')
- return JsonResponse({'code': 200, 'success': True, 'txid': txid})
- else:
- return JsonResponse({'code': 400, 'error': 'transaction_failed'})
- else:
- # eth_refund_dict = {
- # 'from_address':eth_withdraw_address,
- # 'refund_address':refund_address,
- # 'amount_to_refund':pending_amount,
- # 'timestamp':int(time.time()),
- # 'refund_type':'eth_withdraw',
- # 'currency':'eth'
- # }
- # insert_unsuccessful_eth_refund(eth_refund_dict)
- return JsonResponse({'code': 400, 'error': 'transaction_failed'})
- else:
- return JsonResponse({'code': 401, 'token_match': False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def otp_for_admin(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- send_list = get_otp_for_admin_model()
- return JsonResponse({'code': 200, 'list': send_list})
- else:
- return JsonResponse({'code': 401, 'token_match': False})
- def do_eth_transaction(to_address, amount, fee):
- from_address = eth_withdraw_address
- print 'refunding etherr from address::: %s, to address:: %s, amount::: %s, fee::: %s' % (
- from_address, to_address, amount, fee)
- timestamp = str(int(time.time()))
- # signature = calculate_signature('token_baazar_staging','abcd',timestamp)
- eth_send_dict = {
- # 'user':eth_user,
- # 'token':eth_token,
- 'from_address': from_address,
- 'to_address': to_address,
- 'ethers': float(amount),
- # 'timestamp':timestamp,
- # 'signature':signature
- }
- eth_forward_res = requests.post(forward_eth_url, data=eth_send_dict)
- print 'eth_forward_res::: %s' % eth_forward_res.text
- if eth_forward_res.status_code == 200:
- eth_transaction_details = json.loads(eth_forward_res.text)
- if eth_transaction_details['code'] == 200:
- print 'status code:: 200, eth transaction successful'
- txid = eth_transaction_details['msg']['transaction_hash']
- eth_refund_dict = {
- 'from_address': from_address,
- 'refund_address': to_address,
- 'txid': txid,
- 'transaction_fee': fee,
- 'amount_refunded': float(amount) - float(fee),
- 'timestamp': int(time.time()),
- 'refund_type': 'eth_withdraw',
- 'currency': 'eth'
- }
- insert_successful_eth_refund(eth_refund_dict)
- return txid
- else:
- print 'status not 200::: eth transaction unsuccessful %s' % eth_forward_res.text
- eth_refund_dict = {
- 'from_address': from_address,
- 'refund_address': to_address,
- 'amount_to_refund': amount,
- 'timestamp': int(time.time()),
- 'refund_type': 'eth_withdraw',
- 'currency': 'eth'
- }
- insert_unsuccessful_eth_refund(eth_refund_dict)
- return None
- else:
- print 'eth_auxpay error::: '
- eth_refund_dict = {
- 'from_address': from_address,
- 'refund_address': to_address,
- 'amount_to_refund': amount,
- 'timestamp': int(time.time()),
- 'refund_type': 'eth_withdraw',
- 'currency': 'eth'
- }
- insert_unsuccessful_eth_refund(eth_refund_dict)
- return None
- def do_btc_transaction(refund_amount, btc_fee, btc_bal, btc_refund_address):
- # def refund_btc(address,btc_refund_address,refund_amount,btc_fee,btc_bal,refund_type):
- amount_to_refund = refund_amount - btc_fee
- address = btc_withdraw_address
- print 'amount to refud::: %s,fee: %s, refund_amount:: %s,btc bal:: %s' % (
- amount_to_refund, btc_fee, refund_amount, btc_bal)
- send_dict = {
- 'user_name': auxpay_user,
- 'token': auxpay_token,
- 'transactions': {
- 'input_address': [address],
- 'output_address': {
- btc_refund_address: round(amount_to_refund, 8),
- address: round(btc_bal - refund_amount, 8)
- }
- },
- # 'change_flag': False
- }
- print 'json sent %s to url %s' % (send_dict, forward_btc_url)
- forward_btc_res = requests.post(forward_btc_url, data=json.dumps(send_dict))
- if forward_btc_res.status_code == 200:
- txid = json.loads(forward_btc_res.text)['new_txid']
- print 'update db after refund:::: '
- btc_refund_dict = {
- 'from_address': address,
- 'refund_address': btc_refund_address,
- 'txid': txid,
- 'transaction_fee': btc_fee,
- 'amount_refunded': amount_to_refund,
- 'timestamp': int(time.time()),
- 'refund_type': 'btc_withdraw',
- 'currency': 'btc'
- }
- insert_successful_btc_refund(btc_refund_dict)
- return txid
- else:
- print 'err::: %s' % forward_btc_res.text
- btc_refund_dict = {
- 'from_address': address,
- 'refund_address': btc_refund_address,
- 'amount_to_refund': refund_amount,
- 'timestamp': int(time.time()),
- 'refund_type': 'btc_withdraw',
- 'currency': 'btc'
- }
- insert_unsuccessful_btc_refund(btc_refund_dict)
- return None
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def get_referral_details(request):
- print 'get_referral_details hitted:::: '
- data = json.loads(request.body)
- print data
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- ref_id = get_ref_id(email)
- print 'ref_id::: %s' % ref_id
- eth_refund_address = get_refund_address_using_mail(email, 'eth')
- btc_refund_address = get_refund_address_using_mail(email, 'btc')
- send_dict = dict()
- send_dict['ref_id'] = ref_id
- send_dict['eth_refund_address'] = eth_refund_address
- send_dict['btc_refund_address'] = btc_refund_address
- res = get_referral_list_model(ref_id)
- referral_list = []
- for data in res:
- tmp_dict = dict()
- tmp_dict['name'] = data['name']
- tmp_dict['degree'] = data['height']
- if data['currency'] == 'btc':
- tmp_dict['amount_in_btc'] = round(data['bonus_amount'], 6)
- tmp_dict['amount_in_eth'] = 0
- else:
- tmp_dict['amount_in_btc'] = 0
- tmp_dict['amount_in_eth'] = data['bonus_amount']
- referral_list.append(tmp_dict)
- child_details = get_child_details(ref_id)
- send_dict['child_details'] = child_details
- send_dict['referral_details_list'] = referral_list
- withdrawn_btc, pending_btc, withdrawn_eth, pending_eth = get_withdraw_details_model(ref_id)
- send_dict['withdrawn_btc'] = withdrawn_btc
- send_dict['pending_btc'] = pending_btc
- send_dict['earned_btc'] = withdrawn_btc + pending_btc
- send_dict['withdrawn_eth'] = withdrawn_eth
- send_dict['pending_eth'] = pending_eth
- send_dict['earned_eth'] = withdrawn_eth + pending_eth
- total_xal_earned, db_data = total_xal_earned_via_referial(email)
- return JsonResponse(
- {'code': 200, 'referral_json': send_dict, 'total_xal_earned': total_xal_earned, 'total_data': db_data})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- def get_child_details(ref_id):
- try:
- i = 0
- parents = [ref_id]
- tree_arr = []
- while i < 10:
- children = []
- name_list = []
- res = get_details_from_ref_tree(parents)
- for data in res:
- if len(data['child']) > 0:
- children += data['child']
- name = get_name(data['child'])
- for ind_name in name:
- if ind_name not in name_list:
- name_list.append(ind_name)
- else:
- print '-'
- if len(name_list) > 0:
- mn = list(set(name_list))
- tmp_dict = {str(i + 1): mn}
- if tmp_dict not in tree_arr:
- tree_arr.append(tmp_dict)
- i += 1
- parents = children
- return tree_arr
- except Exception as e:
- print "error in get_chid_details model %s" %e
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def token(request):
- if request.method == "POST":
- sold = model_token()
- data = json.loads(request.body)
- total_token = data['total']
- available = total_token - sold
- return JsonResponse({"sold_token": sold, "available_token": available})
- def validate_eth_address(eth_address_input):
- # eth_address_input = str(eth_address_input)
- # hex_eth_address = str.lower(eth_address_input)
- # if len(eth_address_input) == 42:
- # prefix = hex_eth_address[0:2]
- # if prefix == '0x':
- # eth_address = hex_eth_address[3:len(hex_eth_address)]
- # try:
- # int(eth_address,16)
- # return True
- # except ValueError:
- # return False
- # else:
- # return False
- # else:
- # return False
- eth_address_validator_url = "https://api.blockcypher.com/v1/eth/main/addrs/" + eth_address_input
- resp = requests.get(eth_address_validator_url)
- if resp.status_code == 200:
- return True
- else:
- return False
- def validate_btc_address(address):
- btc_address_validator_url = "https://blockexplorer.com/api/addr/" + address + "?noTxList=1&noCache=1"
- resp = requests.get(btc_address_validator_url)
- if resp.status_code == 200:
- return True
- else:
- return False
- # helpdesk start
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def add_category(request):
- print 'adding category::: '
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- category = data['category']
- res = add_category_model(category)
- return JsonResponse({'code': 200})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def update_category(request):
- print 'updating category::: '
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- new_category = data['new_category']
- _id = data['_id']
- res = update_category_model(new_category, _id)
- return JsonResponse({'code': 200})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def delete_category(request):
- print 'deleting category::: '
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- _id = data['_id']
- res = delete_category_model(_id)
- return JsonResponse({'code': 200})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- # @TokenValidatorMiddleware
- # @JWTMiddleware
- def display_category(request):
- print 'display category::: '
- data = json.loads(request.body)
- uuid_flag = 1
- if uuid_flag == 1:
- list_to_send = []
- res = display_category_model()
- for data in res:
- # print data
- data['_id'] = str(data['_id'])
- list_to_send.append(data)
- print list_to_send
- return JsonResponse({'code': 200, 'categories_list': list_to_send})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def raise_ticket(request):
- print 'raising ticket------------------------------->:::'
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- issue_category = data['issue_category']
- subject = data['subject']
- if data.__contains__('phone'):
- phone = data['phone']
- else:
- phone = 'NA'
- description = data['description']
- if len(subject) > 100 or len(description) > 1000:
- return JsonResponse({"code": 401, "error": "message_too_long"})
- support_email = get_admin_email_model()
- res = raise_ticket_model(email, issue_category, cgi.escape(subject), phone, cgi.escape(description))
- send_ticket_raise_mail(email, support_email, str(res), subject, description, )
- return JsonResponse({'code': 200, 'ticket_no': str(res)})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def display_tickets_to_user(request):
- print 'display tickets to user:::'
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- res = display_ticket_to_user_model(email)
- h = HTMLParser()
- user_tickets_list = []
- for details in res:
- print details
- details['_id'] = str(details['_id'])
- details['description'] = h.unescape(details['description'])
- details['subject'] = h.unescape(details['subject'])
- user_tickets_list.append(details)
- return JsonResponse({'code': 200, 'user_tickets_list': user_tickets_list})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- # @TokenValidatorMiddleware
- # @JWTMiddleware
- def display_tickets_to_admin(request):
- print 'display tickets to admin:::'
- data = json.loads(request.body)
- email = data['email']
- res = display_ticket_to_admin_model()
- if res:
- h = HTMLParser()
- tickets_list = []
- print "111111111111111111111111111"
- for data in res:
- print "-----9999999999--------------"
- print data
- data['email'] = str(data['email'])
- data['name'] = get_user_name(data['email'])
- data['_id'] = str(data['_id'])
- data['description'] = h.unescape(data['description'])
- data['subject'] = h.unescape(data['subject'])
- print data
- tickets_list.append(data)
- return JsonResponse({'code': 200, 'tickets_list': tickets_list})
- else:
- return JsonResponse({"code": 401, "msg": "Error"})
- @csrf_exempt
- # @TokenValidatorMiddleware
- # @JWTMiddleware
- def close_ticket(request):
- print 'closing ticket:::'
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- _id = data['_id']
- res = close_ticket_model(_id)
- user_email = res['email']
- send_ticket_close_email(user_email, _id)
- return JsonResponse({'code': 200})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def reopen_ticket(request):
- print 'closing ticket:::'
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- _id = data['_id']
- res = reopen_ticket_model(_id)
- user_email = res['email']
- description = res['description']
- subject = res['subject']
- support_email = get_admin_email_model()
- send_ticket_reopen_email(user_email, support_email, _id, subject, description)
- return JsonResponse({'code': 200})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- def send_ticket_raise_mail(user_email, support_email, ticket_no, subject, description):
- m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
- print 'sending mail to admin::: '
- email_dict = {
- "to": {support_email: support_email},
- "from": ["support@auxledger.org"],
- "replyto": [user_email, user_email],
- "subject": "New Support Ticket ID " + ticket_no + " Raised",
- "html": "A new support ticket is created with support number " + ticket_no + "<br>Subject: " + subject + "<br>Message: " + description + "<br>Please reply to this mail and connect with the user directly."
- }
- result = m.send_email(email_dict)
- def send_ticket_close_email(email, ticket_no):
- m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
- data = { "id" : 50,
- "to" : {email: email},
- "replyto" : "support@auxledger.org",
- "attr" : {"ticket_no": str(ticket_no)},
- "headers" : {"Content-Type": "text/html;charset=iso-8859-1"}
- }
- result = m.send_transactional_template(data)
- def send_ticket_response_email(email, ticket_no,message):
- m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
- print 'sending mail to admin::: '
- data = { "id" : 51,
- "to" : {email: email},
- "replyto" : "support@auxledger.org",
- "attr" : {"ticket_no": str(ticket_no),"reply": str(message)},
- "headers" : {"Content-Type": "text/html;charset=iso-8859-1"}
- }
- result = m.send_transactional_template(data)
- def send_ticket_reopen_email(user_email, support_email, ticket_no, subject, description):
- m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
- print 'sending mail to admin::: '
- email_dict = {
- "to": {support_email: support_email},
- "from": ["support@auxledger.org"],
- "replyto": [user_email, user_email],
- "subject": "Support Ticket ID " + ticket_no + " is Reopened",
- "html": "Subject: " + subject + "<br>Message: " + description + "<br>Please reply to this mail and connect with the user directly."
- }
- result = m.send_email(email_dict)
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def set_support_email(request):
- print 'setting support email:::'
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- admin_email = data['admin_email']
- res = set_admin_email_model(admin_email)
- return JsonResponse({'code': 200, 'success': True})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- # @TokenValidatorMiddleware
- # @JWTMiddleware
- def get_support_email(request):
- print 'getting support email:::'
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- admin_email = get_admin_email_model()
- return JsonResponse({'code': 200, 'admin_email': admin_email})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def send_user_message(request):
- print 'send user msg:::'
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- message = data['message']
- if len(message) > 1000:
- return JsonResponse({"code": 401, "error": "message_too_long"})
- ticket_no = data['_id']
- res = insert_user_message_model(cgi.escape(message), ticket_no)
- support_email = get_admin_email_model()
- send_user_reply_email(support_email, message,ticket_no)
- return JsonResponse({'code': 200, 'success': True})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- # db_conn.tickets.update({"_id":ObjectId(ticket_no)},{"$set":{"chat_status":"admin_answered","last_modified":int(time.time())}})
- @csrf_exempt
- # @TokenValidatorMiddleware
- # @JWTMiddleware
- def send_admin_message(request):
- print 'send admin msg:::'
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- message = data['message']
- if len(message) > 1000:
- return JsonResponse({"code": 401, "error": "message_too_long"})
- ticket_no = data['_id']
- res = insert_admin_message_model(cgi.escape(message), ticket_no)
- user_email = get_email_from_obj_id(ticket_no)
- send_ticket_response_email(user_email,ticket_no,message)
- return JsonResponse({'code': 200, 'success': True})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- def send_user_reply_email(support_email, message,ticket_no):
- m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
- print 'sending mail to admin::: '
- email_dict = {
- "to": {support_email: support_email},
- "from": ["support@auxledger.org"],
- # "replyto": [user_email, user_email],
- "subject": "reply to existing support ticket from user",
- "html": " user reply on ticket no"+str(ticket_no)
- }
- result = m.send_email(email_dict)
- print result
- @csrf_exempt
- # @TokenValidatorMiddleware
- # @JWTMiddleware
- def get_chat_details(request):
- print 'getting chat detailss::: '
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- ticket_no = data['_id']
- chat_details = get_chat_details_model(ticket_no)
- chat_details['_id'] = str(chat_details['_id'])
- print 'vvccc %s' % chat_details
- return JsonResponse({'code': 200, 'chat_details': chat_details})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- # @TokenValidatorMiddleware
- # @JWTMiddleware
- def get_ticket_chat_notifications(request):
- print 'get_ticket_chat_notifications hitted'
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- return JsonResponse({"code": 200, 'data': get_ticket_chat_notifications_model()})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def get_ticket_chat_notifications_from_admin(request):
- print 'get_ticket_chat_notifications hitted'
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- return JsonResponse({"code": 200, 'data': get_ticket_chat_notifications_from_admin_model(email)})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def get_price_from_couch(request):
- print 'getting chat detailss::: '
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- if config.development:
- couch_db_res = requests.get('https://35.176.9.68:6984/current_price_v1/current_price_unique_id/')
- else:
- couch_db_res = requests.get('http://localhost:6984/current_price_v1/current_price_unique_id/')
- return JsonResponse({'code': 200, 'data': couch_db_res.text})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- # @TokenValidatorMiddleware
- # @JWTMiddleware
- def get_rate_conversion(request):
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- res = get_rate_conversion_model()
- return JsonResponse({"data": res, 'code': 200})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def get_latest_transactions_from_couch(request):
- print 'getting chat detailss::: '
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- if config.development:
- couch_db_res = requests.get('https://35.176.9.68:6984/current_price_v1/current_price_unique_id/')
- else:
- couch_db_res = requests.get('http://localhost:6984/current_price_v1/current_price_unique_id/')
- # couch_db_res = requests.get('http://localhost:6984/live_orders_v1/live_order_unique_id/')
- return JsonResponse({'code': 200, 'data': couch_db_res.text})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def set_bank_details_by_admin(request):
- print 'setting bank detailss::: '
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- bank_name = data['bank_name']
- bank_account_number = data['bank_account_number']
- res = insert_bank_details(bank_name, bank_account_number)
- if res:
- return JsonResponse({'code': 400, 'success': False})
- else:
- return JsonResponse({'code': 200, 'success': True})
- else:
- return JsonResponse({"code": 401, "token_match": False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def user_kyc_form_details(request):
- try:
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- insert_data = {}
- if uuid_flag == 1:
- insert_data["email"] = data['email']
- insert_data["first_name"] = data['first_name']
- insert_data["last_name"] = data['last_name']
- insert_data["address_1"] = data['address_1']
- insert_data["address_2"] = data['address_2']
- insert_data["city"] = data['city']
- insert_data["state"] = data['state']
- insert_data["country"] = data['country']
- insert_data["pin_code"] = data['pin_code']
- insert_data["dob"] = data['dob']
- insert_data["gender"] = data['gender']
- print insert_data
- db_resp = user_kyc_details_model(1, **insert_data) # 1 --> insert flag
- if db_resp:
- print "db response %s" % db_resp
- return JsonResponse({'code': 200, 'success': True})
- except:
- return JsonResponse({"code": 400, 'success': False})
- @csrf_exempt
- @TokenValidatorMiddleware
- @JWTMiddleware
- def display_kyc_form_detail(request):
- print "----------display kyc detail----------------"
- data = json.loads(request.body)
- email = data['email']
- uuid_flag = 1
- if uuid_flag == 1:
- get_user_details = user_kyc_details_model(0, **{"email": data["email"]}) # 0 flag to fetch data
- if get_user_details:
- return JsonResponse({"code": 200, "user_details": get_user_details})
- else:
- return JsonResponse({"code": 400, "success": False})
- @csrf_exempt
- def subscribed_email(request):
- data = json.loads(request.body)
- print "data is s----------------------> %s" % data
- email = str(data["mc_email"])
- flag = subscribed_email_model(email)
- if flag == 0:
- return JsonResponse({"code": 200})
- else:
- return JsonResponse({"code": 201})
- @csrf_exempt
- def send_email_from_html(request):
- data = json.loads(request.body)
- user_email = str(data["contact_email"])
- message = str(data["contact_message"])
- name = str(data["contact_name"])
- phn_no = str(data["contact_Mobile"])
- m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
- email = "info@auxledger.org"
- email_dict = {
- "to": {email: email},
- "from": ["support@auxledger.org"],
- "subject": "contact request from " + " " + name + ".auxledger.org",
- "html": "You have recived one new mail <br> <b>Name</b>: " + name + "<br> <b>Email</b> :" + user_email + "<br><b>Phone No</b> " + phn_no + ":<br><b> Message</b> : " + message}
- result = m.send_email(email_dict)
- print result
- return JsonResponse({'code': 200})
- @csrf_exempt
- # @TokenValidatorMiddleware
- # @JWTMiddleware
- def admin_referral_details(requests):
- ref_details,total_tokens = get_admin_referral_details()
- if ref_details:
- return JsonResponse({"code":200,"data":ref_details,"total_referral_earned":total_tokens})
- else:
- return JsonResponse({"code": 400, "msg": "data not found"})
- @csrf_exempt
- def user_detail(requests):
- data = json.load(requests)
- email = data["email"]
- print email
- user_details = user_exists_model(email)
- user_name = user_details['tnc']['name']
- date_registered = user_details['tnc']['time_stamp']
- ref_id = user_details['ref_id']
- if user_details.__contains__('kyc'):
- print "inside kyc"
- kyc_flag = user_details['kyc']['status']
- else:
- print "not kyc"
- kyc_flag = "NA"
- user_timeline_list = []
- tokens = 0.0
- timeline_res = get_user_timeline_model(email)
- for data in timeline_res:
- user_timeline_list.append(data)
- if data.__contains__('tokens_purchased'):
- tokens += float(data['tokens_purchased'])
- if data.__contains__('token_purchased'):
- tokens += float(data['token_purchased'])
- btc_address = get_generated_address(email,"btc")
- eth_address = get_generated_address(email,"eth")
- two_fa_status = check_2fa_status(email)
- send_dict = {
- 'status': 200,
- 'email':email,
- 'btc_address':btc_address,
- 'eth_address':eth_address,
- 'kyc': kyc_flag,
- 'tokens': round(tokens, 3),
- 'user_name': user_name,
- 'two_fa_status': two_fa_status,
- 'ref_id':ref_id,
- 'date_registered':date_registered,
- 'was_referred':False
- }
- referral_details= get_referral_status(ref_id)
- if referral_details['was_referred']:
- send_dict['was_referred'] = True
- send_dict['referred_by'] = referral_details['referred_by']
- return JsonResponse(send_dict)
- # import razorpay
- # client = razorpay.Client(auth=("rzp_test_EDSwYy6TtJ8wOT", "8DAvPokF0PINAlGOryGDC1EO"))
- # client = razorpay.Client(auth=("rzp_live_cvfiP9RLAgfFmN", "7t6QOr7wKXQMpUzy8qNI3CxT"))
- @csrf_exempt
- def capture_payments(request):
- try:
- print "-----------------razaor pay------------"
- data = json.loads(request.body)
- user_email = str(data["email"])
- payment_id = str(data["payment_id"])
- payment_amount = str(data["amount"])
- xal_amount = str(data["xal_amount"])
- currency = "INR"
- type_ = "inr_transfer"
- resp = client.payment.capture(payment_id, payment_amount)
- if resp["captured"]:
- result1 = insert_pay_inr_to_transaction_details(user_email, currency, payment_id,
- float(payment_amount) / 100,
- xal_amount, resp) # check resp.response
- result2 = insert_pay_inr_to_user_timeline(user_email, currency, xal_amount, payment_id, type_,
- float(payment_amount) / 100)
- ref_id, name = get_inr_referral_details_model_fiat(user_email)
- calc_referal_bonus_auxledger(ref_id, float(payment_amount) / 100, name, 'INR', "na", payment_id, user_email)
- send_confirmation_mail(user_email, xal_amount, float(payment_amount) / 100, "INR")
- return JsonResponse({"code": 200})
- except Exception as e:
- print e
- return JsonResponse({"code": 400, 'success': False})
Add Comment
Please, Sign In to add comment