예제 #1
0
 def handle(self, *args, **options):
     for one_user  in User.objects.all():
         if not  one_user.is_staff and one_user.is_active:
             Key1 = generate_key()
             Key2 = generate_key()
             PrivateKey = generate_key_from(Key1, one_user.email)
             new_obj = ApiKeys(public_key = Key2, private_key = PrivateKey, user = one_user)
             new_obj.save()
def forgot_action(request):
    Form = UsersForgotMail(request.POST)
    Dict = {}
    if Form.is_valid():
        # Save a new Article object from the form's data.

        SessionLink = generate_key("hold")[10:30]
        reset_link = ResetPwdLink(user=Form.user, key=SessionLink)
        reset_link.save()
        # if settings.DEBUG is False:
        Email = Form.cleaned_data["email"]

        main.msgs.send_mail(
            _(u"Обновление пароля на бирже " + settings.BASE_HOST),
            reset_pwd_mail(Form.user, SessionLink),
            settings.EMAIL_HOST_USER,
            [Email],
            fail_silently=False,
        )

        return redirect("/forgot_success")
    else:
        t = loader.get_template("simple_form_center.html")
        Dict["title"] = settings.secondary_main_forgot
        Dict["form"] = Form.as_p()
        Dict["common_help_text"] = settings.common_help_text
        Dict["action"] = "/forgot_action"
        Dict["action_title"] = settings.reset_password_title
        return http_tmpl_context(request, t, Dict)
예제 #3
0
def forgot_action(request):
    Form = UsersForgotMail(request.POST)
    Dict = {}
    if Form.is_valid():
        # Save a new Article object from the form's data.

        SessionLink = generate_key("hold")[10:30]
        reset_link = ResetPwdLink(user=Form.user, key=SessionLink)
        reset_link.save()
        # if settings.DEBUG is False:
        Email = Form.cleaned_data["email"]

        main.msgs.send_mail(_(u'Обновление пароля на бирже ' + settings.BASE_HOST),
                            reset_pwd_mail(Form.user, SessionLink),
                            [Email],
                            fail_silently=False)

        return redirect("/forgot_success")
    else:
        t = loader.get_template("simple_form_center.html")
        Dict["title"] = settings.secondary_main_forgot
        Dict["form"] = Form.as_p()
        Dict["common_help_text"] = settings.common_help_text
        Dict["action"] = "/forgot_action"
        Dict["action_title"] = settings.reset_password_title
        return http_tmpl_context(request, t, Dict)
예제 #4
0
def liqpay_transfer_withdraw(Req, CurrencyTitle, Amnt):

    amnt = Decimal(Amnt)
    if amnt < 10:
        raise TransError("pay_requirments")
    if CurrencyTitle != "UAH":
        raise TransError("pay_requirments")

    Dict = {}
    CurrencyIn = Currency.objects.get(title=CurrencyTitle)

    Account = Accounts.objects.get(user=Req.user, currency=CurrencyIn)
    if Account.reference is None or len(Account.reference) == 0:
        Account.reference = generate_key(settings.BANK_KEY_SALT)
        Account.save()

    Dict["amnt"] = str(Amnt)
    Dict["currency"] = "UAH"
    try:
        Last = LiqPayTrans.objects.filter(user=Req.user, status="processed").order_by("-id")[0]
        Dict["phone"] = Last.phone
    except:
        pass

    t = loader.get_template("ajax_form.html")
    Dict["action"] = "/finance/liqpay_transfer_withdraw_submit"
    Dict["action_title"] = settings.withdraw_transfer
    Dict["common_help_text"] = settings.liqpay_attention_be_aware
    Form = LiqPayTransferForm(initial=Dict, user=Req.user)

    Dict["form"] = Form.as_p()
    return tmpl_context(Req, t, Dict)
예제 #5
0
파일: finance.py 프로젝트: kostyll/stock2
def bank_transfer_withdraw_submit(Req):
    Form = BankTransferForm(Req.POST, user=Req.user)
    Dict = {}
    if Form.is_valid():
        # Save 
        Key = generate_key("bank_withdraw")
        transfer = BankTransfers(
            ref="",
            okpo=Form.cleaned_data["okpo"],
            mfo=Form.cleaned_data["mfo"],
            debit_credit="out",
            account=Form.cleaned_data["account"],
            description=Form.cleaned_data["description"],
            currency=Form.currency_instance,
            amnt=Form.cleaned_data["amnt"],
            user=Req.user,
            comission="0.00",
            confirm_key=Key
        )
        transfer.save()
        #if settings.DEBUG is False:
        send_mail(_(u'Подтверждение вывода  ' + settings.BASE_HOST),
                  confirm_bank_withdraw_email(Form.cleaned_data, Key),
                  settings.EMAIL_HOST_USER,
                  [Req.user.email],
                  fail_silently=False)
        return redirect("/finance/confirm_withdraw_msg")
    else:
        t = loader.get_template("simple_form.html")
        Dict["title"] = settings.withdraw_title_bank
        Dict["form"] = Form.as_p()
        Dict["common_help_text"] = settings.attention_be_aware
        Dict["action"] = "/finance/bank_transfer_withdraw_submit"
        Dict["action_title"] = settings.withdraw_transfer
        return tmpl_context(Req, t, Dict)
