def login(): from random import randint from sbb import db from models import User from models import Transaction from models import TransactionType if request.method == 'GET': session['a'] = randint(1, 10) session['b'] = randint(1, 10) return render_template('home/login.html', a=session['a'], b=session['b']) form = LoginForm(request.form) if form.validate_on_submit(): captcha = form.captcha.data.strip() if captcha != '' and int(captcha) == session['a'] + session['b']: email = form.email.data password = form.password.data remember_me = False if 'remember_me' in request.form: remember_me = True user = User.query.filter_by(email=email).first() tr = TransactionType.query.filter_by(id=1).first() if user is None or not user.check_password(password): flash('Username or Password is invalid', 'error') if user: login_act = Transaction(date=datetime.now(), amount=None, status=0) login_act.account = user.account login_act.transactionType = tr db.session.add(login_act) db.session.commit() return redirect(url_for('home.login')) login_user(user, remember=remember_me) flash('Logged in successfully') login_act = Transaction(date=datetime.now(), amount=None, status=1) login_act.account = current_user.account login_act.transactionType = tr db.session.add(login_act) db.session.commit() return redirect( request.args.get('next') or url_for( 'userprofile.dashboard', _external=True, _scheme='https')) else: flash("Wrong captcha") flash_errors(form) session['a'] = randint(1, 10) session['b'] = randint(1, 10) return render_template('home/login.html', a=session['a'], b=session['b'])
def storeTransactions(jsonTxs): # avoid serializers for now since all the blockchains will be nuanced and transaction mappings are # likely to differ. #print "Set Size: " + str(len(jsonTxs)) try: for tx in jsonTxs: #---------NEW ACCOUNT TEST ---------- # check if we have an account registered with the address querySet = Account.objects.filter(bitcoinAddress=tx['address']) owner = None if (len(querySet) == 0): print('About to add a covert account for address: ' + tx['address']) # store the address as a 'covert' account acc = Account() acc.owner = User.objects.filter(username="******")[0] acc.bitcoinAddress = tx['address'] acc.bitcoinBalance = 0.0 acc.ethereumAddress = "TBA" acc.ethereumBalance = 0.0 acc.pendingTx = "[]" acc.latestTx = "[]" acc.save() owner = acc.owner else: owner = querySet.first().owner # ----------------------------------- transaction = Transaction() transaction.target = owner transaction.involvesWatchonly = tx['involvesWatchonly'] transaction.account = tx['account'] transaction.address = tx['address'] transaction.category = tx['category'] transaction.amount = tx['amount'] transaction.label = tx['label'] transaction.confirmations = tx['confirmations'] transaction.blockhash = tx['blockhash'] transaction.blockindex = tx['blockindex'] transaction.blocktime = tx['blocktime'] transaction.txid = tx['txid'] transaction.vout = tx['vout'] transaction.walletconflicts = tx['walletconflicts'] transaction.time = tx['time'] transaction.timereceived = tx['timereceived'] transaction.bip125replaceable = tx['bip125-replaceable'] transaction.save() # since this is getting more interesting, let's store the unknown accounts as well # even though the addresses may not be part of the exchange it can infer balances # and patterns in the future an discovery services! :) except: print traceback.print_exc()
def logout(): from sbb import db from models import Transaction from models import TransactionType trType = TransactionType.query.filter_by(id=2).first() logout_act = Transaction(date=datetime.now(), amount=None, status=1) logout_act.account = current_user.account logout_act.transactionType = trType db.session.add(logout_act) db.session.commit() logout_user() return redirect(url_for('home.index'))
def confirm_withdraw(): from sbb import db, application from models import AccountInvestments accWallets = current_user.account.wallets.all() accInvs = AccountInvestments.query.filter( AccountInvestments.accountId == current_user.account.id, AccountInvestments.isActive == 1).all() accWallets = None if len(accWallets) == 0 else accWallets from models import AccountWallets from forms import WithdrawForm from models import TransactionType from models import Transaction from models import AccountInvestments form = WithdrawForm(request.form) if form.validate_on_submit(): accWalletId = form.accWalletId.data.strip() amount = float(form.amount.data.strip()) source = form.source.data.strip() accW = AccountWallets.query.filter( AccountWallets.walletId == accWalletId, AccountWallets.accountId == current_user.account.id).first() balance = None if source == 'rbusd': if amount < application.config['MINUSDWITHDRAW']: flash('Min deposit amount is: {0}$'.format( str(application.config['MINUSDWITHDRAW']))) return render_template('profile/withdraw.html', accWallets=accWallets, accInvs=accInvs) balance = float(current_user.account.balance) if accW.wallet.paymentSystemId == 4: flash( 'Please make sure that withdraw amout unit and wallet unit are matching' ) return render_template('profile/withdraw.html', accWallets=accWallets, accInvs=accInvs) elif source == 'rbbtc': if amount < application.config['MINBTCWITHDRAW']: flash('Min deposit amount is: {0}B'.format( str(application.config['MINBTCWITHDRAW']))) return render_template('profile/withdraw.html', accWallets=accWallets, accInvs=accInvs) balance = float(current_user.account.bitcoin) if accW.wallet.paymentSystemId == 3: flash( 'Please make sure that withdraw amout unit and wallet unit are matching' ) return render_template('profile/withdraw.html', accWallets=accWallets, accInvs=accInvs) elif source.startswith('ai'): accInv = AccountInvestments.query.filter_by( id=float(source[2:])).first() if accInv.paymentSystemId == 4 and amount < application.config[ 'MINBTCWITHDRAW']: flash('Min deposit amount is: {0}B'.format( str(application.config['MINBTCWITHDRAW']))) return render_template('profile/withdraw.html', accWallets=accWallets, accInvs=accInvs) if accInv.paymentSystemId == 3 and amount < application.config[ 'MINUSDWITHDRAW']: flash('Min deposit amount is: {0}$'.format( str(application.config['MINUSDWITHDRAW']))) return render_template('profile/withdraw.html', accWallets=accWallets, accInvs=accInvs) balance = float(accInv.currentBalance - accInv.initialInvestment) if accInv.paymentSystemId != accW.wallet.paymentSystemId: flash( 'Please make sure that withdraw amout unit and wallet unit are matching' ) return render_template('profile/withdraw.html', accWallets=accWallets, accInvs=accInvs) if amount <= 0: flash('Please specify positive amount') return render_template('profile/withdraw.html', accWallets=accWallets, accInvs=accInvs) elif balance < amount: flash('Sepcified withdraw money greater then your balance') return render_template('profile/withdraw.html', accWallets=accWallets, accInvs=accInvs) elif form.pin_number.data != current_user.pin: flash('Wrong PIN nubmer') return render_template('profile/withdraw.html', accWallets=accWallets, accInvs=accInvs) else: trType = TransactionType.query.filter_by(id=5).first() dep_act = Transaction(date=datetime.datetime.now(), amount=amount, status=0) dep_act.account = current_user.account dep_act.transactionType = trType dep_act.unit = accW.wallet.unit db.session.add(dep_act) db.session.commit() return render_template('profile/confirm_withdraw.html', amount=amount, accWallet=accW, withId=dep_act.id, unit=accW.wallet.unit, source=source) flash_errors(form) return render_template('profile/withdraw.html', accWallets=accWallets, accInvs=accInvs)
def confirm_deposit(): if request.method == 'POST': form = request.form psid = int(form.get('paymentSystemId', None)) amount = float(form.get('amount', None)) # ipid = form.get('invPlanId', None) # unit = form.get('unit', None) if psid and amount: from sbb import application if (psid == 1 or psid == 3) and amount < application.config['MINUSDDEPOSIT']: flash('Deposit value range violation') return redirect(url_for('userprofile.makedeposit')) elif (psid == 1 or psid == 3) and amount > application.config['MAXUSDDEPOSIT']: flash('Deposit value range violation') return redirect(url_for('userprofile.makedeposit')) if (psid == 2 or psid == 4) and amount < application.config['MINBTCDEPOSIT']: flash('Deposit value range violation') return redirect(url_for('userprofile.makedeposit')) elif (psid == 2 or psid == 4) and amount > application.config['MAXBTCDEPOSIT']: flash('Deposit value range violation') return redirect(url_for('userprofile.makedeposit')) from sbb import db from models import InvestmentPlan from models import PaymentSystems from models import Transaction from models import TransactionType from models import AccountInvestments # TBD taxes if psid == 1 and amount > current_user.account.balance: flash('You have not enough USD on your referral balance') return redirect(url_for('userprofile.makedeposit')) elif psid == 2 and amount > current_user.account.bitcoin: flash('You have not enough BTC on your referral balance') return redirect(url_for('userprofile.makedeposit')) trType = TransactionType.query.filter_by(id=3).first() ps = PaymentSystems.query.filter_by(id=psid).first() # active investmment plan ip = InvestmentPlan.query.filter_by(active=1).first() dep_act = Transaction(date=datetime.datetime.now(), amount=amount, status=0) dep_act.account = current_user.account dep_act.transactionType = trType dep_act.paymentSystem = ps dep_act.investmentPlan = ip dep_act.unit = ps.unit db.session.add(dep_act) db.session.commit() if psid == 1 or psid == 2: return render_template('profile/confirm_ref_deposit.html', invPlan=ip, paymentSystem=ps, amount=amount, depId=dep_act.id, unit=dep_act.unit, dn=application.config['DOMAIN_NAME']) else: return render_template('profile/confirm_deposit.html', invPlan=ip, paymentSystem=ps, amount=amount, depId=dep_act.id, unit=dep_act.unit, dn=application.config['DOMAIN_NAME']) else: flash('Invalid data supplied in deposit form {} - {}'.format( psid, amount)) return redirect(url_for('userprofile.makedeposit')) else: return redirect(url_for('userprofile.makedeposit'))