def process_out(CurrencyTitle):

        Crypton = CryptoAccount(CurrencyTitle, "trade_stock")
        user_system =   User.objects.get(id = 1)
        CurrencyInstance = Currency.objects.get(title = CurrencyTitle)
        if  check_global_lock():
            raise LockBusyException("global check crypto currency has raised")
	
#sys.exit(0)
        getcontext().prec = crypton.settings.TRANS_PREC
        for obj in CryptoTransfers.objects.filter(status="processing", 
                                                  debit_credit ="out",
                                                  currency = CurrencyInstance):
  		
               print "sending funds of %s to %s amount %s"  % (obj.user.username,  obj.account, obj.amnt)
#	       continue   
               if not obj.verify(get_decrypted_user_pin(obj.user)):
			print "SALT FAILED"
			continue
	       else:
			print "Salt ok"
               obj.status = "processed"
               obj.user_accomplished = user_system               
               obj.save()
               obj.order.status = "processed"                      
               Txid = Crypton.sendto(obj.account, float(obj.amnt))
               print "txid %s" % (Txid) 
               obj.order.save()                       
               obj.crypto_txid = Txid
               obj.save()
               notify_email(obj.user, "withdraw_notify", obj)
Beispiel #2
0
def try_login(request):
    username = request.REQUEST.get('login')
    password = request.REQUEST.get('password')
    usr = None
    # try:
    usr = User.objects.get(email=username)
    #except User.DoesNotExist:
    #   request.result_auth = "bad"
    #   return HttpResponse("bad")

    user = authenticate(username=usr.username, password=password)
    if user is not None:
        if user.is_active is True:

                login(request, user)
                request.result_auth = "good"
                request.session['auth_user_computered'] = True
                request.session['use_f2a'] = False
                request.session['user_id'] = user.id
                request.session['username'] = user.username
                request.session['email'] = user.email
                notify_email(user, "auth_notify", request)
                return HttpResponse("good")
           

        else:
            request.result_auth = "bad"
            notify_email(user, "auth_notify", request)
            return HttpResponse("bad")
    else:
        notify_email_admin(request, "try_login")
        return HttpResponse("very_bad")
Beispiel #3
0
def login_f2a(request):
    key = request.REQUEST.get('key', None)
    password = request.REQUEST.get('password', None)
    cache = caching()
    UserIdCached = cache.get(key, False)
    if not UserIdCached:
        return json_false500(request)

    UserIdCachedInt = int(UserIdCached)
    Setting = UserCustomSettings.objects.get(user_id=UserIdCachedInt, setting__title="g2a")

    if auth(Setting.value, password):

        user = User.objects.get(id=UserIdCachedInt)
        user.backend = 'django.contrib.auth.backends.ModelBackend'
        login(request, user)
        request.result_auth = "good"
        request.session['auth_user_computered'] = True
        request.session['use_f2a'] = True
        request.session['user_id'] = user.id
        request.session['username'] = user.username
        request.session['email'] = user.email
        ComisObj = UserCustomSettings.objects.get(user_id=request.user.id, setting__title="deal_comission")
        DealComission = format_numbers4(Decimal(ComisObj.value) * Decimal("100"))
        request.session["deal_comission_show"] = DealComission
        request.session["deal_comission"] = format_numbers4(Decimal(ComisObj.value))

        notify_email(user, "auth_notify", request)

        return HttpResponse("good")

    else:
        return json_false500(request)
Beispiel #4
0
def login_f2a(request):
    key = request.REQUEST.get('key', None)
    password = request.REQUEST.get('password', None)
    cache = caching()
    UserIdCached = cache.get(key, False)
    if not UserIdCached:
        return json_false500(request)

    UserIdCachedInt = int(UserIdCached)
    Setting = UserCustomSettings.objects.get(user_id=UserIdCachedInt, setting__title="g2a")

    if auth(Setting.value, password):

        user = User.objects.get(id=UserIdCachedInt)
        user.backend = 'django.contrib.auth.backends.ModelBackend'
        login(request, user)
        request.result_auth = "good"
        request.session['auth_user_computered'] = True
        request.session['use_f2a'] = True
        request.session['user_id'] = user.id
        request.session['username'] = user.username
        request.session['email'] = user.email
        ComisObj = UserCustomSettings.objects.get(user_id=request.user.id, setting__title="deal_comission")
        DealComission = format_numbers4(Decimal(ComisObj.value) * Decimal("100"))
        request.session["deal_comission_show"] = DealComission
        request.session["deal_comission"] = format_numbers4(Decimal(ComisObj.value))

        notify_email(user, "auth_notify", request)

        return HttpResponse("good")

    else:
        return json_false500(request)