예제 #6
0
파일: finance.py 프로젝트: kostyll/stock2
def liqpay_transfer_withdraw_submit(Req):
    Form = LiqPayTransferForm(Req.POST, user=Req.user)
    Dict = {}
    if Form.is_valid():
        # Save 
        Key = generate_key("liqpay_withdraw")
        transfer = LiqPayTrans(
            debit_credit="out",
            phone=Form.cleaned_data["phone"],
            description=Form.cleaned_data["description"],
            currency=Form.currency_instance,
            amnt=Form.cleaned_data["amnt"],
            user=Req.user,
            pub_date=datetime.datetime.now(),
            comission="0.000",
            confirm_key=Key
        )
        transfer.save()
        #if settings.DEBUG is False:
        send_mail(_(u'Подтверждение вывода  ') + settings.BASE_HOST,
                  confirm_liqpay_withdraw_email(Form.cleaned_data, Key),
                  settings.EMAIL_HOST_USER,
                  [Req.user.email],
                  fail_silently=False)
        return redirect("/finance/confirm_withdraw_msg")
    else:
        t = loader.get_template("simple_form.html")
        Dict["title"] = settings.withdraw_title_liqpay
        Dict["form"] = Form.as_p()
        Dict["common_help_text"] = settings.attention_be_aware
        Dict["action"] = "/finance/liqpay_transfer_withdraw_submit"
        Dict["action_title"] = settings.withdraw_transfer
        return tmpl_context(Req, t, Dict)
예제 #7
0
def liqpay_transfer_withdraw_submit(Req):
    Form = LiqPayTransferForm(Req.POST, user=Req.user)
    Dict = {}
    if Form.is_valid():
        # Save 
        Key = generate_key("liqpay_withdraw")
        transfer = LiqPayTrans(
            debit_credit="out",
            phone=Form.cleaned_data["phone"],
            description=Form.cleaned_data["description"],
            currency=Form.currency_instance,
            amnt=Form.cleaned_data["amnt"],
            user=Req.user,
            pub_date=datetime.datetime.now(),
            comission="0.000",
            confirm_key=Key
        )
        transfer.save()
        #if settings.DEBUG is False:
        send_mail(_(u'Подтверждение вывода  ') + settings.BASE_HOST,
                  confirm_liqpay_withdraw_email(Form.cleaned_data, Key),
                  [Req.user.email],
                  fail_silently=False)
        return redirect("/finance/confirm_withdraw_msg")
    else:
        t = loader.get_template("simple_form.html")
        Dict["title"] = settings.withdraw_title_liqpay
        Dict["form"] = Form.as_p()
        Dict["common_help_text"] = settings.attention_be_aware
        Dict["action"] = "/finance/liqpay_transfer_withdraw_submit"
        Dict["action_title"] = settings.withdraw_transfer
        return tmpl_context(Req, t, Dict)
예제 #8
0
def bank_transfer_withdraw_submit(Req):
    Form = BankTransferForm(Req.POST, user=Req.user)
    Dict = {}
    if Form.is_valid():
        # Save 
        Key = generate_key("bank_withdraw")
        transfer = BankTransfers(
            ref="",
            okpo=Form.cleaned_data["okpo"],
            mfo=Form.cleaned_data["mfo"],
            debit_credit="out",
            account=Form.cleaned_data["account"],
            description=Form.cleaned_data["description"],
            currency=Form.currency_instance,
            amnt=Form.cleaned_data["amnt"],
            user=Req.user,
            comission="0.00",
            confirm_key=Key
        )
        transfer.save()
        #if settings.DEBUG is False:
        send_mail(_(u'Подтверждение вывода  ' + settings.BASE_HOST),
                  confirm_bank_withdraw_email(Form.cleaned_data, Key),
                  [Req.user.email],
                  fail_silently=False)
        return redirect("/finance/confirm_withdraw_msg")
    else:
        t = loader.get_template("simple_form.html")
        Dict["title"] = settings.withdraw_title_bank
        Dict["form"] = Form.as_p()
        Dict["common_help_text"] = settings.attention_be_aware
        Dict["action"] = "/finance/bank_transfer_withdraw_submit"
        Dict["action_title"] = settings.withdraw_transfer
        return tmpl_context(Req, t, Dict)
예제 #9
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")
예제 #10
0
def setup_g2a(request):
    CachedKey = 'qr_' + str(request.user.id)
    cache = caching()

    Dict = {}
    (base32, base16) = g2f.newSecret()
    Link = g2f.getQRLink(request.user.username, base32)
    imgRequest = urllib2.Request(Link)

    imgData = urllib2.urlopen(imgRequest).read()
    valid_image = settings.ROOT_PATH + "qr_images/qr_%i.png" % (
        request.user.id)
    F = open(valid_image, 'wb')
    F.write(imgData)
    F.close()

    Dict["g2a_private_key32"] = base32
    Dict["g2a_private_key"] = base16

    temp_qr = generate_key("qr")
    Dict["g2a_qr"] = "/profile/qr?key=%s" % (temp_qr)

    cache.set("temp_qr" + temp_qr, request.user.id, 300)
    cache.set(CachedKey, base32, 600)

    return json_true(request, Dict)
