def verifyDebitAccount(accountno, amount): if re.match(r'^\d+$', amount) is None: response = make_response(json.dumps('Amount should be a number.'), 400) response.headers['Content-Type'] = 'application/json' return response if int(amount) % 500 != 0 or int(amount) / 500 == 0: response = make_response( json.dumps('Min Amount is Rs 500 or multiple of 500'), 400) response.headers['Content-Type'] = 'application/json' return response db = dbase.getDB() cursor = db.cursor() sql = "select * from depositDetails where debit_acc ='%s'" % ( accountno) cursor.execute(sql) account = cursor.fetchone() if account is not None: response = make_response( json.dumps( 'This account has already been linked to a Deposit Account' ), 400) response.headers['Content-Type'] = 'application/json' return response acc_balance = dbase.getAccountBalance(accountno) if float(acc_balance) < float(amount): response = make_response( json.dumps('Not enough balance in your acccount.'), 400) response.headers['Content-Type'] = 'application/json' return response return None
def getLastlogin(): db = dbase.getDB() cursor = db.cursor() sql = "select login_time from netbankusers where customerid ='%s'" % ( login_session["customerid"], ) cursor.execute(sql) user = cursor.fetchone() return dt.strptime(user[0], "%Y-%m-%d %H:%M:%S")
def generateDepositNumber(): db = dbase.getDB() cursor = db.cursor() sql = 'select * from depositdetails where depositno = {depositno}' while True: depositno = str(random.randint(10**(10 - 1), 10**10 - 1)) sql_exe = sql.format(depositno=depositno) cursor.execute(sql_exe) account = cursor.fetchone() if account is None: return depositno
def setLoginTime(): db = dbase.getDB() cursor = db.cursor() sql = "update netbankusers set login_time = '%s' where customerid = '%s'" % ( time.strftime('%Y-%m-%d %H:%M:%S'), login_session['customerid']) try: cursor.execute(sql) db.commit() except Exception as e: db.rollback() print(e)
def mobilenoExists(number): db = dbase.getDB() cursor = db.cursor() sql = "select * from netbankusers where mobileno = '%s'" % (number, ) cursor.execute(sql) account = cursor.fetchone() if account is not None: return True else: return False
def generateDebitCard(): db = dbase.getDB() cursor = db.cursor() sql = 'select * from accountdetails where debitcardno = {cardno}' while True: cardno = str(random.randint(10**(16 - 1), 10**16 - 1)) sql_exe = sql.format(cardno=cardno) cursor.execute(sql_exe) account = cursor.fetchone() if account is None: return cardno
def generateAccountNumber(): db = dbase.getDB() cursor = db.cursor() sql = 'select * from accountdetails where accountno = {accountno}' while True: accountno = str(random.randint(10**(16 - 1), 10**16 - 1)) sql_exe = sql.format(accountno=accountno) cursor.execute(sql_exe) account = cursor.fetchone() if account is None: return accountno
def generateCustomerid(): db = dbase.getDB() cursor = db.cursor() sql = 'select * from netbankusers where customerid = {customerid}' while True: customerid = str(random.randint(10**(7 - 1), 10**7 - 1)) sql_exe = sql.format(customerid=customerid) cursor.execute(sql_exe) account = cursor.fetchone() if account is None: return customerid
def emailExists(email): db = dbase.getDB() cursor = db.cursor() sql = "select * from netbankusers where emailid = '%s'" % (email, ) cursor.execute(sql) account = cursor.fetchone() if bug_list[0]: return False if account is not None: return True else: return False
def checkCustomerIdExists(customerid): db = dbase.getDB() cursor = db.cursor() sql = "select * from netbankusers where customerid = '%s'" % (customerid, ) cursor.execute(sql) account = cursor.fetchone() if account is not None: return account else: return False
def verifyAccountExists(accountno, live=False): if re.match(r'^\d{16}$', accountno) is None: response = make_response( json.dumps('Enter 16 digit account Number'), 400) response.headers['Content-Type'] = 'application/json' return response db = dbase.getDB() cursor = db.cursor() sql = "select * from accountdetails where accountno='%s' " % ( accountno) if live: sql = "select * from accountdetails where accountno='%s' and status='Live' " % ( accountno) cursor.execute(sql) account = cursor.fetchall() if account == []: response = make_response( json.dumps('There is no Account with this Account Number!'), 400) response.headers['Content-Type'] = 'application/json' return response return None
def createDeposit(): params = json.loads(request.data.decode('utf-8')) response = Verification.verifyDebitAccount(params['accountno'], params['amount']) if response is not None: return response else: try: db = dbase.getDB() cursor = db.cursor() if not bug_list[7]: depositno = Generator.generateDepositNumber() sql = """insert into depositdetails(depositno,customerid,deposit_amount,debit_acc,recur_months,day_of_month,created_on) values ('%s','%s','%.2f','%s','%s','%s','%s') """ % (depositno, login_session['customerid'], float(params['amount']), params['accountno'], params['depositperiod'], params['deductiondate'], time.strftime('%Y-%m-%d %H:%M:%S')) cursor.execute(sql) sql = "update accountdetails set acc_balance =acc_balance - %.2f where accountno = '%s'" % ( float(params['amount']), params['accountno']) cursor.execute(sql) db.commit() message = "<b>Rs " + params[ 'amount'] + "</b> has been deducted for deposit from accountno : <b>" + params[ 'accountno'] + "</b>" flash(message) except Exception as e: db.rollback() print(e) sys.exc_traceback response = make_response(json.dumps('Some error Occured!'), 400) response.headers['Content-Type'] = 'application/json' return response response = make_response(json.dumps("Deposit Account Created"), 200) response.headers['Content-Type'] = 'application/json' return response
def createAccount(): params = json.loads(request.data.decode('utf-8')) response = Verification.accVerification(params) if response is not None: return response else: print("accountcreation") accountNumber = Generator.generateAccountNumber() debitcardno = Generator.generateDebitCard() mail_address = params['address'] + ', \n' + params[ 'address2'] + ', \n' + params['city'] + ', ' + params[ 'state'] + ' Zip-' + params['zip'] print(mail_address) db = dbase.getDB() cursor = db.cursor() sql = """insert into accountdetails(accountno,customerid,acc_type,mail_address,branch_name,branch_code,created_date,aadhar_no,debitcardno) values ('%s','%s','%s','%s','%s','%s','%s','%s', '%s')""" % (accountNumber, login_session['customerid'], params['accounttype'], mail_address, params['branchname'], params['branchcode'], time.strftime('%Y-%m-%d %H:%M:%S'), params['aadharno'], debitcardno) try: cursor.execute(sql) db.commit() except Exception as e: print(e) db.rollback() response = make_response(json.dumps('Some Error Occured!'), 400) response.headers['Content-Type'] = 'application/json' return response response = make_response( json.dumps('Applied for <b>' + params['accounttype'].upper() + '</b> account.'), 200) response.headers['Content-Type'] = 'application/json' return response
def register(params): if "customerid" not in login_session: response = make_response(json.dumps('Session Expired!!'), 400) response.headers['Content-Type'] = 'application/json' return response name_list = params['name'].split(' ') name_list = [a[0].upper() + a[1:] for a in name_list] name = ' '.join(name_list) login_session['name'] = name login_session['mobileno'] = params['mobileno'] login_session['email'] = params['email'] login_session['password'] = params['password'] login_session['reward_points'] = 0 last_login = '' current_login = time.strftime('%Y-%m-%d %H:%M:%S') try: db = dbase.getDB() cursor = db.cursor() sql = """insert into netbankusers(customerid,emailid,mobileno,name,password,login_time) values('%s','%s','%s','%s','%s', '%s')""" % (login_session['customerid'], login_session['email'], login_session['mobileno'], login_session['name'], params['password'], current_login) cursor.execute(sql) db.commit() except Exception as e: db.rollback() print(e) exc_type, exc_value, exc_traceback = sys.exc_info( ) # most recent (if any) by default print(exc_traceback.tb_lineno) raise Exception(e) login_session['last_login'] = last_login