parishilan

ico_with_bid_views.py

Feb 28th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 137.34 KB | None | 0 0
  1. from django.http import HttpResponse, JsonResponse
  2. from django.views.decorators.csrf import csrf_exempt
  3. # from django.conf.urls import url
  4. from middleware import JWTMiddleware, TokenValidatorMiddleware, RequestValidatorMiddleware
  5. from models import *
  6. from wrap_core import *
  7. from html_strings import *
  8.  
  9. import json
  10. import ast
  11. import boto
  12. from boto.s3.key import Key
  13. # import urlparse
  14. # from urllib.parse import urlparse, parse_qs
  15.  
  16. from urlparse import urlparse
  17.  
  18. m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
  19.  
  20. from random import randint
  21. import requests
  22. from mailin import Mailin
  23. import time
  24. import uuid
  25. import hmac
  26. import csv
  27. import cgi
  28. from HTMLParser import HTMLParser
  29. import pyrebase
  30. import config
  31. import base64
  32. import hashlib
  33. import binascii
  34. import random, string
  35. from Crypto.Cipher import AES
  36. import pyotp
  37. import sys, os
  38.  
  39. # import middleware
  40. # from rest_framework_swagger.views import get_swagger_view
  41.  
  42. # schema_view = get_swagger_view(title='Token baazar API')
  43. # urlpatterns = [
  44. # url(r'^$', schema_view)
  45. # ]
  46.  
  47.  
  48. if config.prod is False:
  49. REGION_HOST = 's3.us-east-2.amazonaws.com'
  50. bucket_name = 'bubblo-kyc-data'
  51. else:
  52. REGION_HOST = 's3.eu-west-2.amazonaws.com'
  53. bucket_name = 'otc-data'
  54.  
  55. if config.staging is False:
  56. token_baazar_media_url = '/home/parin/Documents/ico_with_bid/media/'
  57. service_account_json = "/home/parin/Documents/ico_with_bid/media/token baazar-f215172e741e.json"
  58. else:
  59. token_baazar_media_url = '/var/www/ico_with_bid/media/'
  60. service_account_json = "/var/www/ico_with_bid/media/token baazar-f215172e741e.json"
  61. service_account_json = get_firebase_config()
  62. s3_conn = boto.connect_s3(host=REGION_HOST)
  63. bucket = s3_conn.get_bucket("bubblo-kyc-data")
  64.  
  65. # firebase_user_id = get_firebase_user_id
  66. # print 'firebase user authenticated:::s %s' %firebase_user_id
  67. firebase_config = {
  68. "apiKey": "AIzaSyBMsLUf7d6anHBiOTYzrQUaOhI-g8EhBH4",
  69. "authDomain": "proud-parity-131813.firebaseapp.com",
  70. "databaseURL": "https://proud-parity-131813.firebaseio.com",
  71. "projectId": "proud-parity-131813",
  72. "storageBucket": "proud-parity-131813.appspot.com",
  73. "messagingSenderId": "829650100337",
  74. # "serviceAccount": service_account_json
  75. }
  76. firebase = pyrebase.initialize_app(firebase_config)
  77. db = firebase.database()
  78. auth = firebase.auth()
  79. aes_key = 'd57c3965685720958cef68af53f6ba219e0eb1ddf163c649ebc8ec653c47fe8d'
  80.  
  81. # Create your views here.
  82. if config.prod is False:
  83. eth_user = 'bubblo'
  84. eth_token = '2399038c8873444177469b4c4095baa2adf4fc'
  85. auxpay_user = 'bubblo'
  86. auxpay_token = '0d16df905b404a40a83af5aa837b6074d6140e6b71d245f4a090f2fc85990fab'
  87. multisig_address_url = 'http://207.154.234.187/get_key/' + auxpay_user + '?token=' + auxpay_token
  88. # multisig_address_url = 'http://159.203.125.112/get_key/' + auxpay_user+'?token='+ auxpay_token
  89. # multisig_address_url = 'http://127.0.0.1:5000/get_key/' + auxpay_user+'?token='+ auxpay_token
  90. btc_address_url = 'http://207.154.234.187/get_key/' + auxpay_user + '?token=' + auxpay_token + '&notify_count=1'
  91. # btc_address_url = 'http://159.203.125.112/get_key/' + auxpay_user + '?token=' + auxpay_token + '&notify_count=1'
  92. eth_address_url = 'http://138.197.111.208:8003/eth_auxpay/api/get_eth_address?user=' + eth_user + '&token=' + eth_token
  93. btc_fee_url = 'http://207.154.234.187/get_fees'
  94. # btc_fee_url = 'http://159.203.125.112/get_fees'
  95. eth_fee_url = 'http://138.197.111.208:8003/eth_auxpay/api/get_fee?user=' + eth_user + '&token' + eth_token
  96. btc_get_balance_url = 'http://207.154.234.187/get_balance'
  97. # btc_get_balance_url = 'http://159.203.125.112/get_balance'
  98. forward_btc_url = 'http://159.203.125.112/forward_btc'
  99. forward_eth_url = 'http://138.197.111.208:8003/eth_auxpay/api/forward_eth'
  100. hd_address_url = 'http://207.154.234.187/get_key/' + auxpay_user + '?token=' + auxpay_token + '&isInternal=false&notify_count=1&conf_limit=10&type=HD&seed_hash='
  101. # hd_address_url = 'http://159.203.125.112/get_key/' + auxpay_user + '?token=' + auxpay_token + '&isInternal=false&notify_count=1&conf_limit=10&type=HD&seed_hash='
  102. init_hd_seed_url = 'http://159.203.125.112/initialise_seed/' + auxpay_user + '?token=' + auxpay_token + '&type=HD'
  103. btc_withdraw_address = 'mpRvRkW2NeUgRJW9PWUuEVKh9hZ9kPJh76'
  104. eth_withdraw_address = ''
  105. eth_payout_address = '0x73e97a483381b16b6208d6c9eb8a85e6adf90d2d'
  106. cas_payout_address = '0xa95fef2fa0264e119d8ffe6136aa08bf7ab2d285'
  107. cas_withdraw_url = 'https://127.0.0.1:1234/cas/withdraw-cas/'
  108. else:
  109. eth_user = 'cashaa_otc'
  110. eth_token = '092a318a169b4c4095baa2adf4fc5c1af'
  111. auxpay_user = 'bubblo'
  112. auxpay_token = '0d16df905b404a40a83af5aa837b6074d6140e6b71d245f4a090f2fc85990fab'
  113. multisig_address_url = 'http://207.154.234.187/get_key/' + auxpay_user
  114. # multisig_address_url = 'http://127.0.0.1:5000/get_key/' + auxpay_user
  115.  
  116. btc_address_url = 'http://207.154.234.187/get_key/' + auxpay_user + '?token=' + auxpay_token + '&notify_count=1'
  117. eth_address_url = 'http://159.89.14.24:8003/eth_auxpay/api/get_eth_address?user=' + eth_user + '&token=' + eth_token
  118. btc_fee_url = 'http://207.154.234.187/get_fees'
  119. eth_fee_url = 'http://159.89.14.24:8003/eth_auxpay/api/get_fee?user=' + eth_user + '&token=' + eth_token
  120. btc_get_balance_url = 'http://207.154.234.187/get_balance'
  121. forward_btc_url = 'http://207.154.234.187/forward_btc'
  122. forward_eth_url = 'http://159.89.14.24:8003/eth_auxpay/api/forward_eth'
  123. hd_address_url = 'http://207.154.234.187/get_key/' + auxpay_user + '?token=' + auxpay_token + '&isInternal=false&notify_count=1&conf_limit=10&type=HD&seed_hash='
  124. init_hd_seed_url = 'http://207.154.234.187/initialise_seed/' + auxpay_user + '?token=' + auxpay_token + '&type=HD'
  125. btc_withdraw_address = '14ZZ4YybZF7ggT2yDucNACfWizTFEJ2Gbb'
  126. eth_withdraw_address = '0x1e7d5667bf73f8a666d87fe3a3ae5ed52747fb4c'
  127. eth_payout_address = '0x0ba7ebb60e19d85f5c1bba88a765a1b4eeff9a7a'
  128. cas_withdraw_url = 'https://127.0.0.1:1234/cas/withdraw-cas'
  129.  
  130.  
  131. def _decrypt(edata, password):
  132. def pad(data):
  133. BLOCK_SIZE = 16
  134. pad = BLOCK_SIZE - len(data) % BLOCK_SIZE
  135. return data + pad * chr(pad)
  136.  
  137. def unpad(padded):
  138. pad = ord(padded[-1])
  139. return padded[:-pad]
  140.  
  141. try:
  142. edata = base64.urlsafe_b64decode(str(edata))
  143. m = hashlib.md5()
  144. m.update(password)
  145. key = m.hexdigest()
  146.  
  147. m = hashlib.md5()
  148. m.update(password + key)
  149. iv = m.hexdigest()
  150.  
  151. aes = AES.new(key, AES.MODE_CBC, iv[:16])
  152. str1 = str(unpad(aes.decrypt(edata)))
  153. str1 = unicode(str1, errors='replace')
  154. print 'unpadded final', str1
  155. return str1
  156. except Exception as e:
  157. print "Decrypt failed. Error: ", e.message
  158. return None
  159.  
  160.  
  161. @csrf_exempt
  162. # @TokenValidatorMiddleware
  163. # @RequestValidatorMiddleware
  164. def sign_up(request):
  165. """abcd abcd"""
  166. print 'bbb %s,%s, aaa %s' % (request.body, type(request.body), request.POST)
  167. data = json.loads(request.body)
  168. print 'ppppp %s,%s' % (data, type(data))
  169. if request.method == 'POST':
  170. email = data['email']
  171. exists_flag = user_exists_model(email)
  172. password_flag = password_exists_model(email)
  173. if exists_flag is None or password_flag is None:
  174. return JsonResponse({"code": 200, 'type': 'new'})
  175. else:
  176. forgot_token = str(randint(111111, 999999))
  177. otp_session('forgot_password_' + email, forgot_token)
  178. return JsonResponse({"code": 200, 'type': 'old', 'forgot_token': forgot_token})
  179. return JsonResponse({'response': 'get request'})
  180.  
  181.  
  182. @csrf_exempt
  183. def android_sign_in(request):
  184. print 'hitted android sign_up0'
  185. data = json.loads(request.body)
  186. email = data['email']
  187. password = data['password']
  188. flag = validate_user(email, password)
  189. if flag:
  190. forgot_token = str(randint(111111, 999999))
  191. otp_session('forgot_password_' + email, forgot_token)
  192. return JsonResponse({"code": 200, 'type': 'old', 'forgot_token': forgot_token})
  193. else:
  194. return JsonResponse({'code': 401, 'msg': 'invalid_user'})
  195.  
  196.  
  197. @csrf_exempt
  198. @TokenValidatorMiddleware
  199. @RequestValidatorMiddleware
  200. def init_forgot_password(request):
  201. data = json.loads(request.body)
  202. email = data['email']
  203. forgot_token = data['forgot_token']
  204. flag = otp_verification('forgot_password_' + email, forgot_token)
  205. if flag == 1:
  206. url = data['url']
  207. send_forgot_password_email(email, url)
  208. name = get_user_name(email)
  209. return JsonResponse({"code": 200, 'msg': 'link_sent', 'name': name})
  210. else:
  211. return JsonResponse({"code": 400, "err": "invalid_forgot_token"})
  212.  
  213.  
  214. def send_forgot_password_email(email, url):
  215. data = { "id" : 43,
  216. "to" : {email: email},
  217. "replyto" : "support@auxledger.org",
  218. "attr" : {"url": str(url)},
  219. "headers" : {"Content-Type": "text/html;charset=iso-8859-1"}
  220. }
  221. result = m.send_transactional_template(data)
  222.  
  223.  
  224. @csrf_exempt
  225. @TokenValidatorMiddleware
  226. @RequestValidatorMiddleware
  227. def forgot_password(request):
  228. data = json.loads(request.body)
  229. email = data['email']
  230. forgot_token = data['forgot_token']
  231. flag = otp_verification('forgot_password_' + email, forgot_token)
  232. if flag == 1:
  233. password = data['password']
  234. if len(password) > 7 and password.isalpha() == False and password.isdigit() == False:
  235. update_password_model(email, password)
  236. res = user_exists_model(email)
  237. if res.__contains__('tnc'):
  238. unique_id = create_jwt(email)
  239. # unique_id = str(uuid.uuid4()) + str(uuid.uuid4()) + str(uuid.uuid4())
  240. save_uuid(unique_id, email)
  241. if res.__contains__('kyc'):
  242. return JsonResponse({'code': 200, 'tnc': True, 'kyc': res['kyc']['status'], 'token': unique_id})
  243. else:
  244. return JsonResponse({'code': 200, 'tnc': True, 'kyc': False, 'token': unique_id})
  245. else:
  246. return JsonResponse({'code': 200, 'tnc': False, 'kyc': False})
  247. else:
  248. return JsonResponse({"code": 400, 'msg': 'invalid_password'})
  249. else:
  250. return JsonResponse({"code": 400, "err": "invalid_forgot_token"})
  251.  
  252.  
  253. @csrf_exempt
  254. @TokenValidatorMiddleware
  255. def new_user_password(request):
  256. data = json.loads(request.body)
  257. email = data['email']
  258. password = data['password']
  259. # exists_flag = user_exists_model(email)
  260. password_flag = password_exists_model(email)
  261. if password_flag:
  262. return JsonResponse({'code': 400, 'msg': 'already_exists'})
  263. if len(password) > 7 and password.isalpha() == False and password.isdigit() == False:
  264. user_existance(email, password)
  265. otp = str(randint(111111, 999999))
  266. data = {"id": 36,
  267. "to": {email: email},
  268. "replyto": "support@auxledger.org",
  269. "attr": {"otp": str(otp)},
  270. "headers": {"Content-Type": "text/html;charset=iso-8859-1"}
  271. }
  272. result = m.send_transactional_template(data)
  273. if result['code'] == "success":
  274. otp_session(email, otp)
  275. return JsonResponse({'code': 200, 'msg': 'password_set_successfully'})
  276. else:
  277. return JsonResponse({"code": 400, 'msg': 'invalid_password'})
  278.  
  279.  
  280. @csrf_exempt
  281. @TokenValidatorMiddleware
  282. def verify_otp(request): ##email and otp is taken from front end
  283. data = json.loads(request.body)
  284. email = data['email']
  285. otp_ = data['otp']
  286. flag = otp_verification(email, otp_)
  287. if flag == 1:
  288. res = user_exists_model(email)
  289. if res.__contains__('tnc'):
  290. # if res['kyc']['status'] == 'pending':
  291. # return JsonResponse({'code':200,'tnc':True,'kyc':'pending'})
  292. # elif res['kyc']['status'] == 'rejected':
  293. # return JsonResponse({"code":200,'tnc':True,'kyc':'rejected'})
  294. # else:
  295. unique_id = create_jwt(email)
  296. save_uuid(unique_id, email)
  297. if res.__contains__('kyc'):
  298. return JsonResponse({'code': 200, 'tnc': True, 'kyc': res['kyc']['status'], 'token': unique_id})
  299. else:
  300. return JsonResponse({'code': 200, 'tnc': True, 'kyc': False, 'token': unique_id})
  301. # elif res.__contains__('tnc') and not res.__contains__('kyc'):
  302. # return JsonResponse({'code':200,'tnc':True,'kyc':False})
  303. else:
  304. res1 = enter_signup_in_user_timeline(email)
  305. return JsonResponse({'code': 200, 'tnc': False, 'kyc': False})
  306. else:
  307. return JsonResponse({"code": 400, "otp": "not_verified"})
  308.  
  309.  
  310. @csrf_exempt
  311. # @TokenValidatorMiddleware
  312. # @JWTMiddleware
  313. def logout(request):
  314. data = json.loads(request.body)
  315. email = data['email']
  316. unique_id = data["token"]
  317. uuid_flag = 1
  318. if uuid_flag == 1:
  319. del_uuid_from_redis(unique_id)
  320. return JsonResponse({"code": 200, "success": True})
  321. else:
  322. return JsonResponse({"code": 401, "token_match": False})
  323.  
  324.  
  325. @csrf_exempt
  326. @TokenValidatorMiddleware
  327. def verify_password(request):
  328. data = json.loads(request.body)
  329. email = data['email']
  330. password = data['password']
  331. res = verify_password_model(email, password)
  332. if res:
  333. res = check_2fa_status(email)
  334. if res:
  335. return JsonResponse({"code": 200, "password_match": True, '2fa_enabled': True})
  336. else:
  337. send_otp_mail(email)
  338. return JsonResponse({"code": 200, "password_match": True, '2fa_enabled': False})
  339. else:
  340. return JsonResponse({"code": 400, "password_match": False})
  341.  
  342.  
  343. @csrf_exempt
  344. @TokenValidatorMiddleware
  345. @JWTMiddleware
  346. def change_password(request):
  347. data = json.loads(request.body)
  348. email = data['email']
  349. uuid_flag = 1
  350. if uuid_flag == 1:
  351. password = data['current_password']
  352. new_password = data['new_password']
  353. res = verify_password_model(email, password)
  354. if res:
  355. if len(new_password) > 7 and new_password.isalpha() == False and new_password.isdigit() == False:
  356. update_password_model(email, new_password)
  357. return JsonResponse({'code': 200, 'msg': 'password_set_successfully'})
  358. else:
  359. return JsonResponse({"code": 400, 'msg': 'invalid_password'})
  360. else:
  361. return JsonResponse({"code": 400, "password_match": False})
  362. else:
  363. return JsonResponse({"code": 401, "token_match": False})
  364.  
  365.  
  366. @csrf_exempt
  367. @TokenValidatorMiddleware
  368. def resent_otp(request):
  369. data = json.loads(request.body)
  370. email = data['email']
  371. otp = str(randint(111111, 999999))
  372. otp_session(email, otp)
  373. m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
  374. data = {"id": 36,
  375. "to": {email: email},
  376. "replyto": "support@auxledger.org",
  377. "attr": {"otp": str(otp)},
  378. "headers": {"Content-Type": "text/html;charset=iso-8859-1"}
  379. }
  380. result = m.send_transactional_template(data)
  381. exists_flag = user_exists_model(email)
  382. password_flag = password_exists_model(email)
  383. if exists_flag is None or password_flag is None:
  384. return JsonResponse({"code": 200, 'type': 'new'})
  385. else:
  386. forgot_token = str(randint(111111, 999999))
  387. otp_session('forgot_password_' + email, forgot_token)
  388. return JsonResponse({"code": 200, 'type': 'old', 'forgot_token': forgot_token})
  389.  
  390.  
  391. def send_otp_mail(email):
  392. print "_-------------------into send_otp_mail_____-----------------"
  393. otp = str(randint(111111, 999999))
  394. otp_session(email, otp)
  395.  
  396. m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
  397.  
  398. data = {"id": 36,
  399. "to": {email: email},
  400. "replyto": "support@auxledger.org",
  401. "attr": {"otp": str(otp)},
  402. "headers": {"Content-Type": "text/html;charset=iso-8859-1"}
  403. }
  404. result = m.send_transactional_template(data)
  405. print 'opt email status for email ::: %s, is:::: %s' % (email, result)
  406.  
  407.  
  408. @csrf_exempt
  409. @TokenValidatorMiddleware
  410. @JWTMiddleware
  411. def get_otp_qr_code(request):
  412. data = json.loads(request.body)
  413. email = data['email']
  414. unique_id = data['token']
  415. uuid_flag = uuid_verification(unique_id, email)
  416. if uuid_flag == 1:
  417. res = get_otp_str_model(email)
  418. if res:
  419. qr_code_str = pyotp.TOTP(res['otp_str']).provisioning_uri("Auxledger Tokensale", issuer_name="Auxledger")
  420. return JsonResponse({'code': 200, 'msg': 'new_user', 'qr_code_str': qr_code_str})
  421. else:
  422. otp_str = pyotp.random_base32()
  423. insert_in_otp(email, otp_str)
  424. qr_code_str = pyotp.TOTP(otp_str).provisioning_uri("Auxledger Tokensale", issuer_name="Auxledger")
  425. return JsonResponse({'code': 200, 'msg': '2fa_already_done', 'qr_code_str': qr_code_str})
  426. else:
  427. return JsonResponse({"code": 401, "token_match": False})
  428.  
  429.  
  430. @csrf_exempt
  431. def enable_google_authenticator(request):
  432. data = json.loads(request.body)
  433. email = data['email']
  434. unique_id = data['token']
  435. uuid_flag = uuid_verification(unique_id, email)
  436. if uuid_flag == 1:
  437. otp = data['otp']
  438. res = get_otp_str(email)
  439. if res:
  440. otp_str = res['otp_str']
  441. totp = pyotp.TOTP(otp_str)
  442. otp_flag = totp.verify(otp)
  443. if otp_flag is True:
  444. update_current_otp_flag(email)
  445. return JsonResponse({'code': 200, 'msg': 'enabled_2fa'})
  446. else:
  447. return JsonResponse({'code': 400, 'msg': 'otp_verification_false'})
  448. else:
  449. return JsonResponse({'code': 400, 'error': '2fa_already_enabled'})
  450. else:
  451. return JsonResponse({"code": 401, "token_match": False})
  452.  
  453.  
  454. @csrf_exempt
  455. @TokenValidatorMiddleware
  456. @JWTMiddleware
  457. def disable_google_authenticator(request):
  458. data = json.loads(request.body)
  459. email = data['email']
  460. uuid_flag = 1
  461. if uuid_flag == 1:
  462. otp = data['otp']
  463. res = get_otp_str(email, True)
  464. if res:
  465. otp_str = res['otp_str']
  466. totp = pyotp.TOTP(otp_str)
  467. otp_flag = totp.verify(otp)
  468. if otp_flag is True:
  469. disable_current_otp_flag(email)
  470. return JsonResponse({'code': 200, 'msg': 'disable_2fa'})
  471. else:
  472. return JsonResponse({'code': 400, 'msg': 'otp_verification_false'})
  473. else:
  474. return JsonResponse({'code': 400, 'error': '2fa_already_disabled'})
  475. else:
  476. return JsonResponse({"code": 401, "token_match": False})
  477.  
  478.  
  479. @csrf_exempt
  480. def tnc(request):
  481. if request.method == "POST":
  482. data = json.loads(request.body)
  483. name = data['name']
  484. email = data['email']
  485. user_ref_id = get_ref_id(email)
  486. if data.__contains__('ref_id'):
  487. if data['ref_id'] is None:
  488. print '11'
  489. insert_parent_ref_id(user_ref_id, None)
  490. else:
  491. print '22'
  492. ref_id = data['ref_id']
  493. ref_id_flag = validate_ref_id(ref_id)
  494. if ref_id_flag is None:
  495. return JsonResponse({'code': 400, 'error': 'invalid_ref_id'})
  496. insert_parent_ref_id(user_ref_id, ref_id)
  497. push_child_ref_id(user_ref_id, ref_id)
  498. else:
  499. insert_parent_ref_id(user_ref_id, None)
  500. res = user_exists_model(email)
  501. # print res
  502. # unique_id = str(uuid.uuid4()) + str(uuid.uuid4()) + str(uuid.uuid4())
  503. unique_id = create_jwt(email)
  504. save_uuid(unique_id, email)
  505. if res.__contains__("tnc"):
  506. print("----------->")
  507. if config.development:
  508. path = "/home/parin/Documents/ico_with_bid/Kyc_tier2_approved_userlist.csv"
  509. else:
  510. path = "/var/www/ico_with_bid/Kyc_tier2_approved_userlist.csv"
  511. with open(path, 'rb') as f:
  512. reader = csv.reader(f)
  513. for row in reader:
  514. if email == row[0]:
  515. pre_approve_kyc(email)
  516. return JsonResponse(
  517. {"code": 400, 'status': 'already_done', "tnc": True, "kyc": True, "token": unique_id})
  518. if res.__contains__('kyc'):
  519. if res['kyc']['status'] == 'pending':
  520. return JsonResponse(
  521. {"code": 400, 'status': 'already_done', "tnc": True, "kyc": 'pending', "token": unique_id})
  522. elif res['kyc']['status'] == 'rejected':
  523. return JsonResponse(
  524. {"code": 400, 'status': 'already_done', "tnc": True, "kyc": 'rejected', "token": unique_id})
  525. else:
  526. return JsonResponse(
  527. {"code": 400, 'status': 'already_done', "tnc": True, "kyc": True, "token": unique_id})
  528. else:
  529. return JsonResponse(
  530. {"code": 400, 'status': 'already_done', "tnc": True, "kyc": False, "token": unique_id})
  531. else:
  532. tnc_model(name, email)
  533. with open('/var/www/ico_with_bid/Kyc_tier2_approved_userlist.csv', 'rb') as f:
  534. reader = csv.reader(f)
  535. for row in reader:
  536. if email == row[0]:
  537. pre_approve_kyc(email)
  538. return JsonResponse(
  539. {"code": 200, 'status': 'accepted', "tnc": True, "kyc": True, "token": unique_id})
  540. return JsonResponse({"code": 200, 'status': 'accepted', "tnc": True, "kyc": False, "token": unique_id})
  541.  
  542.  
  543. from django.core.files.storage import FileSystemStorage
  544.  
  545.  
  546. @csrf_exempt
  547. # @TokenValidatorMiddleware
  548. # @JWTMiddleware
  549. def kyc(request):
  550. email = request.POST.get('email')
  551. aadhar_card_obj = request.FILES.get('idproofs')
  552. pan_card_obj = request.FILES.get('pan_card')
  553. aadhar_name = email + "_" + "_" + aadhar_card_obj.name
  554. pan_name = email + "_" + pan_card_obj.name
  555. fs = FileSystemStorage(location="/var/www/ico_with_bid/media/kyc")
  556.  
  557. fs.save(aadhar_name, aadhar_card_obj)
  558. fs.save(pan_name, pan_card_obj)
  559. input_json = {"status": "pending", "aadhar_card_details": aadhar_name, "pan_card_details": pan_name}
  560. kyc_model(input_json, email)
  561. enter_kyc_submit_in_user_timeline(email)
  562. return JsonResponse({"code": 200, "tnc": True, 'kyc': 'pending'})
  563.  
  564.  
  565. # @csrf_exempt
  566. # @TokenValidatorMiddleware
  567. # @JWTMiddleware
  568. # def kyc(request):
  569. # data = json.loads(request.body)
  570. # email = data['email']
  571. # uuid_flag =1
  572. # if uuid_flag == 1:
  573. # id_proofs = data['idproofs']
  574. # aadhar_counter = 0
  575. # aadhar_card_details = []
  576. # valid_file_types = ['jpg','jpeg','png','pdf']
  577. # for id_data in id_proofs:
  578. # id_data['name'] = 'aadharcard_' + str(aadhar_counter) + '_' + hashlib.sha256(email).hexdigest() + '_' + str(int(time.time())) + '.' + id_data['filename'].split('.')[1]
  579. # id_data['filetype'] = id_data['filetype'].split('/')[1]
  580. # if id_data['filetype'] not in valid_file_types:
  581. # return JsonResponse({'code':401,'error':'invalid_file_type'})
  582. # id_data['path'] = token_baazar_media_url
  583. # aadhar_counter += 1
  584. # # with open(token_baazar_media_url + id_data['name'],'wb') as adh:
  585. # # adh.write(id_data['value'].decode('base64'))
  586. # aadhar_card_details.append(id_data)
  587. #
  588. # pan_card_details = data['pan_card']
  589. # pan_card_name = 'pancard_' + hashlib.sha256(email).hexdigest() + '_' + str(int(time.time())) + '.' + pan_card_details['filename'].split('.')[1]
  590. # # with open(token_baazar_media_url + pan_card_name,'wb') as fh:
  591. # # fh.write(pan_card_details['value'].decode('base64'))
  592. # pan_card_details['name'] = pan_card_name
  593. # pan_card_details['filetype'] = pan_card_details['filetype'].split('/')[1]
  594. # if pan_card_details['filetype'] not in valid_file_types:
  595. # return JsonResponse({'code':401,'error':'invalid_file_type'})
  596. # pan_card_details['path'] = token_baazar_media_url
  597. # k = Key(bucket)
  598. # k.set_contents_from_string(str(aadhar_card_details))
  599. # adhaar_id = k.key
  600. # k = Key(bucket)
  601. # k.set_contents_from_string(str(pan_card_details))
  602. # pan_status = k.key
  603. # input_json = {"status":"pending","aadhar_card_details":adhaar_id,"pan_card_details":pan_status}
  604. # kyc_model(input_json,email)
  605. # enter_kyc_submit_in_user_timeline(email)
  606. # return JsonResponse({"code":200,"tnc":True,'kyc':'pending'})
  607. # else:
  608. # return JsonResponse({"code":401,'reason':'unauthorized'})
  609.  
  610.  
  611. @csrf_exempt
  612. @TokenValidatorMiddleware
  613. @JWTMiddleware
  614. def create_erc_address(request):
  615. data = json.loads(request.body)
  616. email = data['email']
  617. uuid_flag = 1
  618. if uuid_flag == 1:
  619. erc_address = data['erc_address']
  620. erc_address_validation = validate_eth_address(erc_address)
  621. if erc_address_validation is False:
  622. return JsonResponse({'code': 401, 'address_validation': False})
  623. eth_wallet = data['eth_wallet']
  624. res = create_erc_address_model(email, erc_address, eth_wallet)
  625. return JsonResponse({'code': 200, 'address_validation': True})
  626. else:
  627. return JsonResponse({"code": 401, "token_match": False})
  628.  
  629.  
  630. @csrf_exempt
  631. @TokenValidatorMiddleware
  632. @JWTMiddleware
  633. def dashboard(request):
  634. print 'in dashboaard::: '
  635. data = json.loads(request.body)
  636. email = data['email']
  637. # unique_id = data['token']
  638. # uuid_flag = uuid_verification(unique_id,email)
  639. uuid_flag = 1
  640. if uuid_flag == 1:
  641. # flag = address_avaiblity(email)
  642. # res = user_exists_model(email)
  643. # if not res.__contains__('seed_hash'):
  644. # init_seed_res = requests.get(init_hd_seed_url)
  645. # # print 'aaaa %s,%s' % (init_seed_res.status_code, json.loads(init_seed_res.text))
  646. # if init_seed_res.status_code == 200:
  647. # init_seed_hash = json.loads(init_seed_res.text)['msg']['seedhash']
  648. # encrypted_phrase = json.loads(init_seed_res.text)['msg']['phrase']
  649. # key = hashlib.sha256(init_seed_hash).hexdigest()[0:16]
  650. # seeds = _decrypt(encrypted_phrase,key)
  651. # print 'seeds are::: %s' %seeds
  652. # res = save_seed_hash_model(email,init_seed_hash,seeds)
  653. # if not res.__contains__('btc_address') or not res.__contains__('eth_address'):
  654. # btc_address_res = requests.get(btc_address_url)
  655. # eth_address_res = requests.get(eth_address_url)
  656. # if btc_address_res.status_code == 200 and eth_address_res.status_code == 200:
  657. # btc_address = json.loads(btc_address_res.text)['msg']
  658. # eth_address = json.loads(eth_address_res.text)['msg']['address']
  659. # address_insertion_model(btc_address,eth_address,email)
  660. # # return JsonResponse({"code":200,"btc address":btc_address,"eth_address":eth_address})
  661. # else:
  662. # return JsonResponse({"code":500,"error":'unable_to_generate_btc_or_eth_address'})
  663. # else:
  664. # btc_address = res['btc_address']
  665. # eth_address = res['eth_address']
  666. user_details = user_exists_model(email)
  667. user_name = user_details['tnc']['name']
  668. if user_details.__contains__('kyc'):
  669. kyc_flag = user_details['kyc']['status']
  670. else:
  671. kyc_flag = None
  672.  
  673. user_timeline_list = []
  674. tokens = 0.0
  675. timeline_res = get_user_timeline_model(email)
  676. for data in timeline_res:
  677. user_timeline_list.append(data)
  678. if data.__contains__('tokens_purchased'):
  679. tokens += float(data['tokens_purchased'])
  680. if data.__contains__('token_purchased'):
  681. tokens += float(data['token_purchased'])
  682.  
  683. # cashaa_withdrawal_res = get_cashaa_withdrawal_details(email)
  684. # for data in cashaa_withdrawal_res:
  685. # tokens -= int(float(data['amount_withdrawn']))
  686. rates_list = []
  687. timestamp = int(time.time())
  688. # btc_rate = get_rate(timestamp,'btc')
  689. # eth_rate = get_rate(timestamp,'eth')
  690. # fiat_rate = get_rate(timestamp,'fiat')
  691. # rates_list.append({'btc':btc_rate})
  692. # rates_list.append({'eth':eth_rate})
  693. # rates_list.append({'fiat':fiat_rate})
  694. # min_cap,max_cap = get_cap(timestamp)
  695. two_fa_status = check_2fa_status(email)
  696. send_dict = {
  697. 'status': 200,
  698. 'user_timeline_list': user_timeline_list,
  699. # 'rates_list':rates_list,
  700. # 'min_cap':min_cap,
  701. # 'max_cap':max_cap,
  702. 'kyc': kyc_flag,
  703. 'tokens': round(tokens, 3),
  704. 'user_name': user_name,
  705. 'two_fa_status': two_fa_status
  706. }
  707. # print "*********************************************************%s" %send_dict["tokens"]
  708. return JsonResponse(send_dict)
  709. else:
  710. return JsonResponse({"code": 401, "token_match": False})
  711.  
  712.  
  713. @csrf_exempt
  714. def normal_graph_data(request):
  715. print 'send normal_graph_data'
  716. data = json.loads(request.body)
  717. email = data['email']
  718. # unique_id = data['token']
  719. uuid_flag = 1
  720. if uuid_flag == 1:
  721. from_timestamp = int(data['from_timestamp'])
  722. to_timestamp = int(data['to_timestamp'])
  723. graph_data = get_graph_data(from_timestamp, to_timestamp)
  724. return JsonResponse({"code": 200, 'graph_data': graph_data})
  725. else:
  726. return JsonResponse({"code": 401, "token_match": False})
  727.  
  728.  
  729. @csrf_exempt
  730. def address_avaiblity(email):
  731. print email
  732. res = user_exists_model(email)
  733. print("----------->")
  734. print res
  735. if res.__contains__("btc_address") and res.__contains__("eth_address"):
  736. flag = 1
  737. else:
  738. flag = 0
  739. return flag
  740.  
  741.  
  742. @csrf_exempt
  743. @TokenValidatorMiddleware
  744. @JWTMiddleware
  745. def calculate_token_price(request):
  746. print 'calculating token pricce::: '
  747. data = json.loads(request.body)
  748. currency = data['currency']
  749. # token_amount = data['token_amount']
  750. email = data['email']
  751. # unique_id = data['token']
  752. uuid_flag = 1
  753. # uuid_flag = uuid_verification(unique_id,email)
  754. if uuid_flag == 1:
  755. rate = get_rate(int(time.time()), currency)
  756. # return_dict = {}
  757. print 'rate is:: %s' % rate
  758. # for key,value in rates_dict.iteritems():
  759. # return_dict[key] = float(float(token_amount)/float(value))
  760. return JsonResponse({currency: rate})
  761. else:
  762. return JsonResponse({"code": 401, "token_match": False})
  763.  
  764.  
  765.  
  766. @csrf_exempt
  767. @TokenValidatorMiddleware
  768. @JWTMiddleware
  769. def fiat_currency_for_approval(request): # for user
  770. data = json.loads(request.body)
  771. email = data['email']
  772. exchange_rate = get_usd_rate()
  773. uuid_flag = 1
  774. if uuid_flag == 1:
  775.  
  776. amount_deposited = data['amount_deposited']
  777. date = data['date']
  778. transaction_id = data['transaction_id']
  779. bank = data['deposit_bank']
  780. type = data['type']
  781. currency = data['currency']
  782.  
  783. insert_fiat_transaction_for_approval(amount_deposited,date,transaction_id,bank,email,exchange_rate,type,currency)
  784. wire_insert_payment_initialization_in_user_timeline(email,amount_deposited,currency)
  785. try:
  786. send_fiat_pending_mail(email, amount_deposited, transaction_id, bank,currency)
  787. except Exception as e:
  788. print "mail error"
  789. return JsonResponse({'code': 200, 'success': True})
  790. else:
  791. return JsonResponse({"code": 400, "token_match": False})
  792.  
  793. def send_fiat_pending_mail(email, amount_deposited, transaction_id, bank,currency):
  794. m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
  795. data = { "id" : 44,
  796. "to" : {email: email},
  797. "replyto" : "support@auxledger.org",
  798. "attr" : {"amount_deposited": str(amount_deposited), "currency": currency},
  799. "headers" : {"Content-Type": "text/html;charset=iso-8859-1"}
  800. }
  801. result = m.send_transactional_template(data)
  802. print result
  803. print result
  804.  
  805.  
  806.  
  807. @csrf_exempt
  808. # @TokenValidatorMiddleware
  809. # @JWTMiddleware
  810. def get_pending_fiat_transactions(request): # show fiat data to admin
  811. data = json.loads(request.body)
  812. uuid_flag = 1
  813. if uuid_flag == 1:
  814. pending_fiat_transactions = get_pending_fiat_transactions_model()
  815. return_list = []
  816. for data in pending_fiat_transactions:
  817. temp_json = {}
  818. temp_json["date"] = str(data["date"])
  819. temp_json["bank"] = str(data["bank"])
  820. temp_json["payment_method"] = data["type"]
  821. temp_json["time"] = data["time"]
  822. temp_json["amount_deposited_according_to_user"] = data["amount_deposited_according_to_user"]
  823. temp_json["transaction_id"] = data["transaction_id"]
  824. temp_json["email"] = data["email"]
  825. return_list.append(temp_json)
  826. return JsonResponse({'code': 200, 'pending_fiat_transactions': return_list})
  827. else:
  828. return JsonResponse({"code": 401, "token_match": False})
  829.  
  830.  
  831. @csrf_exempt
  832. def get_fiat_data_from_admin(request): ##call when user is approved
  833. data = json.loads(request.body)
  834. print data
  835. email = data['email']
  836. transaction_id = data["transaction_id"]
  837. update_json = {'email': data['email'], 'admin_receive_date': data['receive_date'],
  838. 'admin_receive_time': data['receive_time'], 'admin_received_amount': data['received_amount'],
  839. "admin_send_token": data['send_token'], "transaction_status": data['status']}
  840. update_fiat_transaction_admin(**update_json)
  841. if (data['status'] == "approve"):
  842. insert_fiat_transaction_in_transaction_details(email, transaction_id)
  843. # insert_payment_initialization_in_user_timeline(email,"usd",token_amount,price,amount_to_pay,bid_id)
  844. final_fiat_data = get_final_fiat_data(email, transaction_id)
  845. return JsonResponse({'code': 200, 'final_fiat_data': final_fiat_data})
  846.  
  847.  
  848. @csrf_exempt
  849. # @TokenValidatorMiddleware
  850. # @JWTMiddleware
  851. def fiat_confirmation_url(request):
  852. data = json.loads(request.body)
  853. print data
  854. _id = data['_id']
  855. email = data['email']
  856. uuid_flag = 1
  857. if uuid_flag == 1:
  858. timestamp = data['timestamp']
  859. amount = float(data['amount'])
  860. res = update_fiat_transaction_flag(_id)
  861. erc_address = get_erc_address(email)
  862. erc_wallet = get_erc_wallet(email)
  863. insert_res = insert_fiat_transaction_in_transaction_details(_id, email, timestamp, amount, erc_address,
  864. erc_wallet)
  865. insert_successful_fiat_transaction_in_user_timeline(_id, timestamp, amount, email)
  866. ref_id, name = get_referral_details_model_fiat(_id)
  867. calc_referal_bonus(ref_id, insert_res, name, 'fiat')
  868. return JsonResponse({'success': True})
  869. else:
  870. return JsonResponse({"code": 401, "token_match": False})
  871.  
  872.  
  873. @csrf_exempt
  874. @TokenValidatorMiddleware
  875. @JWTMiddleware
  876. def fiat_rejection_url(request):
  877. data = json.loads(request.body)
  878. print 'rejecting fiat transaction::::: %s' % data
  879. _id = data['_id']
  880. email = data['email']
  881. uuid_flag = 1
  882. if uuid_flag == 1:
  883. res = reject_fiat_transaction_flag(_id)
  884. insert_rejected_fiat_transaction_in_user_timeline(_id, email)
  885. return JsonResponse({'code': 200, 'success': True})
  886. else:
  887. return JsonResponse({"code": 401, "token_match": False})
  888.  
  889.  
  890. @csrf_exempt
  891. @TokenValidatorMiddleware
  892. @JWTMiddleware
  893. def pay_with_currency(request): ##not applicable for fiat
  894. print "_______-pay with currency___________-%s" % request.body
  895. data = json.loads(request.body)
  896.  
  897. email = data['email']
  898. currency = data['currency']
  899. token_amount = data['token_amount']
  900.  
  901. price_distribution, price = get_price(token_amount, currency)
  902.  
  903. if currency == 'btc':
  904. btc_to_usd = get_current_bubblo_price_model('btc')
  905. amount_to_pay = round(float(price), 8)
  906. bid_id = None
  907.  
  908. to_address, address_code = get_address_from_cashaa_pay(email, currency)
  909.  
  910. redeem_script = "NA"
  911. to_address_json = {"dummy": "NA"}
  912.  
  913. if address_code == 400:
  914. return JsonResponse({'code': 400, 'error': 'unable_to_generate_btc_address'})
  915.  
  916. res = insert_pay_click_model_btc(email, currency, token_amount, amount_to_pay, price, price_distribution,
  917. to_address, btc_to_usd, bid_id, redeem_script, to_address_json)
  918. insert_payment_initialization_in_user_timeline(email, currency, token_amount, price, amount_to_pay, bid_id)
  919.  
  920. return JsonResponse(
  921. {'code': 200, 'currency': currency, 'price': price, 'amount_to_pay': amount_to_pay, '_id': str(res),
  922. 'to_address': to_address, 'bid_id': bid_id})
  923.  
  924. if currency == 'eth':
  925. print "Into currency = eth"
  926. eth_to_usd = get_current_bubblo_price_model('eth')
  927. amount_to_pay = round(float(price), 3)
  928. bid_id = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6))
  929.  
  930. to_address, address_code = get_address_from_cashaa_pay(email, currency)
  931.  
  932. if address_code == 400:
  933. return JsonResponse({'code': 400, 'error': 'unable_to_generate_eth_address'})
  934.  
  935. insert_unverified_transaction(email, currency, token_amount, amount_to_pay, price, price_distribution,
  936. to_address, eth_to_usd, bid_id)
  937. insert_payment_initialization_in_user_timeline(email, currency, token_amount, price, amount_to_pay, bid_id)
  938.  
  939. return JsonResponse({'code': 200, 'currency': currency, 'price': price, 'amount_to_pay': amount_to_pay,
  940. 'to_address': to_address, 'bid_id': bid_id, 'bid_id_hex': binascii.hexlify(bid_id)})
  941.  
  942.  
  943. def get_address_from_cashaa_pay(email, currency):
  944. code = 400
  945. address = "na"
  946. if currency == "btc" or currency == "BTC":
  947. address = "NA"
  948. print "into get_address_cashaa"
  949. url_wallet_id = "http://35.181.20.211/bank/account/setup"
  950. url_address = "http://35.181.20.211/bank/address/multisig/"
  951.  
  952. header_content = {
  953.  
  954. "token": "HfgF2bJVHHDb-heUBQRhUIL3e",
  955. "username": "auxledger",
  956. "Authorization": "Basic YXV4bGVkZ2VyOk5FZTNxVUlZVWdsbnJndlhFMGdMRGR1a2lGamIzNHJUbDBWTg=="
  957. }
  958.  
  959. present = check_if_wallet_present(email, currency)
  960. if present:
  961. address = present
  962. return address, 200
  963. else:
  964. response = requests.post(url_wallet_id, headers=header_content)
  965. resp = response.json()
  966. resp_data = resp["data"]
  967. if int(resp["code"]) == 200:
  968. wallet_id = resp_data["walletId"]
  969. url_address = url_address + wallet_id
  970. response = requests.post(url_address, headers=header_content)
  971. resp = response.json()
  972. if int(resp["code"]) == 200:
  973. code = 200
  974. address = resp["address"]
  975. insert_address_in_cashaa_wallet(email, address, wallet_id, currency)
  976. add_btc_address_to_user_master_model(email, address)
  977. return address, code
  978.  
  979. return address, code
  980.  
  981. if currency == "eth" or currency == "ETH":
  982. code = 400
  983. eth_address_url_uat = "http://52.23.53.49:8003/v1/eth/singleton/address"
  984. eth_address_url_prod = "http://35.180.218.161:8003/v1/eth/singleton/address"
  985. user_address = check_if_wallet_present(email, currency)
  986.  
  987. if user_address:
  988. return user_address, 200
  989. else:
  990. headers_content = {
  991.  
  992. "x-app-key": "xal-auxledger",
  993. "x-secret-key": "ZUdGc0xXRjFlR3hsWkdkbGNpMWhkWGhsYzJseg==",
  994. }
  995.  
  996. headers_content["x-app-wallet-id"] = email
  997. headers_content["x-app-user-id"] = email
  998. body_content = {
  999. "userpassword": email
  1000. }
  1001.  
  1002. try:
  1003. response = requests.post(eth_address_url_prod, headers=headers_content, data=body_content)
  1004. resp_json = response.json()
  1005. print resp_json
  1006. if resp_json["body"]["status"] == "success":
  1007. address = resp_json["body"]["data"]["address"]
  1008. wallet_id = email
  1009.  
  1010. insert_address_in_cashaa_wallet(email, address, wallet_id, currency)
  1011. add_eth_address_to_user_master_model(email, address)
  1012. return address, 200
  1013. except Exception as e:
  1014. print e
  1015. return address, code
  1016.  
  1017.  
  1018. @csrf_exempt
  1019. # @TokenValidatorMiddleware
  1020. # @JWTMiddleware
  1021. def cas_for_approval_from_user(request): # for user
  1022. print "-----------into cas_for_approval_from_user----------"
  1023. data = json.loads(request.body)
  1024. email = data['email']
  1025. txid = data['tx_id']
  1026. _id = data['_id']
  1027. res = update_txid_cas_model(_id, txid)
  1028. return JsonResponse({'code': 200})
  1029.  
  1030.  
  1031. def send_cas_admin_pending_mail(email, amount_deposited, transaction_id, bank):
  1032. print 'sending email for fiat admin pending'
  1033. m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
  1034. email_dict = {
  1035. "to": {email: email},
  1036. "from": ["support@auxledger.org"],
  1037. "subject": "Welcome at Auxledger ",
  1038. "html": "Your payment of " + str(
  1039. amount_deposited) + " CAS is registered with us. Please wait for admin approval."
  1040. }
  1041. result = m.send_email(email_dict)
  1042. print 'res::: %s' % result
  1043.  
  1044.  
  1045. @csrf_exempt
  1046. @TokenValidatorMiddleware
  1047. @JWTMiddleware
  1048. def send_cashaa_withdrawal_otp(request):
  1049. data = json.loads(request.body)
  1050. email = data['email']
  1051. # unique_id = data['token']
  1052. uuid_flag = 1
  1053. if uuid_flag == 1:
  1054. res = get_otp_str(email, True)
  1055. if not res:
  1056. otp = str(randint(111111, 999999))
  1057. user_name = get_user_name(email)
  1058. m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
  1059. print 'sending mail to admin::: '
  1060. email_dict = {
  1061. "to": {email: email},
  1062. "from": ["support@auxledger.org"],
  1063. "subject": "OTP for Auxledger token withdrawal",
  1064. "html": get_html_send_cashaa_withdrawal_otp(user_name, str(otp))
  1065. }
  1066. result = m.send_email(email_dict)
  1067. print 'res::: %s' % result
  1068. if result['code'] == "success":
  1069. otp_session('withdraw_cashaa_' + email, otp)
  1070. # print 'mail sent response ::::::: %s' % result
  1071. return JsonResponse({"code": 200, 'success': 'mail sent'})
  1072. else:
  1073. return JsonResponse({"code": 400, 'failed': 'mail not sent'})
  1074. else:
  1075. return JsonResponse({"code": 200, 'success': 'mail sent'})
  1076. else:
  1077. return JsonResponse({"code": 401, "token_match": False})
  1078.  
  1079.  
  1080. @csrf_exempt
  1081. @TokenValidatorMiddleware
  1082. @JWTMiddleware
  1083. def verify_cashaa_withdraw_otp(request):
  1084. data = json.loads(request.body)
  1085. email = data['email']
  1086. uuid_flag = 1
  1087. if uuid_flag == 1:
  1088. print 'eeeeeeeeee %s' % email
  1089. otp_ = data['otp']
  1090. flag = otp_verification('withdraw_cashaa_' + email, otp_)
  1091. if flag == 1:
  1092. return JsonResponse({'code': 200, "otp": "verified"})
  1093. else:
  1094. return JsonResponse({"code": 400, "otp": "not_verified"})
  1095. else:
  1096. return JsonResponse({"code": 401, "token_match": False})
  1097.  
  1098.  
  1099. @csrf_exempt
  1100. @TokenValidatorMiddleware
  1101. @JWTMiddleware
  1102. def get_cashaa_withdrawals_for_admin(request):
  1103. data = json.loads(request.body)
  1104. email = data['email']
  1105. uuid_flag = 1
  1106. if uuid_flag == 1:
  1107. list_to_send = get_cashaa_withdrawals_for_admin_model()
  1108. return JsonResponse({"code": 200, "withdrawal_list": list_to_send})
  1109. else:
  1110. return JsonResponse({"code": 401, "token_match": False})
  1111.  
  1112.  
  1113. @csrf_exempt
  1114. @TokenValidatorMiddleware
  1115. @JWTMiddleware
  1116. def approve_cashaa_withdrawal(request):
  1117. data = json.loads(request.body)
  1118. email = data['email']
  1119. uuid_flag = 1
  1120. if uuid_flag == 1:
  1121. _id = data['_id']
  1122. res = get_withdraw_details(_id)
  1123. to_address = res['to_address']
  1124. token = res['amount_withdrawn']
  1125. requests.packages.urllib3.disable_warnings()
  1126. cas_res = requests.post(cas_withdraw_url, data={"token": token, "toaddress": to_address}, verify=False)
  1127. print 'data sent to cas withdrawal url::::: %s, is :::::: %s, response status is::::: %s, text is:::::: %s' % (
  1128. cas_withdraw_url, {"token": token, "to_address": to_address}, cas_res.status_code, cas_res.text)
  1129. if cas_res.status_code == 200:
  1130. cas_txt = json.loads(cas_res.text)
  1131. if cas_txt['data']['data'][len(cas_txt['data']['data']) - 1].__contains__('hash'):
  1132. txid = cas_txt['data']['data'][len(cas_txt['data']['data']) - 1]['hash']
  1133. approve_cashaa_withdrawal_model(_id, txid)
  1134. return JsonResponse({"code": 200, "success": True, "txid": txid})
  1135. else:
  1136. return JsonResponse({'code': 400, 'msg': 'transaction_falied'})
  1137. else:
  1138. return JsonResponse({"code": 400, "msg": 'transaction_falied'})
  1139. else:
  1140. return JsonResponse({"code": 401, "token_match": False})
  1141.  
  1142.  
  1143. @csrf_exempt
  1144. @TokenValidatorMiddleware
  1145. @JWTMiddleware
  1146. def reject_cashaa_withdrawal(request):
  1147. data = json.loads(request.body)
  1148. email = data['email']
  1149. uuid_flag = 1
  1150. if uuid_flag == 1:
  1151. _id = data['_id']
  1152. reject_cashaa_withdrawal_model(_id)
  1153. return JsonResponse({"code": 200, "success": True})
  1154. else:
  1155. return JsonResponse({"code": 401, "token_match": False})
  1156.  
  1157.  
  1158. @csrf_exempt
  1159. @TokenValidatorMiddleware
  1160. @JWTMiddleware
  1161. def request_cashaa_withdraw(request):
  1162. print 'request_cashaa_withdraw hitted::: '
  1163. data = json.loads(request.body)
  1164. email = data['email']
  1165. uuid_flag = 1
  1166. if uuid_flag == 1:
  1167. from_address = data['from_address']
  1168. to_address = data['to_address']
  1169. value = data['value']
  1170. cas_bal = get_user_cas_bal(email)
  1171. if float(value) > float(cas_bal):
  1172. return JsonResponse({"code": 400, "error": "insufficient_funds"})
  1173. insert_withdraw_in_cashaa_withdrawals(email, from_address, to_address, value)
  1174. send_withdraw_init_mail(email, value)
  1175. return JsonResponse({"code": 200, "success": True})
  1176. else:
  1177. return JsonResponse({"code": 401, "token_match": False})
  1178.  
  1179.  
  1180. def send_withdraw_init_mail(email, value):
  1181. m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
  1182. print 'sending mail to admin::: '
  1183. email_dict = {
  1184. "to": {email: email},
  1185. "from": ["support@auxledger.org"],
  1186. "subject": "Withdraw request initiated",
  1187. "html": get_send_withdraw_init_mail_html(value)
  1188. }
  1189. result = m.send_email(email_dict)
  1190. print 'res::: %s' % result
  1191.  
  1192.  
  1193. @csrf_exempt
  1194. @TokenValidatorMiddleware
  1195. @JWTMiddleware
  1196. def update_erc_address(request):
  1197. print 'update_erc hitted:::: '
  1198. data = json.loads(request.body)
  1199. email = data['email']
  1200. uuid_flag = 1
  1201. if uuid_flag == 1:
  1202. _id = data['_id']
  1203. new_erc_address = data['new_erc_address']
  1204. new_erc_wallet = data['new_erc_wallet']
  1205. erc_address_validation = validate_eth_address(new_erc_address)
  1206. if erc_address_validation is False:
  1207. return JsonResponse({'code': 401, 'address_validation': False})
  1208. currency = data['currency']
  1209. refund_address = get_refund_address_using_mail(email, currency)
  1210. update_unconfirmed_status_after_erc_review(_id)
  1211. update_erc_in_user_master(email, new_erc_address, new_erc_wallet)
  1212. res = update_pay_click_model(_id, new_erc_address, new_erc_wallet)
  1213. return JsonResponse({'code': 200, 'success': True, 'refund_address': refund_address, 'currency': currency})
  1214. else:
  1215. return JsonResponse({"code": 401, "token_match": False})
  1216.  
  1217.  
  1218. @csrf_exempt
  1219. @TokenValidatorMiddleware
  1220. @JWTMiddleware
  1221. def review_erc_address(request):
  1222. print 'review erc_address hitted::::: '
  1223. data = json.loads(request.body)
  1224. email = data['email']
  1225. uuid_flag = 1
  1226. if uuid_flag == 1:
  1227. _id = data['_id']
  1228. currency = data['currency']
  1229. refund_address = get_refund_address_using_mail(email, currency)
  1230. update_unconfirmed_status_after_erc_review(_id)
  1231. return JsonResponse({'code': 200, 'success': True, 'refund_address': refund_address, 'currency': currency})
  1232. else:
  1233. return JsonResponse({"code": 401, "token_match": False})
  1234.  
  1235.  
  1236. @csrf_exempt
  1237. @TokenValidatorMiddleware
  1238. @JWTMiddleware
  1239. def update_refund_address(request):
  1240. print 'update_refund hitted:::: '
  1241. data = json.loads(request.body)
  1242. email = data['email']
  1243. uuid_flag = 1
  1244. if uuid_flag == 1:
  1245. _id = data['_id']
  1246. currency = data['currency']
  1247. new_refund_address = data['new_refund_address']
  1248. if currency == 'btc':
  1249. btc_address_validation = validate_btc_address(new_refund_address)
  1250. if btc_address_validation is False:
  1251. return JsonResponse({'code': 401, 'address_validation': False})
  1252. else:
  1253. eth_address_validation = validate_eth_address(new_refund_address)
  1254. if eth_address_validation is False:
  1255. return JsonResponse({'code': 401, 'address_validation': False})
  1256. token_amount = data['token_amount']
  1257. # rate = float(get_rate(int(time.time()),currency))
  1258. # amount_to_pay = float(token_amount)/rate
  1259. res = update_refund_address_in_unconfirmed_transaction(_id, new_refund_address)
  1260. # generated_address = get_generated_address(email,currency)
  1261. generated_address = eth_payout_address
  1262. update_unconfirmed_status_after_refund_review(_id)
  1263. update_refund_address_in_user_master(email, new_refund_address, currency)
  1264. # obj_id = get_obj_id(email)
  1265. send_dict = {
  1266. 'code': 200,
  1267. 'success': True,
  1268. 'generated_address': generated_address,
  1269. 'token_amount': token_amount,
  1270. # 'rate':rate,
  1271. # 'amount_to_pay':amount_to_pay,
  1272. 'currency': currency
  1273. }
  1274. return JsonResponse(send_dict)
  1275. else:
  1276. return JsonResponse({"code": 401, "token_match": False})
  1277.  
  1278.  
  1279. @csrf_exempt
  1280. @TokenValidatorMiddleware
  1281. @JWTMiddleware
  1282. def get_current_cashaa_price(request):
  1283. print 'getting current cashaa price:::: '
  1284. data = json.loads(request.body)
  1285. email = data['email']
  1286. uuid_flag = 1
  1287. if uuid_flag == 1:
  1288. currency = data['currency']
  1289. current_cashaa_price = get_current_cashaa_price_model(currency)
  1290. return JsonResponse({"code": 200, "current_cashaa_price": current_cashaa_price})
  1291. else:
  1292. return JsonResponse({"code": 401, "token_match": False})
  1293.  
  1294.  
  1295. @csrf_exempt
  1296. @TokenValidatorMiddleware
  1297. @JWTMiddleware
  1298. def review_refund_address(request):
  1299. print 'review_refund_address hitted:::: '
  1300. data = json.loads(request.body)
  1301. email = data['email']
  1302. uuid_flag = 1
  1303. if uuid_flag == 1:
  1304. _id = data['_id']
  1305. currency = data['currency']
  1306. token_amount = data['token_amount']
  1307. # rate = float(get_rate(int(time.time()),currency))
  1308. # amount_to_pay = float(token_amount)/rate
  1309. generated_address = eth_payout_address
  1310. update_unconfirmed_status_after_refund_review(_id)
  1311. send_dict = {
  1312. 'code': 200,
  1313. 'success': True,
  1314. 'generated_address': generated_address,
  1315. 'token_amount': token_amount,
  1316. # 'rate':rate,
  1317. # 'amount_to_pay':amount_to_pay,
  1318. 'currency': currency
  1319. }
  1320. return JsonResponse(send_dict)
  1321. else:
  1322. return JsonResponse({"code": 401, "token_match": False})
  1323.  
  1324.  
  1325. # @csrf_exempt
  1326. # def update_status_after_transaction(request):
  1327. # print 'hit update_status_after_transaction:::: '
  1328. # data = json.loads(request.body)
  1329. # email = data['email']
  1330. # unique_id = data['token']
  1331. # uuid_flag = uuid_verification(unique_id,email)
  1332. # if uuid_flag == 1:
  1333. # _id = data['_id']
  1334. # update_unconfirmed_status_after_transaction(_id)
  1335. # return JsonResponse({'code':200,'success':True})
  1336. # else:
  1337. # return JsonResponse({"code":401,"token_match":False})
  1338.  
  1339.  
  1340. # from urllib import parse as urlparse
  1341. # from six.moves.urllib.parse import urlparse
  1342. import urlparse
  1343.  
  1344. import sys, os
  1345. from . import models
  1346.  
  1347.  
  1348. @csrf_exempt
  1349. def btc_notification_url(request):
  1350. try:
  1351. print '------------------ in btc notification ------------------- '
  1352. data = json.loads(request.body)
  1353. print data
  1354. address = data['to_address']
  1355. value = float(data['amount'])
  1356. from_address = data["from_address"]
  1357. txid = data['txid']
  1358. confirmations = int(data['confirmations'])
  1359. email_id = get_email_id_model(address, 'btc')
  1360.  
  1361. if confirmations == 0:
  1362. print "0th confirmations"
  1363.  
  1364. # update in transaction details
  1365.  
  1366. update_transaction_details(address, from_address, value, txid, confirmations)
  1367.  
  1368. no_of_token_allocated, exchange_rate = models.get_no_of_token_allocated(email_id, txid)
  1369.  
  1370. send_mail_flag = insert_zero_confirmation_in_user_timeline(email_id, 'btc', no_of_token_allocated, value,
  1371. None, txid)
  1372.  
  1373. if send_mail_flag:
  1374. print "sending 0 conf mail"
  1375. try:
  1376. send_zero_confirmation_mail(email_id, value, 'BTC', txid, exchange_rate)
  1377. except Exception as e:
  1378. print "send mail error"
  1379.  
  1380. return HttpResponse('OK')
  1381.  
  1382. else:
  1383. proceed_flag = False
  1384.  
  1385. old_confirmations = check_for_conformations(txid, email_id)
  1386.  
  1387. # if missed 0th confirmations
  1388. if not old_confirmations:
  1389. print "txid doesnt exist in transcation details"
  1390. update_transaction_details(address, from_address, value, txid, confirmations)
  1391.  
  1392. if confirmations >= 1:
  1393. proceed_flag = insert_btc_transaction_in_user_timeline(email_id, address, from_address, value, txid,
  1394. confirmations)
  1395. if proceed_flag:
  1396. ref_id, name = get_referral_details_model(address, 'btc')
  1397. calc_referal_bonus_auxledger(ref_id, value, name, 'btc', address, txid, email_id)
  1398.  
  1399. no_of_token_allocated, exchange_rate = models.get_no_of_token_allocated(email_id, txid)
  1400. print "sending received email"
  1401. try:
  1402. send_confirmation_mail(email_id, no_of_token_allocated, value, 'BTC')
  1403. except Exception as e:
  1404. print "sending mail error"
  1405.  
  1406. return HttpResponse('OK')
  1407.  
  1408.  
  1409. # else part
  1410. else:
  1411. print "txid exist in transcation details"
  1412. print "old confirmations is %s new confirmations is %s" % (old_confirmations, confirmations)
  1413. if old_confirmations < confirmations:
  1414. update_transaction_details(address, from_address, value, txid, confirmations)
  1415. proceed_flag = insert_btc_transaction_in_user_timeline(email_id, address, from_address, value, txid,
  1416. confirmations)
  1417. if proceed_flag:
  1418. ref_id, name = get_referral_details_model(address, 'btc')
  1419. calc_referal_bonus_auxledger(ref_id, value, name, 'btc', address, txid, email_id)
  1420.  
  1421. no_of_token_allocated, exchange_rate = models.get_no_of_token_allocated(email_id, txid)
  1422. print "sending email of positive confirmations"
  1423. try:
  1424. send_confirmation_mail(email_id, no_of_token_allocated, value, 'BTC')
  1425. except Exception as e:
  1426. print "sending mail error"
  1427. return HttpResponse('OK')
  1428.  
  1429. print "doing nothing"
  1430. return HttpResponse('OK')
  1431.  
  1432.  
  1433. except Exception as e:
  1434. print "into exception"
  1435. print e
  1436. exc_type, exc_obj, exc_tb = sys.exc_info()
  1437. fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
  1438. error_stack = str(exc_type) + str(fname) + str(exc_tb.tb_lineno)
  1439. print error_stack
  1440. return JsonResponse({"code": 400, "msg": e})
  1441.  
  1442. # except Exception as e:
  1443. # print 'Exception in btc_notification::: %s' %e.message
  1444. # return HttpResponse('ok')
  1445. # else:
  1446. # eth_refund_address = get_refund_address(to_address)
  1447. # eth_fee_res = requests.get(eth_fee_url)
  1448. # if value < min_cap:
  1449. # if eth_fee_res.status_code == 200:
  1450. # eth_fee = json.loads(eth_fee_res)['msg']['transaction_fee']
  1451. # refund_amount = value
  1452. # refund_eth(to_address,eth_refund_address,refund_amount,eth_fee,'less_than_cap')
  1453. # else:
  1454. # print 'eth_auxpay fee response error::: '
  1455. # eth_refund_dict = {
  1456. # 'from_address':to_address,
  1457. # 'refund_address':eth_refund_address,
  1458. # 'amount_to_refund':value,
  1459. # 'timestamp':int(time.time()),
  1460. # 'refund_type':'less_than_cap',
  1461. # 'currency':'eth'
  1462. # }
  1463. # insert_unsuccessful_eth_refund(eth_refund_dict)
  1464. # if value > max_cap:
  1465. # if eth_fee_res.status_code == 200:
  1466. # eth_fee = json.loads(eth_fee_res)['msg']['transaction_fee']
  1467. # refund_amount = value - max_cap
  1468. # refund_eth(to_address,eth_refund_address,refund_amount,eth_fee,'more_than_cap')
  1469. # else:
  1470. # print 'eth_auxpay fee response error::: '
  1471. # eth_refund_dict = {
  1472. # 'from_address':to_address,
  1473. # 'refund_address':eth_refund_address,
  1474. # 'amount_to_refund':value - max_cap,
  1475. # 'timestamp':int(time.time()),
  1476. # 'refund_type':'more_than_cap',
  1477. # 'currency':'eth'
  1478. # }
  1479. # insert_unsuccessful_eth_refund(eth_refund_dict)
  1480. # if confirmations == 0:
  1481. # print 'inserting eth transaction::: %s' %request.POST
  1482. # res = update_recieve_transaction_eth_model(to_address,from_address,max_cap,txid,confirmations)
  1483. # email_id = get_email_id_model(to_address,'eth')
  1484. # # transaction_details = get_transacation_details_model(txid)
  1485. # firebase_json = {
  1486. # 'email_id':email_id,
  1487. # 'to_address':to_address,
  1488. # 'from_address':from_address,
  1489. # 'value':value,
  1490. # 'txid':txid,
  1491. # 'confirmations':0
  1492. # }
  1493. # results = db.child('bubblo_transaction_details').child(to_address).set(firebase_json,firebase_user_id)
  1494. # print 'db update response after eth notification is::: %s' % res
  1495. # return HttpResponse('ok')
  1496. # else:
  1497. # print 'update eth confirmations:::::, of txid::: %s, confirmations::: %s' %(txid,confirmations)
  1498. # res = update_transaction_confirmations(txid)
  1499. # email_id = get_email_id_model(to_address,'eth')
  1500. # transaction_details = get_transacation_details_model(txid)
  1501. # # firebase_json = {
  1502. # # 'email_id':email_id,
  1503. # # 'to_address':to_address,
  1504. # # 'from_address':from_address,
  1505. # # 'value':value,
  1506. # # 'txid':txid,
  1507. # # 'confirmations':transaction_details['confirmations'],
  1508. # # 'currency':'eth'
  1509. # # }
  1510. # results = db.child('bubblo_transaction_details').child(to_address).update({'confirmations':transaction_details['confirmations']})
  1511. # print 'db update response after updating eth confirmation is::: %s' % res
  1512. # if confirmations == 3:
  1513. # insert_eth_transaction_in_user_timeline(email_id,to_address, from_address, value, txid,confirmations)
  1514. # return HttpResponse('ok')
  1515.  
  1516.  
  1517. def calculate_btc_fee(address, btc_refund_address, refund_amount):
  1518. bal_dict = {
  1519. 'user_name': auxpay_user,
  1520. 'token': auxpay_token,
  1521. 'address_list': [address]
  1522. }
  1523. bal_res = requests.post(btc_get_balance_url, data=json.dumps(bal_dict))
  1524. print 'json sent %s to bal_url %s' % (bal_dict, btc_get_balance_url)
  1525. if bal_res.status_code == 200:
  1526. print 'ba res::: %s,%s' % (json.loads(bal_res.text)[0], type(json.loads(bal_res.text)[0]))
  1527. address_details = json.loads(bal_res.text)[0][address]
  1528. address_btc_bal = address_details['confirmed']
  1529. # address_btc_bal = 50.0
  1530. # spent = address_details['spent']
  1531. # unconfirmed = address_details['unconfirmed']
  1532. # address_btc_bal = confirmed - spent + unconfirmed
  1533. else:
  1534. address_btc_bal = None
  1535. fee_dict = {
  1536. 'user_name': auxpay_user,
  1537. 'token': auxpay_token,
  1538. 'transactions': {
  1539. 'input_address': [address],
  1540. 'output_address': {
  1541. btc_refund_address: round(refund_amount, 8),
  1542. address: round(address_btc_bal - refund_amount, 8)
  1543. }
  1544. }
  1545. }
  1546. fee_res = requests.post(btc_fee_url, data=json.dumps(fee_dict))
  1547. print 'json sent %s to fee_url %s' % (fee_dict, btc_fee_url)
  1548. if fee_res.status_code == 200:
  1549. recommended_rate = json.loads(fee_res.text)['recommended_rate']
  1550. inputs = json.loads(fee_res.text)['nInputs']
  1551. # transaction_fee = 0.00040335
  1552. # transaction_fee = (148 inputs + 34 2 + 10) recommended_rate 0.001
  1553. transaction_fee = - (json.loads(fee_res.text)['diff'])
  1554. # btc_to_send = + transaction_fee
  1555. else:
  1556. transaction_fee = 0.00040335
  1557. print 'fee_api_response:::::::::: %s,%s,%s' % (
  1558. fee_res.text, fee_res.status_code, type(fee_res.status_code))
  1559. return transaction_fee, address_btc_bal
  1560.  
  1561.  
  1562. @csrf_exempt
  1563. def eth_notification_url(request):
  1564. print "_______into eth notification url_____________%s" % request.body
  1565.  
  1566. data = json.loads(request.body)
  1567. from_address = data['from_address']
  1568. to_address = data['to_address']
  1569. txid = data['txid']
  1570. confirmations = int(data['confirmations'])
  1571. value = float(data["amount"])
  1572.  
  1573. email_id = get_email_id_from_to_address_model(to_address)
  1574.  
  1575. if not email_id:
  1576. return JsonResponse({"code": 400, "msg": "address not available"})
  1577.  
  1578. erc_address = get_erc_address(email_id)
  1579. erc_wallet = get_erc_wallet(email_id)
  1580.  
  1581. if confirmations == 0:
  1582. proceed_flag = update_recieve_transaction_eth_model(email_id, to_address, from_address, value, txid,
  1583. confirmations, erc_address, erc_wallet)
  1584.  
  1585. if proceed_flag:
  1586. no_of_token_allocated, exchange_rate = models.get_no_of_token_allocated(email_id, txid)
  1587. send_mail_flag = insert_zero_confirmation_in_user_timeline(email_id, 'eth', no_of_token_allocated, value,
  1588. to_address, txid)
  1589.  
  1590. if send_mail_flag:
  1591. try:
  1592. send_zero_confirmation_mail(email_id, value, 'ETH', txid, exchange_rate)
  1593. except Exception as e:
  1594. print "sending mail error"
  1595.  
  1596. return HttpResponse('ok')
  1597. else:
  1598. old_confirmations = check_for_conformations(txid, email_id)
  1599.  
  1600. # if missed 0th confirmations
  1601. if old_confirmations is None:
  1602. update_recieve_transaction_eth_model(email_id, to_address, from_address, value, txid, confirmations,
  1603. erc_address, erc_wallet)
  1604.  
  1605. if confirmations >= 1:
  1606. send_mail_flag = insert_eth_transaction_in_user_timeline(email_id, to_address, from_address, value,
  1607. txid, confirmations)
  1608. if send_mail_flag:
  1609. ref_id, name = get_referral_details_model(to_address, 'eth')
  1610. calc_referal_bonus_auxledger(ref_id, value, name, 'eth', to_address, txid, email_id)
  1611.  
  1612. no_of_token_allocated, exchange_rate = models.get_no_of_token_allocated(email_id, txid)
  1613. print "sending received email"
  1614. try:
  1615. send_confirmation_mail(email_id, no_of_token_allocated, value, 'ETH')
  1616. except Exception as e:
  1617. print "send mail error"
  1618.  
  1619. return HttpResponse('OK')
  1620. else:
  1621. print "txid exist in transcation details"
  1622. print "old confirmations is %s new confirmations is %s" % (old_confirmations, confirmations)
  1623.  
  1624. if old_confirmations < confirmations:
  1625. update_recieve_transaction_eth_model(email_id, to_address, from_address, value, txid, confirmations,
  1626. erc_address, erc_wallet)
  1627.  
  1628. send_mail_flag = insert_eth_transaction_in_user_timeline(email_id, to_address, from_address, value,
  1629. txid, confirmations)
  1630.  
  1631. if send_mail_flag:
  1632. ref_id, name = get_referral_details_model(to_address, 'eth')
  1633. calc_referal_bonus_auxledger(ref_id, value, name, 'eth', to_address, txid, email_id)
  1634.  
  1635. no_of_token_allocated, exchange_rate = models.get_no_of_token_allocated(email_id, txid)
  1636. print "sending received email"
  1637. try:
  1638. send_confirmation_mail(email_id, no_of_token_allocated, value, 'ETH')
  1639. except Exception as e:
  1640. print "send mail error", e
  1641.  
  1642. return HttpResponse('OK')
  1643.  
  1644. print "doing nothing"
  1645. return HttpResponse('ok')
  1646.  
  1647.  
  1648. def refund_eth(from_address, to_address, amount, fee, refund_type):
  1649. print 'refunding etherr from address::: %s, to address:: %s, amount::: %s, fee::: %s' % (
  1650. from_address, to_address, amount, fee)
  1651. timestamp = str(int(time.time()))
  1652. signature = calculate_signature('token_baazar_staging', 'abcd', timestamp)
  1653. eth_send_dict = {
  1654. 'user': eth_user,
  1655. 'token': eth_token,
  1656. 'from_address': from_address,
  1657. 'to_address': to_address,
  1658. 'ethers': float(amount),
  1659. 'timestamp': timestamp,
  1660. 'signature': signature
  1661. }
  1662. eth_forward_res = requests.post(forward_eth_url, data=json.dumps(eth_send_dict))
  1663. if eth_forward_res.status_code == 200:
  1664. eth_transaction_details = json.loads(eth_forward_res.text)
  1665. if eth_transaction_details['code'] == 200:
  1666. print 'status code:: 200, eth transaction successful'
  1667. txid = eth_transaction_details['transaction_hash']
  1668. eth_refund_dict = {
  1669. 'from_address': from_address,
  1670. 'refund_address': to_address,
  1671. 'txid': txid,
  1672. 'transaction_fee': fee,
  1673. 'amount_refunded': float(amount) - float(fee),
  1674. 'timestamp': int(time.time()),
  1675. 'refund_type': refund_type,
  1676. 'currency': 'eth'
  1677. }
  1678. insert_successful_eth_refund(eth_refund_dict)
  1679. else:
  1680. print 'status not 200::: eth transaction unsuccessful'
  1681. eth_refund_dict = {
  1682. 'from_address': from_address,
  1683. 'refund_address': to_address,
  1684. 'amount_to_refund': amount,
  1685. 'timestamp': int(time.time()),
  1686. 'refund_type': refund_type,
  1687. 'currency': 'eth'
  1688. }
  1689. insert_unsuccessful_eth_refund(eth_refund_dict)
  1690. else:
  1691. print 'eth_auxpay error::: '
  1692. eth_refund_dict = {
  1693. 'from_address': from_address,
  1694. 'refund_address': to_address,
  1695. 'amount_to_refund': amount,
  1696. 'timestamp': int(time.time()),
  1697. 'refund_type': refund_type,
  1698. 'currency': 'eth'
  1699. }
  1700. insert_unsuccessful_eth_refund(eth_refund_dict)
  1701.  
  1702.  
  1703. def calculate_signature(user, token, timestamp):
  1704. salt = '007d8f8604acef969b08a2a63819ac0323b447bedd5d14596b86137db23be379'
  1705. signature_json = {
  1706. 'timestamp': timestamp,
  1707. 'user': user,
  1708. 'token': token,
  1709. }
  1710. tmp_list = []
  1711. for param, value in signature_json:
  1712. tmp_list.append(param + '=' + value)
  1713. tmp_list.sort()
  1714. signature_str = ''
  1715. for key in tmp_list:
  1716. signature_str += key + ','
  1717. signature_str = signature_str[0:len(signature_str) - 1]
  1718. signature = hmac.new(salt, signature_str, hashlib.sha256).hexdigest()
  1719. return signature
  1720.  
  1721.  
  1722. # Admin module
  1723.  
  1724. @csrf_exempt
  1725. def sign_in(request):
  1726. print("---------admin_signIn-------->")
  1727. data = json.loads(request.body)
  1728. if request.method == 'POST':
  1729. email = data['email']
  1730. password = data['password']
  1731.  
  1732. status = admin_vefificatoin(email, password)
  1733. if status:
  1734. # otp = str(randint(111111, 999999))
  1735. # m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
  1736. # print 'sending mail to admin::: '
  1737. # email_dict = {
  1738. # "to": {email: email},
  1739. # "from": ["support@auxledger.org"],
  1740. # "subject": "LOGIN OTP",
  1741. # "html": "Admin OTP is " + otp
  1742. # }
  1743. # result = m.send_email(email_dict)
  1744. # print 'email response %s' % result
  1745. # if result['code'] == "success":
  1746. # otp_session(email, otp)
  1747. # print 'mail sent response ::::::: %s' % result
  1748. return JsonResponse({"code": 200, 'success': 'mail sent'})
  1749.  
  1750. else:
  1751. return JsonResponse({'code': 400, 'failed': 'no data found'})
  1752. return JsonResponse({'response': 'get request'})
  1753.  
  1754.  
  1755. @csrf_exempt
  1756. def verify_admin_otp(request): ##email and otp is taken from front end
  1757. print "inside admin otp "
  1758. data = json.loads(request.body)
  1759. email = data['email']
  1760. otp_ = data['otp']
  1761. flag = otp_verification(email, otp_)
  1762. if flag == 1:
  1763. unique_id = create_jwt(email)
  1764. save_uuid(unique_id, email)
  1765. role = get_admin_role(email)
  1766. return JsonResponse({"code": 200, "otp": "verified", 'token': unique_id, 'role': role})
  1767. else:
  1768. return JsonResponse({"code": 400, "otp": "not_verified"})
  1769.  
  1770.  
  1771. @csrf_exempt
  1772. @TokenValidatorMiddleware
  1773. @JWTMiddleware
  1774. def admin_dashboard(request):
  1775. try:
  1776. data = json.loads(request.body)
  1777. email = data['email']
  1778. data = admin_dashboard_data()
  1779. if data:
  1780. data['code'] = 200
  1781. return JsonResponse(data)
  1782. else:
  1783. return JsonResponse({'code':400,'msg':'server error'})
  1784. except Exception as e:
  1785. print e
  1786.  
  1787.  
  1788. @csrf_exempt
  1789. @TokenValidatorMiddleware
  1790. @JWTMiddleware
  1791. def get_withdrawal_details_admin(request):
  1792. data = json.loads(request.body)
  1793. email = data['email']
  1794. uuid_flag = 1
  1795. if uuid_flag == 1:
  1796. res = get_withdrawal_details_admin_model()
  1797. list_to_send = []
  1798. for data in res:
  1799. data['_id'] = str(data['_id'])
  1800. list_to_send.append(data)
  1801. return JsonResponse({'code': 200, 'withdrawal_list': list_to_send})
  1802. else:
  1803. return JsonResponse({'code': 401, 'token_match': False})
  1804.  
  1805.  
  1806. @csrf_exempt
  1807. @TokenValidatorMiddleware
  1808. @JWTMiddleware
  1809. def user_verify(request):
  1810. data = json.loads(request.body)
  1811. user_email = data['useremail']
  1812. email = data['email']
  1813. uuid_flag = 1
  1814. if uuid_flag == 1:
  1815. kyc_status_verify(user_email)
  1816. enter_kyc_accept_in_user_time(email)
  1817. return JsonResponse({"code": 200, "verified-documents": "true", 'status': 'accepted'})
  1818. else:
  1819. return JsonResponse({'code': 401, 'token_match': False})
  1820.  
  1821.  
  1822. @csrf_exempt
  1823. @TokenValidatorMiddleware
  1824. @JWTMiddleware
  1825. def user_reject(request): ##only update status:rejected
  1826. data = json.loads(request.body)
  1827. email = data['email']
  1828. user_email = data['useremail']
  1829. uuid_flag = 1
  1830. if uuid_flag == 1:
  1831. reason = data['reason']
  1832. kyc_status_reject(user_email, reason)
  1833. enter_kyc_reject_in_user_time(email)
  1834. return JsonResponse({"code": 200, "verified-documents": "true", 'status': 'rejected'})
  1835. else:
  1836. return JsonResponse({'code': 401, 'token_match': False})
  1837.  
  1838.  
  1839. @csrf_exempt
  1840. @TokenValidatorMiddleware
  1841. @JWTMiddleware
  1842. def get_all_users(request):
  1843. data = json.loads(request.body)
  1844. email = data['email']
  1845. uuid_flag = 1
  1846. if uuid_flag == 1:
  1847. user_list = []
  1848. res = get_all_users_model()
  1849. for data in res:
  1850. user_list.append(data)
  1851. return JsonResponse({'code': 200, 'users_list': user_list})
  1852. else:
  1853. return JsonResponse({'code': 401, 'token_match': False})
  1854.  
  1855.  
  1856. @csrf_exempt
  1857. @TokenValidatorMiddleware
  1858. @JWTMiddleware
  1859. def display_pending(request): ##only update status:rejected
  1860. data = json.loads(request.body)
  1861. email = data['email']
  1862. uuid_flag = 1
  1863. if uuid_flag == 1:
  1864. if data.__contains__('page'):
  1865. page = int(data['page'])
  1866. else:
  1867. page = 1
  1868.  
  1869. res, count = show_pending_model(page)
  1870. return_list = []
  1871. for data in res:
  1872. pan_id = data['kyc']['pan_card_details']
  1873. aadhar_id = data['kyc']['aadhar_card_details']
  1874.  
  1875. # pan_card_details = ast.literal_eval(bucket.get_key(pan_id).get_contents_as_string())
  1876. # aadhar_card_details = ast.literal_eval(bucket.get_key(aadhar_id).get_contents_as_string())
  1877.  
  1878. file_loc = '/var/www/ico_with_bid/media/kyc/'
  1879.  
  1880. get_user_details = user_kyc_details_model(0, **{"email": data['email']})
  1881. return_list.append({'user_details': get_user_details, 'kyc': {'pan_card_details': file_loc+pan_id,
  1882. 'aadhar_card_details': file_loc+aadhar_id},
  1883. 'email': data['email']})
  1884. # return_list.append(data['email'])
  1885. return JsonResponse({'code': 200, 'kyc_list': return_list, 'total_pending': count})
  1886. else:
  1887. return JsonResponse({'code': 401, 'token_match': False})
  1888.  
  1889.  
  1890. @csrf_exempt
  1891. # @TokenValidatorMiddleware
  1892. # @JWTMiddleware
  1893. def user_kyc_details(request):
  1894. data = json.loads(request.body)
  1895. email = data['email']
  1896. uuid_flag = 1
  1897. if uuid_flag == 1:
  1898. kyc_details = get_user_kyc_details_model(email)
  1899. pan_id = kyc_details['kyc']['pan_card_details']
  1900. aadhar_id = kyc_details['kyc']['aadhar_card_details']
  1901. # pan_card_details = ast.literal_eval(bucket.get_key(pan_id).get_contents_as_string())
  1902. # aadhar_card_details = ast.literal_eval(bucket.get_key(aadhar_id).get_contents_as_string())
  1903. get_user_details = user_kyc_details_model(0, **{"email": email})
  1904. return JsonResponse({'code': 200, 'user_details': get_user_details, 'kyc_details': {
  1905. 'kyc': {'pan_card_details': pan_id, 'aadhar_card_details': aadhar_id,
  1906. 'status': kyc_details['kyc']['status']}}})
  1907. else:
  1908. return JsonResponse({'code': 401, 'token_match': False})
  1909.  
  1910.  
  1911. @csrf_exempt
  1912. @TokenValidatorMiddleware
  1913. @JWTMiddleware
  1914. def display_accepted(request):
  1915. data = json.loads(request.body)
  1916. email = data['email']
  1917. uuid_flag = 1
  1918. if uuid_flag == 1:
  1919. page = data['page']
  1920. res, count = show_accepted_model(page)
  1921. return_list = []
  1922. for data in res:
  1923. # print 'ddd:: %s' %data
  1924. pan_id = data['kyc']['pan_card_details']
  1925. aadhar_id = data['kyc']['aadhar_card_details']
  1926. if pan_id and aadhar_id:
  1927. pan_card_details = ast.literal_eval(bucket.get_key(pan_id).get_contents_as_string())
  1928. aadhar_card_details = ast.literal_eval(bucket.get_key(aadhar_id).get_contents_as_string())
  1929. # print '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ %s,%s,%s,%s' %(pan_id,aadhar_id,pan_card_details,aadhar_card_details)
  1930. get_user_details = user_kyc_details_model(0, **{"email": email})
  1931. return_list.append({'user_details': get_user_details, 'kyc': {'pan_card_details': pan_card_details,
  1932. 'aadhar_card_details': aadhar_card_details},
  1933. 'email': data['email']})
  1934. # return_list.append(data['email'])
  1935. return JsonResponse({'code': 200, 'kyc_list': return_list, "total_accepted": count})
  1936. else:
  1937. return JsonResponse({'code': 401, 'token_match': False})
  1938.  
  1939.  
  1940. @csrf_exempt
  1941. @TokenValidatorMiddleware
  1942. @JWTMiddleware
  1943. def display_rejected(request):
  1944. data = json.loads(request.body)
  1945. email = data['email']
  1946. uuid_flag = 1
  1947. if uuid_flag == 1:
  1948. page = data['page']
  1949. res, count = show_rejected_model(page)
  1950. return_list = []
  1951. for data in res:
  1952. # print 'ddd:: %s' %data
  1953. pan_id = data['kyc']['pan_card_details']
  1954. aadhar_id = data['kyc']['aadhar_card_details']
  1955. pan_card_details = ast.literal_eval(bucket.get_key(pan_id).get_contents_as_string())
  1956. aadhar_card_details = ast.literal_eval(bucket.get_key(aadhar_id).get_contents_as_string())
  1957. get_user_details = user_kyc_details_model(0, **{"email": email})
  1958. return_list.append({'user_details': get_user_details, 'kyc': {'pan_card_details': pan_card_details,
  1959. 'aadhar_card_details': aadhar_card_details},
  1960. 'email': data['email']})
  1961. # return_list.append({'kyc':data['kyc'],'email':data['email']})
  1962. # return_list.append(data['email'])
  1963. return JsonResponse({'code': 200, 'kyc_list': return_list, "total_rejected_data": count})
  1964. else:
  1965. return JsonResponse({'code': 401, 'token_match': False})
  1966.  
  1967.  
  1968. '''{
  1969.  
  1970. "token":"asdfasdf",
  1971. "admin_email":asdf
  1972. "user_email":asdf
  1973.  
  1974. }'''
  1975.  
  1976.  
  1977. @csrf_exempt
  1978. @TokenValidatorMiddleware
  1979. @JWTMiddleware
  1980. def show_single_kyc(request):
  1981. data = json.loads(request.body)
  1982. admin_email = data['admin_email']
  1983. uuid_flag = 1
  1984. if uuid_flag == 1:
  1985. user_email = data['user_email']
  1986. res = show_single_kyc_model(user_email)
  1987. return_list = []
  1988. for data in res:
  1989. pan_id = data['kyc']['pan_card_details']
  1990. aadhar_id = data['kyc']['aadhar_card_details']
  1991. pan_card_details = ast.literal_eval(bucket.get_key(pan_id).get_contents_as_string())
  1992. aadhar_card_details = ast.literal_eval(bucket.get_key(aadhar_id).get_contents_as_string())
  1993. get_user_details = user_kyc_details_model(0, **{"email": user_email})
  1994. return_list.append({'user_details': get_user_details, 'kyc': {'pan_card_details': pan_card_details,
  1995. 'aadhar_card_details': aadhar_card_details},
  1996. 'email': data['email']})
  1997.  
  1998. return JsonResponse({'code': 200, 'kyc_list': return_list})
  1999. # return JsonResponse({'kyc':{'pan_card_details':pan_card_details,'aadhar_card_details':aadhar_card_details},'email':data['email'],'code':200})
  2000. else:
  2001. return JsonResponse({'code': 500, 'response': 'uuid_failed_to_verify'})
  2002.  
  2003.  
  2004. @csrf_exempt
  2005. @TokenValidatorMiddleware
  2006. @JWTMiddleware
  2007. def bank_transfer(request):
  2008. if request.method == "POST":
  2009. data = json.loads(request.body)
  2010. email = data['email']
  2011. uuid_flag = 1
  2012. if uuid_flag == 1:
  2013. method = data['deposit_method']
  2014. amount_deposited = data['amount_deposited']
  2015. bank_name = data['bank']
  2016. trans_id = data['trans_id']
  2017. admin_amount = data['admin_amount']
  2018. date_time = data['date_time']
  2019. transaction_list = {"payment_method": method, "amount_deposited": amount_deposited, "bank_name": bank_name,
  2020. "trans_id": trans_id, "admin_amount": admin_amount, "date_time": date_time}
  2021. bank_transfer_model(transaction_list)
  2022. return JsonResponse({"code": 200, "status": 'success'})
  2023. else:
  2024. return JsonResponse({'code': 401, 'token_match': False})
  2025.  
  2026.  
  2027. @csrf_exempt
  2028. @TokenValidatorMiddleware
  2029. @JWTMiddleware
  2030. def bank_detail(request): ##this is for super users
  2031. data = json.loads(request.body)
  2032. email = data['email']
  2033. uuid_flag = 1
  2034. if uuid_flag == 1:
  2035. bank_name = data['bank_name'] if data['bank_name'] else False
  2036. account_holder_name = data['account_holder_name'] if data['account_holder_name'] else False
  2037. ifsc = data['ifsc'] if data['ifsc'] else False
  2038. account_no = data['account_no'] if data['account_no'] else False
  2039. account_type = data['account_type'] if data['account_type'] else False
  2040. bank_type = data["bank_type"] if data["bank_type"] else False
  2041. swift_code = data["swift_code"] if data["swift_code"] else False
  2042. iban_number = data["iban_number"] if data["iban_number"] else False
  2043.  
  2044. bank_details = {"iban_number": iban_number, "swift_code": swift_code, "bank_type": bank_type,
  2045. "bank_name": bank_name, "account_holder_name": account_holder_name, "ifsc": ifsc,
  2046. "account_no": account_no, "account_type": account_type}
  2047. bank_detail_model(bank_details)
  2048. return JsonResponse({"code": 200, "status": 'success'})
  2049. else:
  2050. return JsonResponse({'code': 400, 'token_match': False})
  2051.  
  2052.  
  2053. @csrf_exempt
  2054. @TokenValidatorMiddleware
  2055. @JWTMiddleware
  2056. def fetch_bank_detail(request):
  2057. data = json.loads(request.body)
  2058. email = data['email']
  2059. uuid_flag = 1
  2060. if uuid_flag == 1:
  2061. db_resp = fetch_bank_detail_model()
  2062. if db_resp:
  2063. return JsonResponse({"code": 200, "bank_detail": db_resp})
  2064. else:
  2065. return JsonResponse({"code": 400, "status": "failure"})
  2066. else:
  2067. return JsonResponse({"code": 400, "message": "verification failed"})
  2068.  
  2069.  
  2070. # @csrf_exempt
  2071. # def rate_conversion(request): #udashi
  2072. # if request.method =='POST':
  2073. # data = json.loads(request.body)
  2074. # btc_eqval = data['btc']
  2075. # eth_eqval = data['eth']
  2076. # fiat_eqval = data['fiat']
  2077. # # token = data['token']
  2078. # timestamp = int(time.time())
  2079. # i=0
  2080. # while i < 3:
  2081. # if i == 0:
  2082. # curr = "btc"
  2083. # val = btc_eqval
  2084. # elif i == 1:
  2085. # curr = "eth"
  2086. # val = eth_eqval
  2087. # else:
  2088. # curr = "fiat"
  2089. # val = fiat_eqval
  2090. # input_json = {"currency":curr,"value":val,"from_timestamp":timestamp,"current":True}
  2091. # rate_conversion_model(input_json)
  2092. # i += 1
  2093.  
  2094. @csrf_exempt
  2095. @TokenValidatorMiddleware
  2096. @JWTMiddleware
  2097. def set_default_rate(request):
  2098. print 'setting default rate:::: '
  2099. data = json.loads(request.body)
  2100. email = data['email']
  2101. uuid_flag = 1
  2102. if uuid_flag == 1:
  2103. default_btc = float(data['default_btc'])
  2104. default_eth = float(data['default_eth'])
  2105. default_fiat = float(data['default_fiat'])
  2106. default_min_cap = float(data['default_min_cap'])
  2107. default_max_cap = float(data['default_max_cap'])
  2108. res = insert_default_rate(default_btc, default_eth, default_fiat)
  2109. res = set_default_cap_model(default_min_cap, default_max_cap)
  2110. return JsonResponse({'success': True})
  2111. else:
  2112. return JsonResponse({'code': 401, 'token_match': False})
  2113.  
  2114.  
  2115. @csrf_exempt
  2116. @TokenValidatorMiddleware
  2117. @JWTMiddleware
  2118. def update_default_rate(request):
  2119. print 'updating default rate:::: '
  2120. data = json.loads(request.body)
  2121. data = json.loads(request.body)
  2122. email = data['email']
  2123. uuid_flag = 1
  2124. if uuid_flag == 1:
  2125. default_btc = float(data['default_btc'])
  2126. default_eth = float(data['default_eth'])
  2127. default_fiat = float(data['default_fiat'])
  2128. default_min_cap = float(data['default_min_cap'])
  2129. default_max_cap = float(data['default_max_cap'])
  2130. res = update_default_rate_model(default_btc, default_eth, default_fiat)
  2131. res = update_default_cap_model(default_min_cap, default_max_cap)
  2132. return JsonResponse({'success': True})
  2133. else:
  2134. return JsonResponse({'code': 401, 'token_match': False})
  2135.  
  2136.  
  2137. @csrf_exempt
  2138. @TokenValidatorMiddleware
  2139. @JWTMiddleware
  2140. def set_rate(request):
  2141. print 'setting rate:::: '
  2142. data = json.loads(request.body)
  2143. email = data['email']
  2144. uuid_flag = 1
  2145. if uuid_flag == 1:
  2146. from_date = data['from_date']
  2147. to_date = data['to_date']
  2148. btc_value = data['btc_value']
  2149. eth_value = data['eth_value']
  2150. fiat_value = data['fiat_value']
  2151. min_cap = data['min_fiat_amount']
  2152. max_cap = data['max_fiat_amount']
  2153. res = insert_set_rate_model(from_date, to_date, btc_value, eth_value, fiat_value)
  2154. res1 = set_cap_model(from_date, to_date, min_cap, max_cap)
  2155. return JsonResponse({'success': True})
  2156. else:
  2157. return JsonResponse({'code': 401, 'token_match': False})
  2158.  
  2159.  
  2160. @csrf_exempt
  2161. @TokenValidatorMiddleware
  2162. @JWTMiddleware
  2163. def return_rates(request):
  2164. print 'return rates:::: '
  2165. req_data = json.loads(request.body)
  2166. email = req_data['email']
  2167. uuid_flag = 1
  2168. if uuid_flag == 1:
  2169. default_rates_list = []
  2170. rates_list = []
  2171. # default_caps_list = []
  2172. # caps_list = []
  2173. default_rates = get_default_rates()
  2174. default_caps = get_default_caps()
  2175. if default_rates is None:
  2176. return JsonResponse({'error': 'default_rates_is_not_set'})
  2177. default_dict = {
  2178. 'btc': default_rates['default_btc'],
  2179. 'eth': default_rates['default_eth'],
  2180. 'fiat': default_rates['default_fiat'],
  2181. 'min_cap': default_caps['default_min_cap'],
  2182. 'max_cap': default_caps['default_max_cap']
  2183. }
  2184. default_rates_list.append(default_dict)
  2185. rates = get_rates()
  2186. for data in rates:
  2187. append_dict = {
  2188. 'id': str(data['_id']),
  2189. 'from_date': data['from_date'],
  2190. 'to_date': data['to_date'],
  2191. 'btc': data['btc'],
  2192. 'eth': data['eth'],
  2193. 'fiat': data['fiat']
  2194. }
  2195. rates_list.append(append_dict)
  2196. caps_list = []
  2197. caps = get_caps()
  2198. for data in caps:
  2199. append_dict = {
  2200. 'id': str(data['_id']),
  2201. 'from_date': data['from_date'],
  2202. 'to_date': data['to_date'],
  2203. 'min_cap': data['min_cap'],
  2204. 'max_cap': data['max_cap']
  2205. }
  2206. caps_list.append(append_dict)
  2207.  
  2208. return JsonResponse({'default_list': default_rates_list, 'rates_list': rates_list, 'caps_list': caps_list})
  2209. else:
  2210. return JsonResponse({'code': 401, 'token_match': False})
  2211.  
  2212.  
  2213. @csrf_exempt
  2214. @TokenValidatorMiddleware
  2215. @JWTMiddleware
  2216. def delete_rates(request):
  2217. data = json.loads(request.body)
  2218. _id = data['_id']
  2219. email = data['email']
  2220. uuid_flag = 1
  2221. if uuid_flag == 1:
  2222. res = remove_rate_model(_id)
  2223. return JsonResponse({'success': True})
  2224. else:
  2225. return JsonResponse({'code': 401, 'token_match': False})
  2226.  
  2227.  
  2228. @csrf_exempt
  2229. @TokenValidatorMiddleware
  2230. @JWTMiddleware
  2231. def update_rates(request):
  2232. data = json.loads(request.body)
  2233. _id = data['_id']
  2234. email = data['email']
  2235. uuid_flag = 1
  2236. if uuid_flag == 1:
  2237. update_dict = {}
  2238. if 'new_from_date' in data:
  2239. update_dict['from_date'] = data['new_from_date']
  2240. if 'new_to_date' in data:
  2241. update_dict['to_date'] = data['new_to_date']
  2242. if 'new_btc' in data:
  2243. update_dict['btc'] = data['new_btc']
  2244. if 'new_eth' in data:
  2245. update_dict['eth'] = data['new_eth']
  2246. if 'new_fiat' in data:
  2247. update_dict['fiat'] = data['new_fiat']
  2248. res = update_rates_model(_id, update_dict)
  2249. min_cap = data['min_fiat_amount']
  2250. max_cap = data['max_fiat_amount']
  2251. res1 = set_cap_model(min_cap, max_cap)
  2252. return JsonResponse({'success': True})
  2253. else:
  2254. return JsonResponse({'code': 401, 'token_match': False})
  2255.  
  2256.  
  2257. @csrf_exempt
  2258. @TokenValidatorMiddleware
  2259. @JWTMiddleware
  2260. def set_cap(request):
  2261. data = json.loads(request.body)
  2262. email = data['email']
  2263. uuid_flag = 1
  2264. if uuid_flag == 1:
  2265. min_cap = data['min_fiat_amount']
  2266. max_cap = data['max_fiat_amount']
  2267. from_date = data['from_date']
  2268. to_date = data['to_date']
  2269. res = set_cap_model(from_date, to_date, min_cap, max_cap)
  2270. return JsonResponse({'success': True})
  2271. else:
  2272. return JsonResponse({'code': 401, 'token_match': False})
  2273.  
  2274.  
  2275. @csrf_exempt
  2276. @TokenValidatorMiddleware
  2277. @JWTMiddleware
  2278. def update_cap(request):
  2279. data = json.loads(request.body)
  2280. email = data['email']
  2281. uuid_flag = 1
  2282. if uuid_flag == 1:
  2283. min_cap = data['min_fiat_amount']
  2284. max_cap = data['max_fiat_amount']
  2285. res = update_cap_model(min_cap, max_cap)
  2286. return JsonResponse({'success': True})
  2287. else:
  2288. return JsonResponse({'code': 401, 'token_match': False})
  2289.  
  2290.  
  2291. # @csrf_exempt
  2292. # def validate_token_amount(request):
  2293. # data = json.loads(request.body)
  2294. # token_amount = data['token_amount']
  2295. # email = data['email']
  2296. # unique_id = data['token']
  2297. # uuid_flag = uuid_verification(unique_id,email)
  2298. # if uuid_flag == 1:
  2299. # currency = data['currency']
  2300. # fiat_rate = get_price(token_amount,currency)[1]
  2301. # # return JsonResponse({'valid':True})
  2302. # print 'ffff %s' %fiat_rate
  2303. # if fiat_rate >= 20:
  2304. # return JsonResponse({'valid':True})
  2305. # else:
  2306. # return JsonResponse({'valid':False})
  2307. # else:
  2308. # return JsonResponse({"code":401,"token_match":False})
  2309.  
  2310. @csrf_exempt
  2311. @TokenValidatorMiddleware
  2312. @JWTMiddleware
  2313. def validate_fiat_amount(request):
  2314. data = json.loads(request.body)
  2315. email = data['email']
  2316. fiat_amount = data['fiat_amount']
  2317. uuid_flag = 1
  2318. if uuid_flag == 1:
  2319. min_cap, max_cap = get_cap(int(time.time()))
  2320. if fiat_amount >= min_cap and fiat_amount <= max_cap:
  2321. return JsonResponse({'valid': True})
  2322. else:
  2323. return JsonResponse({'valid': False})
  2324. else:
  2325. return JsonResponse({'code': 401, 'token_match': False})
  2326.  
  2327.  
  2328. def send_zero_confirmation_mail(email, value, currency, txid, exchange_rate):
  2329. m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
  2330. data = { "id" : 39,
  2331. "to" : {email: email},
  2332. "replyto" : "support@auxledger.org",
  2333. "attr" : {"value": str(value), "currency": currency, "txid": txid, "exchange_rate": str(exchange_rate)},
  2334. "headers" : {"Content-Type": "text/html;charset=iso-8859-1"}
  2335. }
  2336. result = m.send_transactional_template(data)
  2337. print result
  2338.  
  2339.  
  2340. @csrf_exempt
  2341. @TokenValidatorMiddleware
  2342. @JWTMiddleware
  2343. def set_btc_refund_address(request):
  2344. data = json.loads(request.body)
  2345. email = data['email']
  2346. uuid_flag = 1
  2347. if uuid_flag == 1:
  2348. refund_btc_address = data['refund_btc_address']
  2349. btc_address_validation = validate_btc_address(refund_btc_address)
  2350. if btc_address_validation is False:
  2351. return JsonResponse({'code': 401, 'address_validation': False})
  2352. res = set_btc_refund_address_model(email, refund_btc_address)
  2353. return JsonResponse({'code': 200, 'address_validation': True})
  2354. else:
  2355. return JsonResponse({"code": 401, "token_match": False})
  2356.  
  2357.  
  2358. @csrf_exempt
  2359. @TokenValidatorMiddleware
  2360. @JWTMiddleware
  2361. def set_btc_eth_refund_address(request):
  2362. data = json.loads(request.body)
  2363. email = data['email']
  2364. uuid_flag = 1
  2365. if uuid_flag == 1:
  2366.  
  2367. refund_btc_address = data['refund_btc_address']
  2368.  
  2369. btc_address_validation = validate_btc_address(refund_btc_address)
  2370.  
  2371. if btc_address_validation is False:
  2372. return JsonResponse({'code': 400, 'btc_address_validation': False})
  2373.  
  2374. res = set_btc_refund_address_model(email, refund_btc_address)
  2375.  
  2376. refund_eth_address = data['refund_eth_address']
  2377. eth_address_validation = validate_eth_address(refund_eth_address)
  2378.  
  2379. if eth_address_validation is False:
  2380. return JsonResponse({'code': 400, 'eth_address_validation': False})
  2381. res = set_eth_refund_address_model(email, refund_eth_address)
  2382.  
  2383. return JsonResponse({'code': 200, 'address_validation': True})
  2384. else:
  2385. return JsonResponse({"code": 401, "token_match": False})
  2386.  
  2387.  
  2388. @csrf_exempt
  2389. @TokenValidatorMiddleware
  2390. @JWTMiddleware
  2391. def set_eth_refund_address(request):
  2392. data = json.loads(request.body)
  2393. email = data['email']
  2394. uuid_flag = 1
  2395. if uuid_flag == 1:
  2396. refund_eth_address = data['refund_eth_address']
  2397. eth_address_validation = validate_eth_address(refund_eth_address)
  2398. if eth_address_validation is False:
  2399. return JsonResponse({'code': 401, 'address_validation': False})
  2400. res = set_eth_refund_address_model(email, refund_eth_address)
  2401. return JsonResponse({'code': 200, 'address_validation': True})
  2402. else:
  2403. return JsonResponse({"code": 401, "token_match": False})
  2404.  
  2405.  
  2406. @csrf_exempt
  2407. # @TokenValidatorMiddleware
  2408. # @JWTMiddleware
  2409. def get_confirmed_transactions(request):
  2410. data = json.loads(request.body)
  2411. email = data['email']
  2412. uuid_flag = 1
  2413. if uuid_flag == 1:
  2414. send_list = []
  2415. res = get_confirmed_transaction_details()
  2416. for data in res:
  2417. send_list.append(data)
  2418. return JsonResponse(
  2419. {"code": 200, 'transaction_list': send_list, 'btc_usd': get_btc_to_usd(), 'eth_usd': get_eth_to_usd()})
  2420. else:
  2421. return JsonResponse({"code": 401, "token_match": False})
  2422.  
  2423.  
  2424. @csrf_exempt
  2425. def get_total_tokens_sold(request):
  2426. res = get_confirmed_transaction_details()
  2427. sold_tokens = 0.0
  2428. for data in res:
  2429. if data.__contains__('no_of_tokens'):
  2430. sold_tokens += float(data['no_of_tokens'])
  2431. # current_rate = get_current_rate(sold_tokens)
  2432. # sold_tokens = 21312
  2433. return JsonResponse({'sold_tokens': round(sold_tokens,3)})
  2434.  
  2435.  
  2436. '''
  2437. ip:
  2438.  
  2439. {
  2440. "unique_id":"token",
  2441. "from":"from_date", #epoch_format
  2442. "to":"to-date",# #epoch_format
  2443. "type":"detail/summary"
  2444. }
  2445.  
  2446. op:
  2447. [{ "currency" : "usd", "email" : "parishilanrayamajhi@gmail.com", "epoch" : "1526807413", "no_of_tokens" : "23", "txid" : "sssssssssssssssss", "value" : "45" },{},{}]
  2448.  
  2449. '''
  2450.  
  2451. '''
  2452.  
  2453. {
  2454. "btc_value":512,
  2455. "eth-value"4545,
  2456. "btc_usd_eq":121,
  2457. "btc_eth_eq":121,
  2458. "cas_token":112
  2459. }
  2460.  
  2461. '''
  2462.  
  2463.  
  2464. @csrf_exempt
  2465. @TokenValidatorMiddleware
  2466. @JWTMiddleware
  2467. def graph_tokens_sold(request):
  2468. try:
  2469. data = json.loads(request.body)
  2470. # print data
  2471. # email = data['email']
  2472. # unique_id = data['token']
  2473. # uuid_flag = uuid_verification(unique_id,email)
  2474. uuid_flag = 1
  2475. if uuid_flag == 1:
  2476. from_date = int(data["from"])
  2477. to_date = int(data["to"])
  2478. to_date += 86399
  2479. res = get_confirmed_transaction_details_graph(from_date, to_date)
  2480. for data in res:
  2481. print data
  2482. except Exception as e:
  2483. exc_type, exc_obj, exc_tb = sys.exc_info()
  2484. fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
  2485. print(exc_type, fname, exc_tb.tb_lineno, e.message)
  2486. return JsonResponse({"status_code": 400, "reach": "exception"})
  2487.  
  2488.  
  2489. @csrf_exempt
  2490. @TokenValidatorMiddleware
  2491. @JWTMiddleware
  2492. def get_data_from_to_date(request):
  2493. if request.method == "POST":
  2494. try:
  2495. data = json.loads(request.body)
  2496. email = data['email']
  2497. uuid_flag = 1
  2498. if uuid_flag == 1:
  2499. from_date = int(data["from"])
  2500. to_date = int(data["to"])
  2501. to_date += 86399
  2502. type_ = data["type"] if data["type"] else "NA"
  2503. if type_ == "detail":
  2504. data = get_detail_data_from_to_date_model(from_date, to_date)
  2505. # print data
  2506. return JsonResponse({"detail_report": data, "code": 200})
  2507. elif type_ == "summary":
  2508. url = "https://api.coinmarketcap.com/v2/ticker/?convert=BTC&limit=5"
  2509. resp = (requests.get(url)).json()
  2510. btc_usd_rate = float(resp["data"]["1"]["quotes"]["USD"]["price"])
  2511. eth_usd_rate = float(resp["data"]["1027"]["quotes"]["USD"]["price"])
  2512. btc_value, eth_value, cas_token = get_summary_data_from_to_date_model(from_date, to_date)
  2513. btc_usd_value = btc_usd_rate * btc_value
  2514. eth_usd_value = eth_usd_rate * eth_value
  2515. ret_json = {}
  2516. ret_json["btc_value"] = btc_value
  2517. ret_json["eth_value"] = eth_value
  2518. ret_json["btc_usd_eq"] = btc_usd_value
  2519. ret_json["btc_eth_eq"] = eth_usd_value
  2520. ret_json["cas_token"] = cas_token
  2521. return JsonResponse({"data": ret_json, "code": 200})
  2522. else:
  2523. return JsonResponse({"type": "not defined", "status": 500})
  2524. else:
  2525. return JsonResponse({"uuid_verification": "false"})
  2526.  
  2527. except Exception as e:
  2528. exc_type, exc_obj, exc_tb = sys.exc_info()
  2529. fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
  2530. print(exc_type, fname, exc_tb.tb_lineno, e.message)
  2531. return JsonResponse({"status_code": 400, "reach": "exception"})
  2532. else:
  2533. return JsonResponse({"status": "bad_request"})
  2534.  
  2535.  
  2536.  
  2537. @csrf_exempt
  2538. @TokenValidatorMiddleware
  2539. @JWTMiddleware
  2540. def init_withdraw(request):
  2541. data = json.loads(request.body)
  2542. email = data['email']
  2543. uuid_flag = 1
  2544. if uuid_flag == 1:
  2545. currency = data['currency']
  2546. if currency == 'btc':
  2547. pending_amount = get_pending_amount(email, 'btc')
  2548. refund_address = get_refund_address_using_mail(email, 'btc')
  2549. # fee = calculate_btc_fee(btc_withdraw_address,refund_address,pending_amount)[0]
  2550. # fee = 0.0001
  2551. fee = 0.00040335
  2552. if fee is None:
  2553. return JsonResponse({'code': 400, 'error': 'unable_to_calculate_fee'})
  2554. # return JsonResponse({'code':400,'error':'withdrawal_closed'})
  2555. amount_to_be_paid = pending_amount - fee
  2556. else:
  2557. pending_amount = get_pending_amount(email, 'eth')
  2558. refund_address = get_refund_address_using_mail(email, 'eth')
  2559. eth_fee_res = requests.get(eth_fee_url)
  2560. fee = 0.0005
  2561. # if eth_fee_res.status_code == 200:
  2562. # fee = json.loads(eth_fee_res)['msg']['transaction_fee']
  2563. amount_to_be_paid = pending_amount - fee
  2564. # else:
  2565. # return JsonResponse({'code':400,'error':'unable_to_calculate_fee'})
  2566.  
  2567. send_dict = {
  2568. 'pending_amount': pending_amount,
  2569. 'withdraw_address': refund_address,
  2570. 'fee': fee,
  2571. 'amount_to_be_paid': amount_to_be_paid
  2572. }
  2573. return JsonResponse({'code': 200, 'data': send_dict})
  2574. else:
  2575. return JsonResponse({"code": 401, "token_match": False})
  2576.  
  2577.  
  2578. @csrf_exempt
  2579. @TokenValidatorMiddleware
  2580. @JWTMiddleware
  2581. def send_withdraw_otp(request):
  2582. data = json.loads(request.body)
  2583. email = data['email']
  2584. uuid_flag = 1
  2585. if uuid_flag == 1:
  2586. res = get_otp_str(email, True)
  2587. if not res:
  2588. otp = str(randint(111111, 999999))
  2589. m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
  2590. print 'sending mail to admin::: '
  2591. email_dict = {
  2592. "to": {email: email},
  2593. "from": ["support@auxledger.org"],
  2594. "subject": "OTP for Referral Earned Funds Withdrawal | Auxledger ",
  2595. "html": get_send_withdraw_otp_html(str(otp))
  2596. }
  2597. result = m.send_email(email_dict)
  2598. print 'res::: %s' % result
  2599. if result['code'] == "success":
  2600. otp_session('withdraw_' + email, otp)
  2601. # print 'mail sent response ::::::: %s' % result
  2602. return JsonResponse({"code": 200, 'success': 'mail sent'})
  2603. else:
  2604. return JsonResponse({"code": 200, 'success': 'mail sent'})
  2605. else:
  2606. return JsonResponse({"code": 401, "token_match": False})
  2607.  
  2608.  
  2609. def send_request_for_withdraw_apprroval_mail(email, res1, pending_amount, refund_address, currency):
  2610. m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
  2611. email_dict = {
  2612. "to": {email: email},
  2613. "from": ["support@auxledger.org"],
  2614. "subject": "Referral Earned Funds Withdrawal Request Created | Team Auxledger", # Withdraw referral amount OTP
  2615. "html": get_send_request_for_withdraw_apprroval_mail_html(str(res1), str(round(float(pending_amount), 6)),
  2616. str(refund_address), currency)
  2617. }
  2618. result = m.send_email(email_dict)
  2619. return result
  2620.  
  2621.  
  2622. def send_withdraw_confirm_mail(email, txid, earned_amount, refund_address, currency):
  2623. m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
  2624. email_dict = {
  2625. "to": {email: email},
  2626. "from": ["support@auxledger.org"],
  2627. "subject": "Successful Referral Earned Funds Withdrawal | Auxledger ", # Withdraw referral amount OTP
  2628. "html": get_send_withdraw_confirm_mail_html(txid, earned_amount, refund_address, currency)
  2629. }
  2630. result = m.send_email(email_dict)
  2631. return result
  2632.  
  2633.  
  2634. @csrf_exempt
  2635. @TokenValidatorMiddleware
  2636. @JWTMiddleware
  2637. def confirm_withdraw(request):
  2638. data = json.loads(request.body)
  2639. email = data['email']
  2640. uuid_flag = 1
  2641. if uuid_flag == 1:
  2642. input_otp = data['otp']
  2643. otp_flag = otp_verification('withdraw_' + email, str(input_otp))
  2644. print 'pppp %s,%s,%s' % (input_otp, type(input_otp), otp_flag)
  2645. if otp_flag == 1:
  2646. currency = data['currency']
  2647. pending_amount = get_pending_amount(email, currency)
  2648. res = get_docs_to_spend(email, currency)
  2649. refund_address = get_refund_address_using_mail(email, currency)
  2650. ref_id = get_ref_id(email)
  2651. res1 = insert_into_admin(email, refund_address, currency, pending_amount, ref_id)
  2652. update_spent_flag(res)
  2653. if currency == 'btc':
  2654. result = send_request_for_withdraw_apprroval_mail(email, str(res1), pending_amount, refund_address,
  2655. ' BTC')
  2656. else:
  2657. result = send_request_for_withdraw_apprroval_mail(email, str(res1), pending_amount, refund_address,
  2658. ' ETH')
  2659. # if result['code'] == 'success'
  2660. return JsonResponse({'code': 200, 'msg': 'sent_for_approval'})
  2661. else:
  2662. return JsonResponse({"code": 400, "error": 'otp_mismatch'})
  2663. else:
  2664. return JsonResponse({"code": 401, "token_match": False})
  2665.  
  2666.  
  2667. @csrf_exempt
  2668. @TokenValidatorMiddleware
  2669. @JWTMiddleware
  2670. def approve_withdrawal(request):
  2671. data = json.loads(request.body)
  2672. email = data['email']
  2673. uuid_flag = 1
  2674. if uuid_flag == 1:
  2675. _id = data['_id']
  2676. withdraw_details = get_withdraw_details_from_admin_model(_id)
  2677. currency = withdraw_details['currency']
  2678. refund_address = withdraw_details['refund_address']
  2679. pending_amount = withdraw_details['pending']
  2680. user_email = withdraw_details['email']
  2681. if currency == 'btc':
  2682. fee, btc_bal = calculate_btc_fee(btc_withdraw_address, refund_address, pending_amount)
  2683. print 'btc bal:::,btc fe::: %s,%s,%s' % (btc_bal, fee, pending_amount)
  2684. txid = do_btc_transaction(pending_amount, fee, btc_bal, refund_address)
  2685. if txid is not None:
  2686. update_flag_in_admin_withdrawal(_id, txid)
  2687. send_withdraw_confirm_mail(user_email, txid, pending_amount - fee, refund_address, ' BTC')
  2688. return JsonResponse({'code': 200, 'success': True, 'txid': txid})
  2689. else:
  2690. return JsonResponse({'code': 400, 'error': 'transaction_failed'})
  2691. else:
  2692. eth_fee_res = requests.get(eth_fee_url)
  2693. if eth_fee_res.status_code == 200:
  2694. # fee = json.loads(eth_fee_res)['msg']['transaction_fee']
  2695. fee = 0.0005
  2696. txid = do_eth_transaction(refund_address, pending_amount, fee)
  2697. if txid is not None:
  2698. update_flag_in_admin_withdrawal(_id, txid)
  2699. send_withdraw_confirm_mail(user_email, txid, pending_amount - fee, refund_address, ' ETH')
  2700. return JsonResponse({'code': 200, 'success': True, 'txid': txid})
  2701. else:
  2702. return JsonResponse({'code': 400, 'error': 'transaction_failed'})
  2703. else:
  2704. # eth_refund_dict = {
  2705. # 'from_address':eth_withdraw_address,
  2706. # 'refund_address':refund_address,
  2707. # 'amount_to_refund':pending_amount,
  2708. # 'timestamp':int(time.time()),
  2709. # 'refund_type':'eth_withdraw',
  2710. # 'currency':'eth'
  2711. # }
  2712. # insert_unsuccessful_eth_refund(eth_refund_dict)
  2713. return JsonResponse({'code': 400, 'error': 'transaction_failed'})
  2714.  
  2715.  
  2716. else:
  2717. return JsonResponse({'code': 401, 'token_match': False})
  2718.  
  2719.  
  2720. @csrf_exempt
  2721. @TokenValidatorMiddleware
  2722. @JWTMiddleware
  2723. def otp_for_admin(request):
  2724. data = json.loads(request.body)
  2725. email = data['email']
  2726. uuid_flag = 1
  2727. if uuid_flag == 1:
  2728. send_list = get_otp_for_admin_model()
  2729. return JsonResponse({'code': 200, 'list': send_list})
  2730. else:
  2731. return JsonResponse({'code': 401, 'token_match': False})
  2732.  
  2733.  
  2734. def do_eth_transaction(to_address, amount, fee):
  2735. from_address = eth_withdraw_address
  2736. print 'refunding etherr from address::: %s, to address:: %s, amount::: %s, fee::: %s' % (
  2737. from_address, to_address, amount, fee)
  2738. timestamp = str(int(time.time()))
  2739. # signature = calculate_signature('token_baazar_staging','abcd',timestamp)
  2740. eth_send_dict = {
  2741. # 'user':eth_user,
  2742. # 'token':eth_token,
  2743. 'from_address': from_address,
  2744. 'to_address': to_address,
  2745. 'ethers': float(amount),
  2746. # 'timestamp':timestamp,
  2747. # 'signature':signature
  2748. }
  2749. eth_forward_res = requests.post(forward_eth_url, data=eth_send_dict)
  2750. print 'eth_forward_res::: %s' % eth_forward_res.text
  2751. if eth_forward_res.status_code == 200:
  2752. eth_transaction_details = json.loads(eth_forward_res.text)
  2753. if eth_transaction_details['code'] == 200:
  2754. print 'status code:: 200, eth transaction successful'
  2755. txid = eth_transaction_details['msg']['transaction_hash']
  2756. eth_refund_dict = {
  2757. 'from_address': from_address,
  2758. 'refund_address': to_address,
  2759. 'txid': txid,
  2760. 'transaction_fee': fee,
  2761. 'amount_refunded': float(amount) - float(fee),
  2762. 'timestamp': int(time.time()),
  2763. 'refund_type': 'eth_withdraw',
  2764. 'currency': 'eth'
  2765. }
  2766. insert_successful_eth_refund(eth_refund_dict)
  2767. return txid
  2768. else:
  2769. print 'status not 200::: eth transaction unsuccessful %s' % eth_forward_res.text
  2770. eth_refund_dict = {
  2771. 'from_address': from_address,
  2772. 'refund_address': to_address,
  2773. 'amount_to_refund': amount,
  2774. 'timestamp': int(time.time()),
  2775. 'refund_type': 'eth_withdraw',
  2776. 'currency': 'eth'
  2777. }
  2778. insert_unsuccessful_eth_refund(eth_refund_dict)
  2779. return None
  2780. else:
  2781. print 'eth_auxpay error::: '
  2782. eth_refund_dict = {
  2783. 'from_address': from_address,
  2784. 'refund_address': to_address,
  2785. 'amount_to_refund': amount,
  2786. 'timestamp': int(time.time()),
  2787. 'refund_type': 'eth_withdraw',
  2788. 'currency': 'eth'
  2789. }
  2790. insert_unsuccessful_eth_refund(eth_refund_dict)
  2791. return None
  2792.  
  2793.  
  2794. def do_btc_transaction(refund_amount, btc_fee, btc_bal, btc_refund_address):
  2795. # def refund_btc(address,btc_refund_address,refund_amount,btc_fee,btc_bal,refund_type):
  2796. amount_to_refund = refund_amount - btc_fee
  2797. address = btc_withdraw_address
  2798. print 'amount to refud::: %s,fee: %s, refund_amount:: %s,btc bal:: %s' % (
  2799. amount_to_refund, btc_fee, refund_amount, btc_bal)
  2800. send_dict = {
  2801. 'user_name': auxpay_user,
  2802. 'token': auxpay_token,
  2803. 'transactions': {
  2804. 'input_address': [address],
  2805. 'output_address': {
  2806. btc_refund_address: round(amount_to_refund, 8),
  2807. address: round(btc_bal - refund_amount, 8)
  2808. }
  2809. },
  2810. # 'change_flag': False
  2811. }
  2812. print 'json sent %s to url %s' % (send_dict, forward_btc_url)
  2813. forward_btc_res = requests.post(forward_btc_url, data=json.dumps(send_dict))
  2814. if forward_btc_res.status_code == 200:
  2815. txid = json.loads(forward_btc_res.text)['new_txid']
  2816. print 'update db after refund:::: '
  2817. btc_refund_dict = {
  2818. 'from_address': address,
  2819. 'refund_address': btc_refund_address,
  2820. 'txid': txid,
  2821. 'transaction_fee': btc_fee,
  2822. 'amount_refunded': amount_to_refund,
  2823. 'timestamp': int(time.time()),
  2824. 'refund_type': 'btc_withdraw',
  2825. 'currency': 'btc'
  2826. }
  2827. insert_successful_btc_refund(btc_refund_dict)
  2828. return txid
  2829. else:
  2830. print 'err::: %s' % forward_btc_res.text
  2831. btc_refund_dict = {
  2832. 'from_address': address,
  2833. 'refund_address': btc_refund_address,
  2834. 'amount_to_refund': refund_amount,
  2835. 'timestamp': int(time.time()),
  2836. 'refund_type': 'btc_withdraw',
  2837. 'currency': 'btc'
  2838. }
  2839. insert_unsuccessful_btc_refund(btc_refund_dict)
  2840. return None
  2841.  
  2842.  
  2843. @csrf_exempt
  2844. @TokenValidatorMiddleware
  2845. @JWTMiddleware
  2846. def get_referral_details(request):
  2847. print 'get_referral_details hitted:::: '
  2848. data = json.loads(request.body)
  2849. print data
  2850. email = data['email']
  2851. uuid_flag = 1
  2852. if uuid_flag == 1:
  2853.  
  2854. ref_id = get_ref_id(email)
  2855. print 'ref_id::: %s' % ref_id
  2856. eth_refund_address = get_refund_address_using_mail(email, 'eth')
  2857. btc_refund_address = get_refund_address_using_mail(email, 'btc')
  2858.  
  2859. send_dict = dict()
  2860. send_dict['ref_id'] = ref_id
  2861. send_dict['eth_refund_address'] = eth_refund_address
  2862. send_dict['btc_refund_address'] = btc_refund_address
  2863. res = get_referral_list_model(ref_id)
  2864. referral_list = []
  2865. for data in res:
  2866. tmp_dict = dict()
  2867. tmp_dict['name'] = data['name']
  2868.  
  2869. tmp_dict['degree'] = data['height']
  2870.  
  2871. if data['currency'] == 'btc':
  2872. tmp_dict['amount_in_btc'] = round(data['bonus_amount'], 6)
  2873. tmp_dict['amount_in_eth'] = 0
  2874. else:
  2875. tmp_dict['amount_in_btc'] = 0
  2876. tmp_dict['amount_in_eth'] = data['bonus_amount']
  2877. referral_list.append(tmp_dict)
  2878.  
  2879. child_details = get_child_details(ref_id)
  2880. send_dict['child_details'] = child_details
  2881. send_dict['referral_details_list'] = referral_list
  2882. withdrawn_btc, pending_btc, withdrawn_eth, pending_eth = get_withdraw_details_model(ref_id)
  2883. send_dict['withdrawn_btc'] = withdrawn_btc
  2884. send_dict['pending_btc'] = pending_btc
  2885. send_dict['earned_btc'] = withdrawn_btc + pending_btc
  2886. send_dict['withdrawn_eth'] = withdrawn_eth
  2887. send_dict['pending_eth'] = pending_eth
  2888. send_dict['earned_eth'] = withdrawn_eth + pending_eth
  2889.  
  2890. total_xal_earned, db_data = total_xal_earned_via_referial(email)
  2891.  
  2892. return JsonResponse(
  2893. {'code': 200, 'referral_json': send_dict, 'total_xal_earned': total_xal_earned, 'total_data': db_data})
  2894. else:
  2895. return JsonResponse({"code": 401, "token_match": False})
  2896.  
  2897.  
  2898. def get_child_details(ref_id):
  2899. try:
  2900. i = 0
  2901. parents = [ref_id]
  2902. tree_arr = []
  2903. while i < 10:
  2904. children = []
  2905. name_list = []
  2906. res = get_details_from_ref_tree(parents)
  2907. for data in res:
  2908. if len(data['child']) > 0:
  2909. children += data['child']
  2910. name = get_name(data['child'])
  2911. for ind_name in name:
  2912. if ind_name not in name_list:
  2913. name_list.append(ind_name)
  2914. else:
  2915. print '-'
  2916. if len(name_list) > 0:
  2917. mn = list(set(name_list))
  2918. tmp_dict = {str(i + 1): mn}
  2919. if tmp_dict not in tree_arr:
  2920. tree_arr.append(tmp_dict)
  2921.  
  2922. i += 1
  2923. parents = children
  2924. return tree_arr
  2925. except Exception as e:
  2926. print "error in get_chid_details model %s" %e
  2927.  
  2928. @csrf_exempt
  2929. @TokenValidatorMiddleware
  2930. @JWTMiddleware
  2931. def token(request):
  2932. if request.method == "POST":
  2933. sold = model_token()
  2934. data = json.loads(request.body)
  2935. total_token = data['total']
  2936. available = total_token - sold
  2937. return JsonResponse({"sold_token": sold, "available_token": available})
  2938.  
  2939.  
  2940. def validate_eth_address(eth_address_input):
  2941. # eth_address_input = str(eth_address_input)
  2942. # hex_eth_address = str.lower(eth_address_input)
  2943. # if len(eth_address_input) == 42:
  2944. # prefix = hex_eth_address[0:2]
  2945. # if prefix == '0x':
  2946. # eth_address = hex_eth_address[3:len(hex_eth_address)]
  2947. # try:
  2948. # int(eth_address,16)
  2949. # return True
  2950. # except ValueError:
  2951. # return False
  2952. # else:
  2953. # return False
  2954. # else:
  2955. # return False
  2956. eth_address_validator_url = "https://api.blockcypher.com/v1/eth/main/addrs/" + eth_address_input
  2957. resp = requests.get(eth_address_validator_url)
  2958. if resp.status_code == 200:
  2959. return True
  2960. else:
  2961. return False
  2962.  
  2963.  
  2964. def validate_btc_address(address):
  2965. btc_address_validator_url = "https://blockexplorer.com/api/addr/" + address + "?noTxList=1&noCache=1"
  2966. resp = requests.get(btc_address_validator_url)
  2967. if resp.status_code == 200:
  2968. return True
  2969. else:
  2970. return False
  2971.  
  2972.  
  2973. # helpdesk start
  2974. @csrf_exempt
  2975. @TokenValidatorMiddleware
  2976. @JWTMiddleware
  2977. def add_category(request):
  2978. print 'adding category::: '
  2979. data = json.loads(request.body)
  2980. email = data['email']
  2981. uuid_flag = 1
  2982. if uuid_flag == 1:
  2983. category = data['category']
  2984. res = add_category_model(category)
  2985. return JsonResponse({'code': 200})
  2986. else:
  2987. return JsonResponse({"code": 401, "token_match": False})
  2988.  
  2989.  
  2990. @csrf_exempt
  2991. @TokenValidatorMiddleware
  2992. @JWTMiddleware
  2993. def update_category(request):
  2994. print 'updating category::: '
  2995. data = json.loads(request.body)
  2996. email = data['email']
  2997. uuid_flag = 1
  2998. if uuid_flag == 1:
  2999. new_category = data['new_category']
  3000. _id = data['_id']
  3001. res = update_category_model(new_category, _id)
  3002. return JsonResponse({'code': 200})
  3003. else:
  3004. return JsonResponse({"code": 401, "token_match": False})
  3005.  
  3006.  
  3007. @csrf_exempt
  3008. @TokenValidatorMiddleware
  3009. @JWTMiddleware
  3010. def delete_category(request):
  3011. print 'deleting category::: '
  3012. data = json.loads(request.body)
  3013. email = data['email']
  3014. uuid_flag = 1
  3015. if uuid_flag == 1:
  3016. _id = data['_id']
  3017. res = delete_category_model(_id)
  3018. return JsonResponse({'code': 200})
  3019. else:
  3020. return JsonResponse({"code": 401, "token_match": False})
  3021.  
  3022.  
  3023. @csrf_exempt
  3024. # @TokenValidatorMiddleware
  3025. # @JWTMiddleware
  3026. def display_category(request):
  3027. print 'display category::: '
  3028. data = json.loads(request.body)
  3029. uuid_flag = 1
  3030. if uuid_flag == 1:
  3031. list_to_send = []
  3032. res = display_category_model()
  3033. for data in res:
  3034. # print data
  3035. data['_id'] = str(data['_id'])
  3036. list_to_send.append(data)
  3037. print list_to_send
  3038. return JsonResponse({'code': 200, 'categories_list': list_to_send})
  3039. else:
  3040. return JsonResponse({"code": 401, "token_match": False})
  3041.  
  3042.  
  3043. @csrf_exempt
  3044. @TokenValidatorMiddleware
  3045. @JWTMiddleware
  3046. def raise_ticket(request):
  3047. print 'raising ticket------------------------------->:::'
  3048. data = json.loads(request.body)
  3049. email = data['email']
  3050. uuid_flag = 1
  3051. if uuid_flag == 1:
  3052. issue_category = data['issue_category']
  3053. subject = data['subject']
  3054. if data.__contains__('phone'):
  3055. phone = data['phone']
  3056. else:
  3057. phone = 'NA'
  3058. description = data['description']
  3059. if len(subject) > 100 or len(description) > 1000:
  3060. return JsonResponse({"code": 401, "error": "message_too_long"})
  3061. support_email = get_admin_email_model()
  3062. res = raise_ticket_model(email, issue_category, cgi.escape(subject), phone, cgi.escape(description))
  3063. send_ticket_raise_mail(email, support_email, str(res), subject, description, )
  3064. return JsonResponse({'code': 200, 'ticket_no': str(res)})
  3065. else:
  3066. return JsonResponse({"code": 401, "token_match": False})
  3067.  
  3068.  
  3069. @csrf_exempt
  3070. @TokenValidatorMiddleware
  3071. @JWTMiddleware
  3072. def display_tickets_to_user(request):
  3073. print 'display tickets to user:::'
  3074. data = json.loads(request.body)
  3075. email = data['email']
  3076. uuid_flag = 1
  3077. if uuid_flag == 1:
  3078. res = display_ticket_to_user_model(email)
  3079. h = HTMLParser()
  3080. user_tickets_list = []
  3081. for details in res:
  3082. print details
  3083. details['_id'] = str(details['_id'])
  3084. details['description'] = h.unescape(details['description'])
  3085. details['subject'] = h.unescape(details['subject'])
  3086. user_tickets_list.append(details)
  3087. return JsonResponse({'code': 200, 'user_tickets_list': user_tickets_list})
  3088. else:
  3089. return JsonResponse({"code": 401, "token_match": False})
  3090.  
  3091.  
  3092. @csrf_exempt
  3093. # @TokenValidatorMiddleware
  3094. # @JWTMiddleware
  3095. def display_tickets_to_admin(request):
  3096. print 'display tickets to admin:::'
  3097. data = json.loads(request.body)
  3098. email = data['email']
  3099.  
  3100. res = display_ticket_to_admin_model()
  3101. if res:
  3102.  
  3103. h = HTMLParser()
  3104. tickets_list = []
  3105. print "111111111111111111111111111"
  3106. for data in res:
  3107. print "-----9999999999--------------"
  3108. print data
  3109. data['email'] = str(data['email'])
  3110. data['name'] = get_user_name(data['email'])
  3111. data['_id'] = str(data['_id'])
  3112. data['description'] = h.unescape(data['description'])
  3113. data['subject'] = h.unescape(data['subject'])
  3114. print data
  3115. tickets_list.append(data)
  3116. return JsonResponse({'code': 200, 'tickets_list': tickets_list})
  3117. else:
  3118. return JsonResponse({"code": 401, "msg": "Error"})
  3119.  
  3120.  
  3121. @csrf_exempt
  3122. # @TokenValidatorMiddleware
  3123. # @JWTMiddleware
  3124. def close_ticket(request):
  3125. print 'closing ticket:::'
  3126. data = json.loads(request.body)
  3127. email = data['email']
  3128. uuid_flag = 1
  3129. if uuid_flag == 1:
  3130. _id = data['_id']
  3131. res = close_ticket_model(_id)
  3132. user_email = res['email']
  3133. send_ticket_close_email(user_email, _id)
  3134. return JsonResponse({'code': 200})
  3135. else:
  3136. return JsonResponse({"code": 401, "token_match": False})
  3137.  
  3138.  
  3139. @csrf_exempt
  3140. @TokenValidatorMiddleware
  3141. @JWTMiddleware
  3142. def reopen_ticket(request):
  3143. print 'closing ticket:::'
  3144. data = json.loads(request.body)
  3145. email = data['email']
  3146. uuid_flag = 1
  3147. if uuid_flag == 1:
  3148. _id = data['_id']
  3149. res = reopen_ticket_model(_id)
  3150. user_email = res['email']
  3151. description = res['description']
  3152. subject = res['subject']
  3153. support_email = get_admin_email_model()
  3154. send_ticket_reopen_email(user_email, support_email, _id, subject, description)
  3155. return JsonResponse({'code': 200})
  3156. else:
  3157. return JsonResponse({"code": 401, "token_match": False})
  3158.  
  3159.  
  3160. def send_ticket_raise_mail(user_email, support_email, ticket_no, subject, description):
  3161. m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
  3162. print 'sending mail to admin::: '
  3163. email_dict = {
  3164. "to": {support_email: support_email},
  3165. "from": ["support@auxledger.org"],
  3166. "replyto": [user_email, user_email],
  3167. "subject": "New Support Ticket ID " + ticket_no + " Raised",
  3168. "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."
  3169. }
  3170. result = m.send_email(email_dict)
  3171.  
  3172.  
  3173. def send_ticket_close_email(email, ticket_no):
  3174. m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
  3175. data = { "id" : 50,
  3176. "to" : {email: email},
  3177. "replyto" : "support@auxledger.org",
  3178. "attr" : {"ticket_no": str(ticket_no)},
  3179. "headers" : {"Content-Type": "text/html;charset=iso-8859-1"}
  3180. }
  3181. result = m.send_transactional_template(data)
  3182.  
  3183.  
  3184. def send_ticket_response_email(email, ticket_no,message):
  3185. m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
  3186. print 'sending mail to admin::: '
  3187. data = { "id" : 51,
  3188. "to" : {email: email},
  3189. "replyto" : "support@auxledger.org",
  3190. "attr" : {"ticket_no": str(ticket_no),"reply": str(message)},
  3191. "headers" : {"Content-Type": "text/html;charset=iso-8859-1"}
  3192. }
  3193. result = m.send_transactional_template(data)
  3194.  
  3195.  
  3196. def send_ticket_reopen_email(user_email, support_email, ticket_no, subject, description):
  3197. m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
  3198. print 'sending mail to admin::: '
  3199. email_dict = {
  3200. "to": {support_email: support_email},
  3201. "from": ["support@auxledger.org"],
  3202. "replyto": [user_email, user_email],
  3203. "subject": "Support Ticket ID " + ticket_no + " is Reopened",
  3204. "html": "Subject: " + subject + "<br>Message: " + description + "<br>Please reply to this mail and connect with the user directly."
  3205. }
  3206. result = m.send_email(email_dict)
  3207.  
  3208.  
  3209. @csrf_exempt
  3210. @TokenValidatorMiddleware
  3211. @JWTMiddleware
  3212. def set_support_email(request):
  3213. print 'setting support email:::'
  3214. data = json.loads(request.body)
  3215. email = data['email']
  3216. uuid_flag = 1
  3217. if uuid_flag == 1:
  3218. admin_email = data['admin_email']
  3219. res = set_admin_email_model(admin_email)
  3220. return JsonResponse({'code': 200, 'success': True})
  3221. else:
  3222. return JsonResponse({"code": 401, "token_match": False})
  3223.  
  3224.  
  3225. @csrf_exempt
  3226. # @TokenValidatorMiddleware
  3227. # @JWTMiddleware
  3228. def get_support_email(request):
  3229. print 'getting support email:::'
  3230. data = json.loads(request.body)
  3231. email = data['email']
  3232. uuid_flag = 1
  3233. if uuid_flag == 1:
  3234. admin_email = get_admin_email_model()
  3235. return JsonResponse({'code': 200, 'admin_email': admin_email})
  3236. else:
  3237. return JsonResponse({"code": 401, "token_match": False})
  3238.  
  3239.  
  3240. @csrf_exempt
  3241. @TokenValidatorMiddleware
  3242. @JWTMiddleware
  3243. def send_user_message(request):
  3244. print 'send user msg:::'
  3245. data = json.loads(request.body)
  3246. email = data['email']
  3247. uuid_flag = 1
  3248. if uuid_flag == 1:
  3249. message = data['message']
  3250. if len(message) > 1000:
  3251. return JsonResponse({"code": 401, "error": "message_too_long"})
  3252. ticket_no = data['_id']
  3253.  
  3254. res = insert_user_message_model(cgi.escape(message), ticket_no)
  3255.  
  3256. support_email = get_admin_email_model()
  3257.  
  3258. send_user_reply_email(support_email, message,ticket_no)
  3259.  
  3260. return JsonResponse({'code': 200, 'success': True})
  3261. else:
  3262. return JsonResponse({"code": 401, "token_match": False})
  3263.  
  3264.  
  3265. # db_conn.tickets.update({"_id":ObjectId(ticket_no)},{"$set":{"chat_status":"admin_answered","last_modified":int(time.time())}})
  3266.  
  3267.  
  3268. @csrf_exempt
  3269. # @TokenValidatorMiddleware
  3270. # @JWTMiddleware
  3271. def send_admin_message(request):
  3272. print 'send admin msg:::'
  3273. data = json.loads(request.body)
  3274. email = data['email']
  3275. uuid_flag = 1
  3276. if uuid_flag == 1:
  3277. message = data['message']
  3278. if len(message) > 1000:
  3279. return JsonResponse({"code": 401, "error": "message_too_long"})
  3280. ticket_no = data['_id']
  3281.  
  3282. res = insert_admin_message_model(cgi.escape(message), ticket_no)
  3283.  
  3284. user_email = get_email_from_obj_id(ticket_no)
  3285.  
  3286. send_ticket_response_email(user_email,ticket_no,message)
  3287.  
  3288. return JsonResponse({'code': 200, 'success': True})
  3289. else:
  3290. return JsonResponse({"code": 401, "token_match": False})
  3291.  
  3292.  
  3293.  
  3294.  
  3295.  
  3296. def send_user_reply_email(support_email, message,ticket_no):
  3297. m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
  3298. print 'sending mail to admin::: '
  3299. email_dict = {
  3300. "to": {support_email: support_email},
  3301. "from": ["support@auxledger.org"],
  3302. # "replyto": [user_email, user_email],
  3303. "subject": "reply to existing support ticket from user",
  3304. "html": " user reply on ticket no"+str(ticket_no)
  3305. }
  3306. result = m.send_email(email_dict)
  3307. print result
  3308.  
  3309.  
  3310. @csrf_exempt
  3311. # @TokenValidatorMiddleware
  3312. # @JWTMiddleware
  3313. def get_chat_details(request):
  3314. print 'getting chat detailss::: '
  3315. data = json.loads(request.body)
  3316. email = data['email']
  3317. uuid_flag = 1
  3318. if uuid_flag == 1:
  3319. ticket_no = data['_id']
  3320. chat_details = get_chat_details_model(ticket_no)
  3321. chat_details['_id'] = str(chat_details['_id'])
  3322. print 'vvccc %s' % chat_details
  3323. return JsonResponse({'code': 200, 'chat_details': chat_details})
  3324. else:
  3325. return JsonResponse({"code": 401, "token_match": False})
  3326.  
  3327.  
  3328. @csrf_exempt
  3329. # @TokenValidatorMiddleware
  3330. # @JWTMiddleware
  3331. def get_ticket_chat_notifications(request):
  3332. print 'get_ticket_chat_notifications hitted'
  3333. data = json.loads(request.body)
  3334. email = data['email']
  3335. uuid_flag = 1
  3336. if uuid_flag == 1:
  3337. return JsonResponse({"code": 200, 'data': get_ticket_chat_notifications_model()})
  3338. else:
  3339. return JsonResponse({"code": 401, "token_match": False})
  3340.  
  3341.  
  3342. @csrf_exempt
  3343. @TokenValidatorMiddleware
  3344. @JWTMiddleware
  3345. def get_ticket_chat_notifications_from_admin(request):
  3346. print 'get_ticket_chat_notifications hitted'
  3347. data = json.loads(request.body)
  3348. email = data['email']
  3349. uuid_flag = 1
  3350. if uuid_flag == 1:
  3351. return JsonResponse({"code": 200, 'data': get_ticket_chat_notifications_from_admin_model(email)})
  3352. else:
  3353. return JsonResponse({"code": 401, "token_match": False})
  3354.  
  3355.  
  3356. @csrf_exempt
  3357. @TokenValidatorMiddleware
  3358. @JWTMiddleware
  3359. def get_price_from_couch(request):
  3360. print 'getting chat detailss::: '
  3361. data = json.loads(request.body)
  3362. email = data['email']
  3363. uuid_flag = 1
  3364. if uuid_flag == 1:
  3365. if config.development:
  3366. couch_db_res = requests.get('https://35.176.9.68:6984/current_price_v1/current_price_unique_id/')
  3367. else:
  3368. couch_db_res = requests.get('http://localhost:6984/current_price_v1/current_price_unique_id/')
  3369. return JsonResponse({'code': 200, 'data': couch_db_res.text})
  3370. else:
  3371. return JsonResponse({"code": 401, "token_match": False})
  3372.  
  3373.  
  3374. @csrf_exempt
  3375. # @TokenValidatorMiddleware
  3376. # @JWTMiddleware
  3377. def get_rate_conversion(request):
  3378. data = json.loads(request.body)
  3379. email = data['email']
  3380. uuid_flag = 1
  3381. if uuid_flag == 1:
  3382. res = get_rate_conversion_model()
  3383. return JsonResponse({"data": res, 'code': 200})
  3384. else:
  3385. return JsonResponse({"code": 401, "token_match": False})
  3386.  
  3387.  
  3388. @csrf_exempt
  3389. @TokenValidatorMiddleware
  3390. @JWTMiddleware
  3391. def get_latest_transactions_from_couch(request):
  3392. print 'getting chat detailss::: '
  3393. data = json.loads(request.body)
  3394. email = data['email']
  3395. uuid_flag = 1
  3396. if uuid_flag == 1:
  3397. if config.development:
  3398. couch_db_res = requests.get('https://35.176.9.68:6984/current_price_v1/current_price_unique_id/')
  3399. else:
  3400. couch_db_res = requests.get('http://localhost:6984/current_price_v1/current_price_unique_id/')
  3401.  
  3402. # couch_db_res = requests.get('http://localhost:6984/live_orders_v1/live_order_unique_id/')
  3403. return JsonResponse({'code': 200, 'data': couch_db_res.text})
  3404. else:
  3405. return JsonResponse({"code": 401, "token_match": False})
  3406.  
  3407.  
  3408. @csrf_exempt
  3409. @TokenValidatorMiddleware
  3410. @JWTMiddleware
  3411. def set_bank_details_by_admin(request):
  3412. print 'setting bank detailss::: '
  3413. data = json.loads(request.body)
  3414. email = data['email']
  3415. uuid_flag = 1
  3416. if uuid_flag == 1:
  3417. bank_name = data['bank_name']
  3418. bank_account_number = data['bank_account_number']
  3419. res = insert_bank_details(bank_name, bank_account_number)
  3420. if res:
  3421. return JsonResponse({'code': 400, 'success': False})
  3422. else:
  3423. return JsonResponse({'code': 200, 'success': True})
  3424. else:
  3425. return JsonResponse({"code": 401, "token_match": False})
  3426.  
  3427.  
  3428. @csrf_exempt
  3429. @TokenValidatorMiddleware
  3430. @JWTMiddleware
  3431. def user_kyc_form_details(request):
  3432. try:
  3433. data = json.loads(request.body)
  3434. email = data['email']
  3435. uuid_flag = 1
  3436. insert_data = {}
  3437. if uuid_flag == 1:
  3438. insert_data["email"] = data['email']
  3439. insert_data["first_name"] = data['first_name']
  3440. insert_data["last_name"] = data['last_name']
  3441. insert_data["address_1"] = data['address_1']
  3442. insert_data["address_2"] = data['address_2']
  3443. insert_data["city"] = data['city']
  3444. insert_data["state"] = data['state']
  3445. insert_data["country"] = data['country']
  3446. insert_data["pin_code"] = data['pin_code']
  3447. insert_data["dob"] = data['dob']
  3448. insert_data["gender"] = data['gender']
  3449. print insert_data
  3450. db_resp = user_kyc_details_model(1, **insert_data) # 1 --> insert flag
  3451. if db_resp:
  3452. print "db response %s" % db_resp
  3453. return JsonResponse({'code': 200, 'success': True})
  3454. except:
  3455. return JsonResponse({"code": 400, 'success': False})
  3456.  
  3457.  
  3458. @csrf_exempt
  3459. @TokenValidatorMiddleware
  3460. @JWTMiddleware
  3461. def display_kyc_form_detail(request):
  3462. print "----------display kyc detail----------------"
  3463. data = json.loads(request.body)
  3464. email = data['email']
  3465. uuid_flag = 1
  3466. if uuid_flag == 1:
  3467. get_user_details = user_kyc_details_model(0, **{"email": data["email"]}) # 0 flag to fetch data
  3468. if get_user_details:
  3469. return JsonResponse({"code": 200, "user_details": get_user_details})
  3470. else:
  3471. return JsonResponse({"code": 400, "success": False})
  3472.  
  3473.  
  3474. @csrf_exempt
  3475. def subscribed_email(request):
  3476. data = json.loads(request.body)
  3477. print "data is s----------------------> %s" % data
  3478. email = str(data["mc_email"])
  3479. flag = subscribed_email_model(email)
  3480. if flag == 0:
  3481. return JsonResponse({"code": 200})
  3482. else:
  3483. return JsonResponse({"code": 201})
  3484.  
  3485.  
  3486. @csrf_exempt
  3487. def send_email_from_html(request):
  3488. data = json.loads(request.body)
  3489. user_email = str(data["contact_email"])
  3490. message = str(data["contact_message"])
  3491. name = str(data["contact_name"])
  3492. phn_no = str(data["contact_Mobile"])
  3493. m = Mailin("https://api.sendinblue.com/v2.0", "RSv3VdkQOEmC8AUj")
  3494. email = "info@auxledger.org"
  3495. email_dict = {
  3496. "to": {email: email},
  3497. "from": ["support@auxledger.org"],
  3498. "subject": "contact request from " + " " + name + ".auxledger.org",
  3499. "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}
  3500. result = m.send_email(email_dict)
  3501. print result
  3502. return JsonResponse({'code': 200})
  3503.  
  3504.  
  3505. @csrf_exempt
  3506. # @TokenValidatorMiddleware
  3507. # @JWTMiddleware
  3508. def admin_referral_details(requests):
  3509. ref_details,total_tokens = get_admin_referral_details()
  3510. if ref_details:
  3511. return JsonResponse({"code":200,"data":ref_details,"total_referral_earned":total_tokens})
  3512. else:
  3513. return JsonResponse({"code": 400, "msg": "data not found"})
  3514.  
  3515.  
  3516.  
  3517.  
  3518. @csrf_exempt
  3519. def user_detail(requests):
  3520. data = json.load(requests)
  3521. email = data["email"]
  3522. print email
  3523.  
  3524. user_details = user_exists_model(email)
  3525.  
  3526. user_name = user_details['tnc']['name']
  3527. date_registered = user_details['tnc']['time_stamp']
  3528. ref_id = user_details['ref_id']
  3529.  
  3530.  
  3531. if user_details.__contains__('kyc'):
  3532. print "inside kyc"
  3533. kyc_flag = user_details['kyc']['status']
  3534. else:
  3535. print "not kyc"
  3536. kyc_flag = "NA"
  3537.  
  3538.  
  3539. user_timeline_list = []
  3540. tokens = 0.0
  3541. timeline_res = get_user_timeline_model(email)
  3542. for data in timeline_res:
  3543. user_timeline_list.append(data)
  3544. if data.__contains__('tokens_purchased'):
  3545. tokens += float(data['tokens_purchased'])
  3546. if data.__contains__('token_purchased'):
  3547. tokens += float(data['token_purchased'])
  3548.  
  3549. btc_address = get_generated_address(email,"btc")
  3550. eth_address = get_generated_address(email,"eth")
  3551.  
  3552. two_fa_status = check_2fa_status(email)
  3553.  
  3554. send_dict = {
  3555. 'status': 200,
  3556. 'email':email,
  3557. 'btc_address':btc_address,
  3558. 'eth_address':eth_address,
  3559. 'kyc': kyc_flag,
  3560. 'tokens': round(tokens, 3),
  3561. 'user_name': user_name,
  3562. 'two_fa_status': two_fa_status,
  3563. 'ref_id':ref_id,
  3564. 'date_registered':date_registered,
  3565. 'was_referred':False
  3566. }
  3567.  
  3568. referral_details= get_referral_status(ref_id)
  3569.  
  3570. if referral_details['was_referred']:
  3571. send_dict['was_referred'] = True
  3572. send_dict['referred_by'] = referral_details['referred_by']
  3573.  
  3574. return JsonResponse(send_dict)
  3575.  
  3576.  
  3577.  
  3578.  
  3579. # import razorpay
  3580. # client = razorpay.Client(auth=("rzp_test_EDSwYy6TtJ8wOT", "8DAvPokF0PINAlGOryGDC1EO"))
  3581. # client = razorpay.Client(auth=("rzp_live_cvfiP9RLAgfFmN", "7t6QOr7wKXQMpUzy8qNI3CxT"))
  3582.  
  3583. @csrf_exempt
  3584. def capture_payments(request):
  3585. try:
  3586. print "-----------------razaor pay------------"
  3587. data = json.loads(request.body)
  3588. user_email = str(data["email"])
  3589. payment_id = str(data["payment_id"])
  3590. payment_amount = str(data["amount"])
  3591. xal_amount = str(data["xal_amount"])
  3592. currency = "INR"
  3593. type_ = "inr_transfer"
  3594. resp = client.payment.capture(payment_id, payment_amount)
  3595.  
  3596. if resp["captured"]:
  3597. result1 = insert_pay_inr_to_transaction_details(user_email, currency, payment_id,
  3598. float(payment_amount) / 100,
  3599. xal_amount, resp) # check resp.response
  3600. result2 = insert_pay_inr_to_user_timeline(user_email, currency, xal_amount, payment_id, type_,
  3601. float(payment_amount) / 100)
  3602.  
  3603. ref_id, name = get_inr_referral_details_model_fiat(user_email)
  3604. calc_referal_bonus_auxledger(ref_id, float(payment_amount) / 100, name, 'INR', "na", payment_id, user_email)
  3605. send_confirmation_mail(user_email, xal_amount, float(payment_amount) / 100, "INR")
  3606. return JsonResponse({"code": 200})
  3607.  
  3608. except Exception as e:
  3609. print e
  3610. return JsonResponse({"code": 400, 'success': False})
Add Comment
Please, Sign In to add comment