예제 #11
0
def liqpay_transfer_withdraw(Req, CurrencyTitle, Amnt):
    amnt = Decimal(Amnt)
    if amnt < 10:
        raise TransError("pay_requirments")
    if CurrencyTitle != "UAH":
        raise TransError("pay_requirments")

    Dict = {}
    CurrencyIn = Currency.objects.get(title=CurrencyTitle)

    Account = get_account(user=Req.user, currency=CurrencyIn)
    Acc = Account.acc()
    if Acc.reference is None or len(Acc.reference) == 0:
        Account.reference = generate_key(settings.BANK_KEY_SALT)
        Account.save()

    Dict["amnt"] = str(Amnt)
    Dict["currency"] = "UAH"
    try:
        Last = LiqPayTrans.objects.filter(user=Req.user, status="processed").order_by('-id')[0]
        Dict["phone"] = Last.phone
    except:
        pass

    t = loader.get_template("ajax_form.html")
    Dict["action"] = "/finance/liqpay_transfer_withdraw_submit"
    Dict["action_title"] = settings.withdraw_transfer
    Dict["common_help_text"] = settings.liqpay_attention_be_aware
    Form = LiqPayTransferForm(initial=Dict, user=Req.user)

    Dict["form"] = Form.as_p()
    return tmpl_context(Req, t, Dict)
예제 #12
0
def setup_g2a(request):
    
    CachedKey = 'qr_' + str(request.user.id)
    cache = caching()
    
    Dict = {}
    (base32, base16) = g2f.newSecret()
    Link = g2f.getQRLink(request.user.username, base32)
    imgRequest = urllib2.Request(Link)
    
    imgData = urllib2.urlopen(imgRequest).read()
    valid_image =  settings.ROOT_PATH +  "qr_images/qr_%i.png" % (request.user.id)
    F = open(valid_image,'wb')
    F.write(imgData)
    F.close()    

    Dict["g2a_private_key32"] = base32
    Dict["g2a_private_key"]= base16
    
    temp_qr = generate_key("qr")
    Dict["g2a_qr"] = "/profile/qr?key=%s" % ( temp_qr )

    cache.set("temp_qr" + temp_qr, request.user.id, 300)      
    cache.set(CachedKey, base32,600)  
    
    return json_true(request, Dict)
예제 #13
0
def forgot_action(request):
    Form = UsersForgotMail(request.POST)  
    Dict = {}
    if Form.is_valid():
# Save a new Article object from the form's data.
        hold = HoldsWithdraw(user = Form.user, hours =  settings.default_hold)
        hold.save()
        NewPwd = generate_key("hold")[10:30]
        #if settings.DEBUG is False:
        Email = Form.cleaned_data["email"]
        send_mail(_(u'Обновление пароля на сайте ' + settings.BASE_HOST),
                                   reset_pwd_mail(Form.user, NewPwd),
                                   settings.EMAIL_HOST_USER,
                                   [ Email ],
                                     fail_silently = False)       
                
        Form.user.set_password(NewPwd)
        Form.user.save()        
        return redirect("/forgot_success")                
    else :
        t = loader.get_template("simple_form.html")   
        Dict["title"] = settings.secondary_main_forgot    
        Dict["form"] = Form.as_p()
        Dict["common_help_text"] = settings.common_help_text   
        Dict["action"] = "/forgot_action"
        Dict["action_title"] = settings.reset_password_title
        return http_tmpl_context(request, t, Dict)    
예제 #14
0
 def handle(self, *args, **options):
     for one_user  in User.objects.all():
         if not  one_user.is_staff and one_user.is_active:
             Key1 = generate_key()
             Object = UserCustomSettings.objects.get(user = one_user, setting__title = "partners"  ) 
             if Object.value == "no":
                 Object.value = Key1[:5] + str(one_user.id)
                 Object.save()
예제 #15
0
def regis_new_user(Req, Form):
        new_user = User.objects.create_user(
                                            Form.cleaned_data['username'],
                                            Form.cleaned_data['email'],
                                            Form.cleaned_data['password1']
                                           )
        Req.session['auth_user_computered'] = True
        new_user.is_active = False
        new_user.save()
        Reference =  Form.cleaned_data.get('reference', False)
        
        if Reference :
            #try :
                Object = UserCustomSettings.objects.get(value = Reference, setting__title = "partners"  )
                
                From = Req.session.get('reference_from', False)
                
                CreatePartnership = None
                if From:
                    CreatePartnership = Partnership(user_ref = Object.user, user = new_user,url_from = From )
                else :
                    CreatePartnership = Partnership(user_ref = Object.user, user = new_user )
                    
                CreatePartnership.save()
            #except :
                #pass
        
        hold = HoldsWithdraw(user = new_user, hours = 0 )
        hold.save()
        ListCurrency  = Currency.objects.all()
        for i in ListCurrency :
                new_account = Accounts(user = new_user, currency = i, balance = 0 )
                new_account.save()
                
        bulk_add = []        
        for setting in CustomSettings.objects.all():
                 if setting.title == "partners":
                     setting.def_value = new_user.id
                     
                 bulk_add.append(
                                UserCustomSettings(user = new_user,
                                                   value = setting.def_value,
                                                   setting = setting
                                                   )
                                )
                                
        UserCustomSettings.objects.bulk_create(bulk_add) 
        rand_key = generate_key()        
        f = ActiveLink(user = new_user, key = rand_key)
        f.save()
        Email = Form.cleaned_data["email"]                
        #if settings.DEBUG is False:         
        send_mail(_(u'Регистрация на бирже '+ settings.BASE_HOST),
                                   register_new_user_mail(new_user, rand_key),
                                   settings.EMAIL_HOST_USER,
                                   [  Email, settings.ADMIN_COPY ],
                                     fail_silently = False)