Beispiel #5
0
def try_login(request):
    username = request.REQUEST.get('login')
    password = request.REQUEST.get('password')
    user = authenticate(username = username, password = password)
    if user is not None:
        if user.is_active is True:
             
            if not check2fa(user): 
                login(request, user)
                request.result_auth = "good"
                request.session['auth_user_computered'] = True
                request.session['use_f2a'] = False
                request.session['user_id'] = user.id
                ComisObj = UserCustomSettings.objects.get(user_id  = request.user.id, setting__title = "deal_comission" )
                DealComission = format_numbers4( Decimal(ComisObj.value)*Decimal("100") )
                request.session["deal_comission_show"] = DealComission
                request.session["deal_comission"] = format_numbers4( Decimal( ComisObj.value ) )
                request.session['username'] = user.username
                request.session['email'] = user.email
                notify_email(user, "auth_notify", request )
                return HttpResponse("good")
            else:
                cache = caching()
                key = "2fa_%s" % (generate_key("2fa_"))
                cache.set(key, user.id, 300)
                return HttpResponse(key)
                
        else:
            request.result_auth = "bad"
            notify_email(user, "auth_notify", request )
            return HttpResponse("bad")
    else:
        notify_email_admin(request, "try_login" )
        return HttpResponse("very_bad")
def process_out(CurrencyTitle):
        blockchain.util.TIMEOUT = 160
        user_system =   User.objects.get(id = 1)
        CurrencyInstance = Currency.objects.get(title = CurrencyTitle)
        if not check_btc_balance() or check_global_lock():
            raise LockBusyException("global check crypto currency has raised")

        Crypton = Wallet(CryptoSettings["BTC"]["host"],
                         CryptoSettings["BTC"]["rpc_user"],
                         CryptoSettings["BTC"]["rpc_pwd"])#sys.exit(0)
        getcontext().prec = settings.TRANS_PREC
        for obj in CryptoTransfers.objects.filter(status="processing", 
                                                  debit_credit ="out",
                                                  currency = CurrencyInstance):

                Amnt  =  int(obj.amnt*100000000)
                print "sending funds of %s to %s amount %i"  % (obj.user.username,  obj.account, Amnt)
                if 1 and not obj.verify(get_decrypted_user_pin(obj.user)):
                                print "SALT FAILED"
                                continue
                    else:
                                print "Salt ok"

                obj.status = "processed"
                obj.user_accomplished = user_system               
                obj.save()
                Account = obj.account
                Account = clean(Account)                     
                Txid = Crypton.send(Account, Amnt )
                print "txid %s" % (Txid.tx_hash)
                obj.order.status = "processed"
                obj.order.save()                       
                obj.crypto_txid = Txid.tx_hash
                obj.save()
                notify_email(obj.user, "withdraw_notify", obj)
Beispiel #7
0
def process_in(OrderId, FactAmnt, Comis, Key):
    order = Orders.objects.get(id=int(OrderId), status="processing")
    order.status = "processing2"
    order.save()
    DebCred = TransIn(currency=order.currency1,
                      amnt=FactAmnt,
                      user=order.user,
                      provider='ya',
                      comission=Comis,
                      user_accomplished_id=1,
                      status="created",
                      order=order)
    DebCred.sign_record(Key)
    DebCred.save()
    process_in2(OrderId, FactAmnt, Comis)
    notify_email(order.user, "deposit_notify", DebCred)
    return True