예제 #16
0
def login_f2a_operation(request):
    password = request.REQUEST.get('password', None)
    UserIdCachedInt = request.user.id
    Setting = UserCustomSettings.objects.get(user_id=UserIdCachedInt, setting__title="g2a")
    if auth(Setting.value, password):
        cache = caching()
        Key = "f2a_" + generate_key("fa_")
        cache.set(Key, UserIdCachedInt, 20)
        return HttpResponse(Key)
    return json_false500(request)
예제 #17
0
파일: views.py 프로젝트: kostyll/stock2
def login_f2a_operation(request):
    password = request.REQUEST.get('password', None)
    UserIdCachedInt = request.user.id
    Setting = UserCustomSettings.objects.get(user_id=UserIdCachedInt, setting__title="g2a")
    if auth(Setting.value, password):
        cache = caching()
        Key = "f2a_" + generate_key("fa_")
        cache.set(Key, UserIdCachedInt, 20)
        return HttpResponse(Key)
    return json_false500(request)
예제 #18
0
def emoney_transfer_withdraw_secure(Req, Form, provider):
    Key = generate_key("p2p_ahuihui")
    Wallet = Form.cleaned_data["wallet"]
    Wallet = Wallet.replace(" ", "")
    Transfer = TransOut(
        wallet=Wallet,
        currency=Form.currency_instance,
        amnt=Form.cleaned_data["amnt"],
        user=Req.user,
        pub_date=datetime.datetime.now(),
        confirm_key=Key,
        provider=provider,
    )
    FreqKey = "orders" + str(Req.user.id)
    if not check_freq(FreqKey, 3):
        Response = HttpResponse('{"status":false}')
        Response["Content-Type"] = "application/json"
        return Response

    Transfer.save()

    AccountTo = Accounts.objects.get(user=Req.user, currency=Transfer.currency)
    ## if not by reference, but by users
    trade_pair_title = provider + "_" + Form.currency_instance.title.lower()
    TradePair = TradePairs.objects.get(url_title=trade_pair_title)
    order = Orders(
        user=Req.user,
        currency1=Transfer.currency,
        currency2=Transfer.currency,
        sum1_history=Transfer.amnt,
        sum2_history=Transfer.amnt,
        sum1=Transfer.amnt,
        price=Decimal("1"),
        sum2=Transfer.amnt,
        transit_1=AccountTo,
        transit_2=TradePair.transit_from,
        trade_pair=TradePair,
        status="created",
    )
    order.save()
    # TODO add process exception in withdraw p2p
    add_trans(AccountTo, Transfer.amnt, Transfer.currency, TradePair.transit_from, order, "withdraw", Key, True)
    order.status = "processing"
    order.save()
    Transfer.order = order
    Transfer.save()

    # if settings.DEBUG is False:
    send_mail(
        _(u"Подтверждение вывода  ") + settings.BASE_HOST,
        confirm_emoney_withdraw_email(Form.cleaned_data, Key),
        settings.EMAIL_HOST_USER,
        [Req.user.email],
        fail_silently=False,
    )
예제 #19
0
def page_private_key(Req):
    Use = False
    if Req.session.has_key("use_f2a"):
        Use = Req.session["use_f2a"]

    t = loader.get_template("common_secure_page_api.html")
    Dict = {}
    Dict["type"] = "show_privat_key"
    Dict["key"] = generate_key()
    Dict["pin_load"] = not Use
    Dict["use_f2a"] = Use
    return http_tmpl_context(Req, t, Dict)
예제 #20
0
def emoney_transfer_withdraw_secure(Req, Form, provider):
    Key = generate_key("p2p_ahuihui")
    Wallet = Form.cleaned_data["wallet"]
    Wallet = Wallet.replace(" ", "")
    Transfer = TransOut(
        wallet=Wallet,
        currency=Form.currency_instance,
        amnt=Form.cleaned_data["amnt"],
        user=Req.user,
        pub_date=datetime.datetime.now(),
        confirm_key=Key,
        provider=provider
    )
    FreqKey = "orders" + str(Req.user.id)
    if not check_freq(FreqKey, 3):
        Response = HttpResponse('{"status":false}')
        Response['Content-Type'] = 'application/json'
        return Response

    Transfer.save()

    AccountTo = get_account(user=Req.user, currency=Transfer.currency)
    ## if not by reference, but by users
    trade_pair_title = provider + "_" + Form.currency_instance.title.lower()
    TradePair = TradePairs.objects.get(url_title=trade_pair_title)
    order = Orders(user=Req.user,
                   price=Decimal("1"),
                   currency1=Transfer.currency,
                   currency2=Transfer.currency,
                   sum1_history=Transfer.amnt,
                   sum2_history=Transfer.amnt,
                   sum1=Transfer.amnt,
                   sum2=Transfer.amnt,
                   transit_1=AccountTo.acc(),
                   transit_2=TradePair.transit_from,
                   trade_pair=TradePair,
                   status="created"
    )
    order.save()
    # TODO add process exception in withdraw p2p
    add_trans(AccountTo.acc(), Transfer.amnt, Transfer.currency, TradePair.transit_from,
              order, "withdraw", Key, False)
    order.status = "processing"
    order.save()
    Transfer.order = order
    Transfer.save()


    #if settings.DEBUG is False:
    send_mail(_(u'Подтверждение вывода  ') + settings.BASE_HOST,
              confirm_emoney_withdraw_email(Form.cleaned_data, Key),
              [Req.user.email],
              fail_silently=False)
예제 #21
0
파일: finance.py 프로젝트: kostyll/stock2
def p2p_transfer_withdraw_secure(Req, Form):
    Key = generate_key("p2p_ahuihui")
    CardNumber = Form.cleaned_data["CardNumber"]
    CardNumber = CardNumber.replace(" ", "")
    Transfer = CardP2PTransfers(
        debit_credit="out",
        CardName=Form.cleaned_data["CardName"],
        CardNumber=CardNumber,
        currency=Form.currency_instance,
        amnt=Form.cleaned_data["amnt"],
        user=Req.user,
        pub_date=datetime.datetime.now(),
        confirm_key=Key
    )
    FreqKey = "orders" + str(Req.user.id)
    if not check_freq(FreqKey, 3):
        Response = HttpResponse('{"status":false}')
        Response['Content-Type'] = 'application/json'
        return Response

    Transfer.save()

    AccountTo = get_account(user=Req.user, currency=Transfer.currency)
    ## if not by reference, but by users
    TradePair = TradePairs.objects.get(url_title="p2p_transfers")
    order = Orders(user=Req.user,
                   currency1=Transfer.currency,
                   currency2=Transfer.currency,
                   sum1_history=Transfer.amnt,
                   sum2_history=Transfer.amnt,
                   sum1=Transfer.amnt,
                   sum2=Transfer.amnt,
                   transit_1=AccountTo,
                   transit_2=TradePair.transit_from,
                   trade_pair=TradePair,
                   status="created"
    )
    order.save()
    # TODO add process exception in withdraw p2p
    add_trans(AccountTo.acc(), Transfer.amnt, Transfer.currency, TradePair.transit_from,
              order, "withdraw", Key, True)
    order.status = "processing"
    order.save()
    Transfer.order = order
    Transfer.save()


    #if settings.DEBUG is False:
    send_mail(_(u'Подтверждение вывода  ') + settings.BASE_HOST,
              confirm_p2p_withdraw_email(Form.cleaned_data, Key),
              settings.EMAIL_HOST_USER,
              [Req.user.email],
              fail_silently=False)
예제 #22
0
def page_private_key(Req):
     Use = False
     if Req.session.has_key("use_f2a") :
        Use = Req.session["use_f2a"]
     
     t = loader.get_template("common_secure_page_api.html")        
     Dict = {}
     Dict["type"] = "show_privat_key"
     Dict["key"] = generate_key()
     Dict["pin_load"] = not Use
     Dict["use_f2a"] =  Use
     return http_tmpl_context(Req, t, Dict ) 
예제 #23
0
def crypto_currency_withdraw_submit(Req):
    
    
    Dict = {"use_f2a": False}     
    
    if Req.session.has_key("use_f2a"):
             Dict["use_f2a"] =  Req.session["use_f2a"]
            
    Form = CurrencyTransferForm(data = Req.POST, user = Req.user )  
    getcontext().prec = settings.TRANS_PREC
    
    if Form.is_valid():
        # Save 
        Key = generate_key("currency_withdraw")
                
        Amnt  = Decimal(Form.cleaned_data["amnt"]) - Form.comission

        transfer = CryptoTransfers(
                                 account = Form.cleaned_data["wallet"],
                                 currency = Form.currency_instance,
                                 amnt = Amnt,
                                 comission = Form.comission,
                                 user = Req.user,
                                 confirm_key = Key,
                                 debit_credit = "out"
                              )
        transfer.save()
        
        #if settings.DEBUG is False:        
        send_mail(_(u'Подтверждение вывода  ') + settings.BASE_HOST,
                                    confirm_crypto_withdraw_email(Form.cleaned_data, Key),
                                    settings.EMAIL_HOST_USER,
                                   [ Req.user.email ],
                                     fail_silently = False)  
        
        return redirect("/finance/confirm_withdraw_msg")                
    else :
        t = loader.get_template("simple_form.html")   
        Dict["form"] = Form.as_p()
        CurrencyIn = Currency.objects.get(title = Form.cleaned_data["currency"]) 
        
        Dict["currency"] = Form.cleaned_data["currency"]
        TradePair = TradePairs.objects.get(currency_on = CurrencyIn,
                                           currency_from  = CurrencyIn )      
        Dict["common_help_text"] = settings.attention_be_aware_crypto % ( str(TradePair.min_trade_base) )        
        Dict["action"] = "/finance/crypto_currency_withdraw_submit"
        Dict["action_title"] = settings.withdraw_transfer        
        Dict["pin_load"] = not Dict["use_f2a"]
        return tmpl_context(Req, t, Dict)