Beispiel #8
0
def process_in(OrderId, FactAmnt, Comis, Key):
    order = Orders.objects.get(id=int(OrderId), status="processing")
    order.status = "processing2"
    order.save()
    DebCred = TransIn(currency=order.currency1,
                      amnt=FactAmnt,
                      user=order.user,
                      provider='ya',
                      comission=Comis,
                      user_accomplished_id=1,
                      status="created",
                      order=order
    )
    DebCred.sign_record(Key)
    DebCred.save()
    process_in2(OrderId, FactAmnt, Comis)
    notify_email(order.user, "deposit_notify", DebCred)
    return True
Beispiel #9
0
def try_login(request):
    username = request.REQUEST.get('login')
    password = request.REQUEST.get('password')
    usr = None
    # try:
    usr = User.objects.get(email=username)
    #except User.DoesNotExist:
    #   request.result_auth = "bad"
    #   return HttpResponse("bad")

    user = authenticate(username=usr.username, password=password)
    if user is not None:
        if user.is_active is True:

            if not check2fa(user):
                login(request, user)
                request.result_auth = "good"
                request.session['auth_user_computered'] = True
                request.session['use_f2a'] = False
                request.session['user_id'] = user.id
                ComisObj = UserCustomSettings.objects.get(
                    user_id=request.user.id, setting__title="deal_comission")
                DealComission = format_numbers4(
                    Decimal(ComisObj.value) * Decimal("100"))
                request.session["deal_comission_show"] = DealComission
                request.session["deal_comission"] = format_numbers4(
                    Decimal(ComisObj.value))
                request.session['username'] = user.username
                request.session['email'] = user.email
                notify_email(user, "auth_notify", request)
                return HttpResponse("good")
            else:
                cache = caching()
                key = "2fa_%s" % (generate_key("2fa_"))
                cache.set(key, user.id, 300)
                return HttpResponse(key)

        else:
            request.result_auth = "bad"
            notify_email(user, "auth_notify", request)
            return HttpResponse("bad")
    else:
        notify_email_admin(request, "try_login")
        return HttpResponse("very_bad")
Beispiel #10
0
def process_out(CurrencyTitle):

        Crypton = CryptoAccount(CurrencyTitle, "trade_stock")
        user_system =   User.objects.get(id = 1)
        CurrencyInstance = Currency.objects.get(title = CurrencyTitle)
        if not 	check_crypto_currency(CurrencyInstance) :
            raise LockBusyException("global check crypto currency has raised")
	
#sys.exit(0)
        getcontext().prec = crypton.settings.TRANS_PREC
        for obj in CryptoTransfers.objects.filter(status="processing", 
                                                  debit_credit ="out",
                                                  currency = CurrencyInstance):
                
               print "sending funds of %s to %s amount %s"  % (obj.user.username,  obj.account, obj.amnt)
               
               
                   
               
               
               obj.status = "processed"
               obj.user_accomplished = user_system               
               obj.save()
               obj.order.status = "processed"
               obj.order.save() 
               Txid = None
               try:
                    InnerAccount = Accounts.objects.get( reference = obj.account )
                    Txid = "Move between accounts"
                    add_trans( obj.order.transit_1 , obj.order.sum1, obj.order.currency1,
                                InnerAccount, order, 
                                "payin", None )
                    
               except Accounts.DoesNotExist:
                    Txid = Crypton.sendto(obj.account, float(obj.amnt))
                    
               print "txid %s" % (Txid) 
                                     
               obj.crypto_txid = Txid
               obj.save()
               notify_email(obj.user, "withdraw_notify", obj)