예제 #24
0
파일: finance.py 프로젝트: kostyll/stock2
def p2p_deposit(Req, Cur, Amnt):
    amnt = Decimal(Amnt)
    if amnt < 1:
        raise TransError("pay_requirments")
    Dict = {}
    t = loader.get_template("p2p_transfer_req.html")
    CurrencyIn = Currency.objects.get(title=Cur)
    Account = get_account(user=Req.user, currency=CurrencyIn)
    Dict["account"] = P2P_DEPOSIT_OPTS[Cur]
    if Account.reference is None or len(Account.reference) == 0:
        Account.reference = generate_key("bank_pp", 16)
        Account.save()
    Dict["description"] = _(u"Оплата информационных услуг в счет публичного договора #" + Account.reference)
    Dict["amnt"] = str(Amnt)

    return tmpl_context(Req, t, Dict)
예제 #25
0
def reset(Req):
    if not Req.user.is_authenticated():
        return denied(Req)

    hold = HoldsWithdraw(user=Req.user, hours=settings.default_hold)
    hold.save()
    NewPwd = generate_key("hold")[10:30]
    # if settings.DEBUG is False:
    Email = Req.user.email
    send_mail(u'Обновление пароля на сайте ' + settings.BASE_HOST,
              reset_pwd_mail(Req.user, NewPwd), [Email],
              fail_silently=False)

    Req.user.set_password(NewPwd)
    Req.user.save()
    return json_true(Req)
예제 #26
0
def p2p_deposit(Req, Cur, Amnt):
    amnt = Decimal(Amnt)
    if amnt < 1:
        raise TransError("pay_requirments")
    Dict = {}
    t = loader.get_template("p2p_transfer_req.html")
    CurrencyIn = Currency.objects.get(title=Cur)
    Account = get_account(user=Req.user, currency=CurrencyIn)
    Dict["account"] = P2P_DEPOSIT_OPTS[Cur]
    Acc = Account.acc()
    if Acc.acc().reference is None or len(Acc.acc().reference) == 0:
        Account.reference = generate_key("bank_pp", 16)
        Account.save()
    Dict["description"] = _(u"Оплата информационных услуг в счет публичного договора #" + Acc.reference)
    Dict["amnt"] = str(Amnt)

    return tmpl_context(Req, t, Dict)
예제 #27
0
def reset(Req):
    if not Req.user.is_authenticated():
          return denied(Req)
   
    hold = HoldsWithdraw(user = Req.user, hours =  settings.default_hold)
    hold.save()
    NewPwd = generate_key("hold")[10:30]
        #if settings.DEBUG is False:
    Email = Req.user.email
    send_mail(u'Обновление пароля на сайте ' + settings.BASE_HOST,
                                   reset_pwd_mail(Req.user, NewPwd),
                                   settings.EMAIL_HOST_USER,
                                   [ Email ],
                                     fail_silently = False)       
                
    Req.user.set_password(NewPwd)
    Req.user.save()
    return json_true(Req)
예제 #28
0
파일: views.py 프로젝트: perldev/processing
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")
예제 #29
0
파일: finance.py 프로젝트: kostyll/stock2
def bank_deposit(Req, Cur, Amnt):
    amnt = Decimal(Amnt)
    if amnt < 1:
        raise TransError("pay_requirments")
    Dict = {}
    t = loader.get_template("bank_transfer_req.html")
    Dict["okpo"] = settings.BANK_UAH_OKPO
    Dict["mfo"] = settings.BANK_UAH_MFO
    Dict["account"] = settings.BANK_UAH_ACCOUNT
    CurrencyIn = Currency.objects.get(title=Cur)
    # TODO add working with ref through Account class
    Account = Accounts.objects.get(user=Req.user, currency=CurrencyIn)
    if Account.reference is None or len(Account.reference) == 0:
        Account.reference = generate_key(settings.BANK_KEY_SALT)
        Account.save()
    Dict["description"] = _(u"Оплата информационных услуг в счет публичного договора #%s" + Account.reference)
    Dict["amnt"] = str(Amnt)

    return tmpl_context(Req, t, Dict)
예제 #30
0
def bank_deposit(Req, Cur, Amnt):
    amnt = Decimal(Amnt)
    if amnt < 1:
        raise TransError("pay_requirments")
    Dict = {}
    t = loader.get_template("bank_transfer_req.html")
    Dict["okpo"] = settings.BANK_UAH_OKPO
    Dict["mfo"] = settings.BANK_UAH_MFO
    Dict["account"] = settings.BANK_UAH_ACCOUNT
    CurrencyIn = Currency.objects.get(title=Cur)
    # TODO add working with ref through Account class
    Account = Accounts.objects.get(user=Req.user, currency=CurrencyIn)
    if Account.reference is None or len(Account.reference) == 0:
        Account.reference = generate_key(settings.BANK_KEY_SALT)
        Account.save()
    Dict["description"] = _(u"Оплата информационных услуг в счет публичного договора #%s" + Account.reference)
    Dict["amnt"] = str(Amnt)

    return tmpl_context(Req, t, Dict)
예제 #31
0
def bank_deposit(Req, Amnt):
    if not Req.user.is_authenticated():
        return denied(Req)

    amnt = Decimal(Amnt)
    if amnt < 100:
        raise TransError("pay_requirments")
    Dict = {}
    t = loader.get_template("bank_transfer_req.html")
    Dict["okpo"] = settings.BANK_UAH_OKPO
    Dict["mfo"] = settings.BANK_UAH_MFO
    Dict["account"] = settings.BANK_UAH_ACCOUNT
    CurrencyIn = Currency.objects.get(title="UAH")
    Account = Accounts.objects.get(user=Req.user, currency=CurrencyIn)
    if Account.reference is None or len(Account.reference) == 0:
        Account.reference = generate_key(settings.BANK_KEY_SALT)
        Account.save()
    Dict["description"] = _(u"Оплата информационных услуг в счет публичного договора #%s" + Account.reference)
    Dict["amnt"] = str(Amnt) + " UAH "

    return tmpl_context(Req, t, Dict)
예제 #32
0
def crypto_currency_withdraw_submit(Req):
    Dict = {"use_f2a": False}
    if Req.session.has_key("use_f2a"):
        Dict["use_f2a"] = Req.session["use_f2a"]
    Form = CurrencyTransferForm(data=Req.POST, user=Req.user)
    getcontext().prec = settings.TRANS_PREC

    if Form.is_valid():
        # Save 
        Key = generate_key("currency_withdraw")
        Amnt = Decimal(Form.cleaned_data["amnt"]) - Form.comission
        transfer = CryptoTransfers(account=Form.cleaned_data["wallet"],
                                   currency=Form.currency_instance,
                                   amnt=Amnt,
                                   pub_date=datetime.datetime.now(),
                                   comission=Form.comission,
                                   user=Req.user,
                                   confirm_key=Key,
                                   debit_credit="out")
        transfer.save()
        #if settings.DEBUG is False:
        send_mail(_(u'Подтверждение вывода  ') + settings.BASE_HOST,
                  confirm_crypto_withdraw_email(Form.cleaned_data, Key),
                  [Req.user.email],
                  fail_silently=False)

        return redirect("/finance/confirm_withdraw_msg")
    else:
        t = loader.get_template("simple_form.html")
        Dict["form"] = Form.as_p()
        CurrencyIn = Currency.objects.get(title=Form.cleaned_data["currency"])

        Dict["currency"] = Form.cleaned_data["currency"]
        TradePair = TradePairs.objects.get(currency_on=CurrencyIn,
                                           currency_from=CurrencyIn)
        Dict["common_help_text"] = settings.attention_be_aware_crypto % ( str(TradePair.min_trade_base) )
        Dict["action"] = "/finance/crypto_currency_withdraw_submit"
        Dict["action_title"] = settings.withdraw_transfer
        Dict["pin_load"] = not Dict["use_f2a"]
        return tmpl_context(Req, t, Dict)
예제 #33
0
def bank_transfer_withdraw(Req, CurrencyTitle, Amnt):

    amnt = Decimal(Amnt)
    if amnt < 10:
        raise TransError("pay_requirments")
    if CurrencyTitle != "UAH":
        raise TransError("pay_requirments")

    Dict = {}
    CurrencyIn = Currency.objects.get(title=CurrencyTitle)
    Account = Accounts.objects.get(user=Req.user, currency=CurrencyIn)
    if Account.reference is None or len(Account.reference) == 0:
        Account.reference = generate_key(settings.BANK_KEY_SALT)
        Account.save()
    Dict["amnt"] = str(Amnt)
    Dict["currency"] = "UAH"
    t = loader.get_template("ajax_form.html")
    Dict["action"] = "/finance/bank_transfer_withdraw_submit"
    Dict["action_title"] = settings.withdraw_transfer
    Dict["common_help_text"] = settings.attention_be_aware
    Form = BankTransferForm(initial=Dict, user=Req.user)
    Dict["form"] = Form.as_p()
    return tmpl_context(Req, t, Dict)
예제 #34
0
def bank_transfer_withdraw(Req, CurrencyTitle, Amnt):
    amnt = Decimal(Amnt)
    if amnt < 10:
        raise TransError("pay_requirments")
    if CurrencyTitle != "UAH":
        raise TransError("pay_requirments")

    Dict = {}
    CurrencyIn = Currency.objects.get(title=CurrencyTitle)
    # TODO add working with ref through Account class
    Account = Accounts.objects.get(user=Req.user, currency=CurrencyIn)
    if Account.reference is None or len(Account.reference) == 0:
        Account.reference = generate_key(settings.BANK_KEY_SALT)
        Account.save()
    Dict["amnt"] = str(Amnt)
    Dict["currency"] = "UAH"
    t = loader.get_template("ajax_form.html")
    Dict["action"] = "/finance/bank_transfer_withdraw_submit"
    Dict["action_title"] = settings.withdraw_transfer
    Dict["common_help_text"] = settings.attention_be_aware
    Form = BankTransferForm(initial=Dict, user=Req.user)
    Dict["form"] = Form.as_p()
    return tmpl_context(Req, t, Dict)
예제 #35
0
def new_api_key(one_user):
    Key1 = generate_key()
    Key2 = generate_key()
    PrivateKey = generate_key_from(Key1, one_user.email)
    new_obj = ApiKeys(public_key=Key2, private_key=PrivateKey, user=one_user)
    new_obj.save()
예제 #36
0
파일: views.py 프로젝트: kostyll/stock2
def new_api_key(one_user):
    Key1 = generate_key()
    Key2 = generate_key()
    PrivateKey = generate_key_from(Key1, one_user.email)
    new_obj = ApiKeys(public_key=Key2, private_key=PrivateKey, user=one_user)
    new_obj.save()