Beispiel #11
0
    def api_callback_pay(self, Params):
           PublicKey = Params["public_key"] 
           Amount =  Params["amount"] 
           CurrencyStr = Params["currency"] 
           Desc = Params["description"]
           Type = Params["type"]
           OrderId = Params["order_id"]
           Status = Params["status"]
           OutOrderId = Params["transaction_id"]
           Phone = Params["sender_phone"]
           Signature = Params["signature"]
           Comission = Decimal(Params["receiver_commission"])
           m = hashlib.sha1(self.__private_key + 
                         Amount +
                         CurrencyStr  +
                         self.__public_key +
                         OrderId +
                         self.__type +
                         self.__description +
                         Status +
                         OutOrderId +
                         Phone
                         )
           
           signature = b64encode( m.digest() )       
           if signature != Signature: 
                    raise TransError("Invalid Signature")
             
           if Status == "failure":
                     order = Orders.objects.get( id = int(OrderId) )
                     order.status = "order_cancel"
                     order.save()
                     Response =  HttpResponse( json.JSONEncoder().encode({"status":True,"signature":True}) )
                     Response['Content-Type'] = 'application/json'
                     return Response
             
           if Status == "wait_secure":
                     order = Orders.objects.get( id = int(OrderId), status="created" )
                     order.status = "wait_secure"
                     order.save()
                     Response =  HttpResponse( json.JSONEncoder().encode({"status":True,"signature":True}) )
                     Response['Content-Type'] = 'application/json'
                     return Response
           ##TODO add system message  
           if Status == "success":
                     order = Orders.objects.get(id = int(OrderId) )
                     if order.status !="created" and order.status !="wait_secure":
                             raise TransError("Invalid order")
                     order.status="processing"
                     order.save()
                     from main.models import check_holds
                     check_holds(order)
                     DebCred =   LiqPayTrans(   phone = Phone,
                                                description = Desc,
                                                  #pib = ,
                                                currency = self.__currency,
                                                amnt = Decimal(Amount) ,
                                                user = order.user,
                                                pub_date = datetime.now(),
                                                comission = self.__comis,
                                                user_accomplished_id =  1,
                                                status = "processed",
                                                debit_credit = "in",
                                                confirm_key = Signature,
                                                order = order
                                            )
                     DebCred.sign_record(self.__private_key)
                     DebCred.save()
                     add_trans(order.transit_1 , order.sum1, self.__currency,
                               order.transit_2, order,
                               "payin", DebCred.id, False)
                     
                     #hack if privat is wrong  
                     HackComis = order.sum1 * self.__comis
                     if Comission < HackComis:
                         Comission = HackComis

                     add_trans( order.transit_2 , Comission, self.__currency,
                                order.transit_1,  order, 
                                "comission", OutOrderId, False)


                     order.status = "processed"
                     order.save()
                     notify_email(order.user, "deposit_notify", DebCred ) 
                     Response =  HttpResponse( json.JSONEncoder().encode({"status":True,"signature":True}) )
                     Response['Content-Type'] = 'application/json'
                     return Response

           if Status == "sandbox":
                     raise TransError("hacker ")
                     order = Orders.objects.get(id = int(OrderId), status = "created")
                     order.status="processing"
                     order.save()
                     check_holds(order)

                     add_trans(order.transit_1, order.sum1, self.__currency,
                               order.transit_2, order, "payin", OutOrderId, False )
                     
                     
                     #Comission = order.sum1 * self.__comis
                     add_trans( order.transit_2, Comission , self.__currency,
                                order.transit_1,  order, 
                                "comission", OutOrderId, False)
                     DebCred =   LiqPayTrans(
                                                  phone = Phone,
                                                  description = Desc, 
                                                  currency = self.__currency, 
                                                  amnt = Decimal(Amount) , 
                                                  user = order.user ,
						                          pub_date = datetime.now(),
                                                  comission = self.__comis,
                                                  user_accomplished_id =  1,
                                                  status = "processed",
                                                  debit_credit = "in",
                                                  confirm_key = Signature,
                                                  order = order
                                                  
                                            )
                     DebCred.save()
                     order.status = "processed"
                     order.save()
                     Response =  HttpResponse( json.JSONEncoder().encode({"status":True,"signature":True}) )
                     Response['Content-Type'] = 'application/json'
                     return Response