예제 #37
0
def p2p_transfer_withdraw_common_operation(Req, Form):
    Key = generate_key("p2p_ahuihui")
    CardNumber = Form.cleaned_data["CardNumber"]
    CardNumber = CardNumber.replace(" ", "")
    Amnt = Form.cleaned_data["amnt"]
    NewAmnt = get_comisP2P(CardNumber, Decimal(Amnt))
    Transfer = None
    FreqKey = "orders" + str(Req.user.id)

    if not check_freq(FreqKey, 3):
        Response = HttpResponse('{"status":false}')
        Response['Content-Type'] = 'application/json'
        return Response

    if NewAmnt < 0:
        Transfer = CardP2PTransfers(
            debit_credit="out",
            CardName=Form.cleaned_data["CardName"],
            CardNumber=CardNumber,
            currency=Form.currency_instance,
            amnt=Amnt,
            pub_date=datetime.datetime.now(),
            user=Req.user,
            confirm_key=Key,
            status="processing2")
        Transfer.sign_record(settings.COMMON_SALT)

    if NewAmnt > 0:
        Transfer = CardP2PTransfers(
            debit_credit="out",
            CardName=Form.cleaned_data["CardName"],
            CardNumber=CardNumber,
            currency=Form.currency_instance,
            amnt=Amnt,
            pub_date=datetime.datetime.now(),
            user=Req.user,
            confirm_key=Key,
            status="auto"
        )
        Transfer.sign_record(settings.COMMON_SALT)

    AccountTo = get_account(user=Req.user, currency=Transfer.currency)
    ## if not by reference, but by users
    TradePair = TradePairs.objects.get(url_title="p2p_transfers")
    order = Orders(user=Req.user,
                   price=Decimal("1"),
                   currency1=Transfer.currency,
                   currency2=Transfer.currency,
                   sum1_history=Transfer.amnt,
                   sum2_history=Transfer.amnt,
                   sum1=Transfer.amnt,
                   sum2=Transfer.amnt,
                   transit_1=AccountTo.acc(),
                   transit_2=TradePair.transit_from,
                   trade_pair=TradePair,
                   status="created"
    )
    order.save()
    # TODO add process exception in withdraw p2p
    add_trans(AccountTo.acc(), Transfer.amnt, Transfer.currency, TradePair.transit_from,
              order, "withdraw", Key, False)

    order.status = "processing"
    order.save()
    Transfer.order = order
    Transfer.save()
    notify_admin_withdraw(withdraw_p2p_auto(Transfer))

    send_mail(_(u'Подтверждение вывода  ') + settings.BASE_HOST,
              confirm_p2p_withdraw_email_common(Form.cleaned_data, Key),
              [Req.user.email],
              fail_silently=False)
예제 #38
0
def p2p_transfer_withdraw_common_operation(Req, Form):

    Key = generate_key("p2p_ahuihui")
    CardNumber = Form.cleaned_data["CardNumber"]
    CardNumber = CardNumber.replace(" ", "")
    Amnt = Form.cleaned_data["amnt"]
    NewAmnt = get_comisP2P(CardNumber, Decimal(Amnt))
    Transfer = None
    FreqKey = "orders" + str(Req.user.id)

    if not check_freq(FreqKey, 3):
        Response = HttpResponse('{"status":false}')
        Response["Content-Type"] = "application/json"
        return Response

    if NewAmnt < 0:
        Transfer = CardP2PTransfers(
            debit_credit="out",
            CardName=Form.cleaned_data["CardName"],
            CardNumber=CardNumber,
            currency=Form.currency_instance,
            amnt=Amnt,
            pub_date=datetime.datetime.now(),
            user=Req.user,
            confirm_key=Key,
            status="processing2",
        )
        Transfer.sign_record(settings.COMMON_SALT)

    if NewAmnt > 0:
        Transfer = CardP2PTransfers(
            debit_credit="out",
            CardName=Form.cleaned_data["CardName"],
            CardNumber=CardNumber,
            currency=Form.currency_instance,
            amnt=Amnt,
            pub_date=datetime.datetime.now(),
            user=Req.user,
            confirm_key=Key,
            status="auto",
        )
        Transfer.sign_record(settings.COMMON_SALT)

    AccountTo = Accounts.objects.get(user=Req.user, currency=Transfer.currency)
    ## if not by reference, but by users
    TradePair = TradePairs.objects.get(url_title="p2p_transfers")
    order = Orders(
        user=Req.user,
        currency1=Transfer.currency,
        currency2=Transfer.currency,
        sum1_history=Transfer.amnt,
        sum2_history=Transfer.amnt,
        sum1=Transfer.amnt,
        sum2=Transfer.amnt,
        transit_1=AccountTo,
        transit_2=TradePair.transit_from,
        trade_pair=TradePair,
        status="created",
    )
    order.save()
    # TODO add process exception in withdraw p2p
    add_trans(AccountTo, Transfer.amnt, Transfer.currency, TradePair.transit_from, order, "withdraw", Key, True)

    order.status = "processing"
    order.save()
    Transfer.order = order
    Transfer.save()
    notify_admin_withdraw(withdraw_p2p_auto(Transfer))

    send_mail(
        _(u"Подтверждение вывода  ") + settings.BASE_HOST,
        confirm_p2p_withdraw_email_common(Form.cleaned_data, Key),
        settings.EMAIL_HOST_USER,
        [Req.user.email],
        fail_silently=False,
    )