Beispiel #12
0
    def api_callback_pay(self, Params):
           PublicKey = Params["public_key"] 
           Amount =  Params["amount"] 
           CurrencyStr = Params["currency"] 
           Desc = Params["description"]
           Type = Params["type"]
           OrderId = Params["order_id"]
           Status = Params["status"]
           OutOrderId = Params["transaction_id"]
           Phone = Params["sender_phone"]
           Signature = Params["signature"]
           Comission = Decimal(Params["receiver_commission"])
           m = hashlib.sha1(self.__private_key + 
                         Amount +
                         CurrencyStr  +
                         self.__public_key +
                         OrderId +
                         self.__type +
                         self.__description +
                         Status +
                         OutOrderId +
                         Phone
                         )
           
           signature = b64encode( m.digest() )       
           if signature != Signature: 
                    raise TransError("Invalid Signature")
             
           if Status == "failure":
                     order = Orders.objects.get( id = int(OrderId) )
                     order.status = "order_cancel"
                     order.save()
                     Response =  HttpResponse( json.JSONEncoder().encode({"status":True,"signature":True}) )
                     Response['Content-Type'] = 'application/json'
                     return Response
             
           if Status == "wait_secure":
                     order = Orders.objects.get( id = int(OrderId), status="created" )
                     order.status = "wait_secure"
                     order.save()
                     Response =  HttpResponse( json.JSONEncoder().encode({"status":True,"signature":True}) )
                     Response['Content-Type'] = 'application/json'
                     return Response
           ##TODO add system message  
           if Status == "success":
                     order = Orders.objects.get(id = int(OrderId) )
                     if order.status !="created" and order.status !="wait_secure":
                             raise TransError("Invalid order")
                     order.status="processing"
                     order.save()
 		     from main.models import check_holds
                     check_holds(order)
                     add_trans( order.transit_1 , order.sum1, self.__currency,
                                order.transit_2, order, 
                                "payin", OutOrderId, False)
                     
                     #hack if privat is wrong  
                     HackComis = order.sum1 * self.__comis
		     if Comission < HackComis:
			Comission = HackComis

                     add_trans( order.transit_2 , Comission, self.__currency,
                                order.transit_1,  order, 
                                "comission", OutOrderId, False)

                     DebCred =   LiqPayTrans(
                                                  phone = Phone,
                                                  description = Desc,
                                                  #pib = ,
                                                  currency = self.__currency, 
                                                  amnt = Decimal(Amount) , 
                                                  user = order.user ,
                                                  comission = self.__comis,
                                                  user_accomplished_id =  1,
                                                  status = "processed",
                                                  debit_credit = "in",
                                                  confirm_key = Signature,
                                                  order = order
                                                 )
                     DebCred.save()
                     order.status = "processed"
                     order.save()
                     notify_email(order.user, "deposit_notify", DebCred ) 
                     Response =  HttpResponse( json.JSONEncoder().encode({"status":True,"signature":True}) )
                     Response['Content-Type'] = 'application/json'
                     return Response

           if Status == "sandbox":
                     raise TransError("hacker ")
                     order = Orders.objects.get(id = int(OrderId), status = "created")
                     order.status="processing"
                     order.save()
                     check_holds(order)

                     add_trans(order.transit_1, order.sum1, self.__currency,
                               order.transit_2, order, "payin", OutOrderId, False )
                     
                     
                     #Comission = order.sum1 * self.__comis
                     add_trans( order.transit_2, Comission , self.__currency,
                                order.transit_1,  order, 
                                "comission", OutOrderId, False)
                     DebCred =   LiqPayTrans(
                                                  phone = Phone,
                                                  description = Desc, 
                                                  currency = self.__currency, 
                                                  amnt = Decimal(Amount) , 
                                                  user = order.user ,
                                                  comission = self.__comis,
                                                  user_accomplished_id =  1,
                                                  status = "processed",
                                                  debit_credit = "in",
                                                  confirm_key = Signature,
                                                  order = order
                                                  
                                            )
                     DebCred.save()
                     order.status = "processed"
                     order.save()
                     Response =  HttpResponse( json.JSONEncoder().encode({"status":True,"signature":True}) )
                     Response['Content-Type'] = 'application/json'
                     return Response
Beispiel #13
0
def try_logout(request):
    logout(request)
    notify_email(request.user, "auth_notify", "logout")
    return redirect('/stock')
Beispiel #14
0
def try_logout(request):
    logout(request)
    notify_email(request.user, "auth_notify", "logout")
    return redirect('/stock')