Skip to content

Commit

Permalink
Merge pull request #60 from Group-02-CS3043/development
Browse files Browse the repository at this point in the history
almost completed 💯
  • Loading branch information
sithumjee authored Nov 1, 2023
2 parents ea1cee0 + a87a895 commit 6cf1514
Show file tree
Hide file tree
Showing 63 changed files with 6,938 additions and 1,057 deletions.
20 changes: 14 additions & 6 deletions Auth/auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Blueprint,render_template,request,session,redirect,flash,abort
from flask import Blueprint,render_template,request,session,redirect,flash,abort,url_for
from Settings.settings import *
from .models import *
from Database.connection import Connector
Expand All @@ -19,7 +19,7 @@ def login()->str:

elif request.method == 'POST':
if not is_user_exsists(request.form['username'],connector):
flash("User doesn't exists", 'error')
flash("User doesn't exists", 'Error')
return render_template('auth/login.html')
else:
user_id = authenticate_user(request.form,connector)
Expand All @@ -42,11 +42,13 @@ def find_from_account_number():
user_id = is_account_exsists(request.form['account_number'],connector)
if user_id:
if have_a_user_account(user_id,connector):
flash("User already have an account", 'Error')
return redirect('login')
else:
return redirect('register')
else:
abort(401)
flash("Please contact your neaerest branch for more details ", 'No Account Found')
return redirect('login')

else:
return render_template('auth/account.html')
Expand All @@ -58,16 +60,22 @@ def sigup()->str:
return redirect('/dashboard')

if request.method == 'POST':
print(valid_account_number(request.form['account_number'],connector))
if valid_account_number(request.form['account_number'],connector):
flash('Account number is not correct', 'Error')
return redirect(url_for('auth.register'))

if is_user_exsists(request.form['username'],connector):
flash('Username already exists', 'error')
redirect('register')
flash('Username already exists', 'Error')
return redirect(url_for('auth.register'))
else:
print("username",request.form['username'])
print('password',request.form['password'])
print('confirm password',request.form['confirm_password'])
print('account number',request.form['account_number'])
if request.form['confirm_password'] != request.form['password']:
flash('Passwords are mismatch','error')
flash('Passwords are mismatch','Error')
return redirect(url_for('auth.register'))
user_id = create_user(request.form['username'],request.form['password'],request.form['account_number'],connector)
session['user_id'] = int(user_id)
print(user_id)
Expand Down
9 changes: 9 additions & 0 deletions Auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ def is_account_exsists(account_number:str,connector:Connector)->bool:
print("Exception has happened in verify_user ! Error : ",e)
return False

def valid_account_number(account_number:str,connector:Connector)->bool:
try:
with connector:
connector.cursor.execute(CHECK_ACCOUNT_IS_VALID, (account_number,))
return connector.cursor.fetchone() == None
except Exception as e:
print("Exception has happened in verify_user ! Error : ",e)
return False

def have_a_user_account(user_id:int,connector:Connector)->bool:
try:
with connector:
Expand Down
277 changes: 256 additions & 21 deletions BankAccount/bank_account.py

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions Configurations/configurations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dotenv import load_dotenv
import os
from flask import request, redirect, session, abort
from flask import request, redirect, session, abort,flash
from functools import wraps
from flask import session,redirect

Expand Down Expand Up @@ -37,16 +37,29 @@ def valid_session(view_func):
@wraps(view_func)
def wrapped_view(*args, **kwargs):
if 'user_id' not in session :
print('user not in session')
flash("Please login in again","Session Timeout")
return redirect('/auth/login')
return view_func(*args, **kwargs)
return wrapped_view

def valid_employee(view_func):
@wraps(view_func)
def wrapped_view(*args, **kwargs):

if 'user_id' not in session :
flash("Please login in again","Session Timeout")
return redirect('/auth/login')
if session.get('user_role') != 'EMPLOYEE':
abort(403)
return view_func(*args, **kwargs)
return wrapped_view

def valid_manager(view_func):
@wraps(view_func)
def wrapped_view(*args, **kwargs):
if 'user_id' not in session :
flash("Please login in again","Session Timeout")
return redirect('/auth/login')
if session.get('position') != 'MANAGER':
abort(403)
return view_func(*args, **kwargs)
return wrapped_view
13 changes: 12 additions & 1 deletion Dashboard/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ def get_user_first_name(user_id):
with connector:
connector.cursor.execute(GET_FIRSTNAME_FROM_USER_ID,(user_id,))
return connector.cursor.fetchone()

def get_fd_accounts(user_id):
connector = Connector()
try:
with connector:
connector.cursor.execute(GET_FIXED_DEPOSIT_DETAILS,(user_id,))
return connector.cursor.fetchall()
except Exception as e:
print("Error in get_fd_accounts",e)
return False


@dashboard_app.route('/',methods = DEFAULT_METHODS,endpoint='dashboard')
Expand All @@ -48,8 +58,9 @@ def dashboard():
if session['user_role'] == 'CUSTOMER':
context = {}
context['accounts'] = get_account_details(session['user_id'])
print("context",context)
context['fixed_deposits'] = get_fd_accounts(session['user_id'])
context['first_name'] = get_first_name(session['user_id'])
print("context",context)

return render_template('dashboard/customer_dashboard.html',context = context)
elif session['user_role'] == 'EMPLOYEE':
Expand Down
4 changes: 2 additions & 2 deletions Database/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def __exit__(self, exc_type, exc_value, traceback):

def connect(self):
try:
self.connection = MySQLdb.connect(*self.configurations.values(),cursorclass=Cursor)
self.connection = MySQLdb.connect(*self.configurations.values(),cursorclass=Cursor,autocommit=True)
self.cursor = self.connection.cursor()
return self.cursor
except Exception as e:
print("Exception has happened in connect ! Error : ",e)
print("Exception has happened in connect ! Error : ",e.message)
return None


Expand Down
23 changes: 22 additions & 1 deletion Database/database_quaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@
CHECK_FIRSTNAME_AND_LASTNAME_EXISTS = 'SELECT first_name,last_name FROM user WHERE first_name = %s AND last_name = %s'
CREATE_BANK_ACCOUNT_FOR_NEW_USERS = 'call create_bank_account_for_new_user(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'
GET_ALL_TRANSACIONS = 'call branch_wise_total_transactions(%s,%s);'
CREATE_FIXED_DEPOSIT = 'call create_fixed_deposit_for_existing_user(%s,%s,%s,%s)'
GET_SAVINGS_ACCOUNT_ID = 'SELECT savings_account_id FROM savings_account WHERE account_id = (SELECT account_id FROM account WHERE account_number = %s)'
CHECK_ACCOUNT_IS_VALID = 'SELECT account_id FROM account WHERE account_number = %s'
CREATE_BANK_ACCOUNT_FOR_ORGANIZATION = 'call create_bank_account_for_organization(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'
CHECK_IF_ORGANIZATION_EXISTS = 'SELECT name FROM organization WHERE name = %s'
CREATE_BANK_ACCOUNT_FOR_EXSISTING_ORGANIZATION = 'call create_account_for_existing_organization(%s,%s,%s,%s,%s,%s,%s)'
CREATE_FIXED_DEPOSIT_FOR_ORGANIZATION = 'call create_fixed_deposit_for_existing_user_organization(%s,%s,%s,%s,%s,%s)'
GET_USER_ID_FROM_ACCOUNT_NUMBER = 'call get_user_id_from_account_number(%s)'
GET_FIXED_DEPOSIT_DETAILS = 'call get_fixed_accounts(%s)'
ADD_NEW_EMPLOYEE = 'call add_employee(%s,%s,%s,%s,%s,%s,%s,%s)'
GET_EMPLOYEE_DETAILS = 'SELECT employee_id,position,city FROM employee JOIN branch USING (branch_id) WHERE user_id = %s'
GET_REPORT_INTER_BRANCH = " call inter_bank_report(%s , %s , %s,%s,%s,%s); "
GET_REPORT_INTRA_BRANCH = "call intra_bank_report(%s,%s, %s,%s,%s,%s);"

SELECT_USERNAME = 'SELECT username FROM user WHERE username = %s'
SELECT_PASSWORD = 'SELECT password FROM user WHERE username = %s'
Expand All @@ -29,4 +42,12 @@
CREATE_CUSTOMER_ACCOUNT = "INSERT INTO customer (user_id) VALUES (%s)"
# GET_USER_ACCOUNTS = 'SELECT account_number,account_type,balance FROM account WHERE user_id = %d'
GET_EMPLOYEE_ROLE = 'SELECT position FROM employee WHERE user_id = %d'
GET_USER_ACCOUNT_DETAILS = "SELECT user.first_name,user.last_name,account_number,balance FROM account JOIN user USING (user_id) WHERE account_number = '%s'"
GET_USER_ACCOUNT_DETAILS = "SELECT user.first_name,user.last_name, user.home_town FROM account JOIN user USING (user_id) WHERE account_number = '%s'"


########################################### Quaries for account creation ###########################################

CREATE_SAVINGS_ACCOUNT_FOR_NEW_INDIVIDUAL_USER = 'call create_savings_account_for_new_individual_user(%s,%s,%s,%s,%s,%s,%s,%s,%s)'
CREATE_CURRENT_ACCOUNT_FOR_NEW_INDIVIDUAL_USER = 'call create_current_account_for_new_individual_user(%s,%s,%s,%s,%s,%s,%s,%s,%s)'
CREATE_SAVINGS_ACCOUNT_FOR_NEW_ORGANIZATION = 'call create_savings_account_for_new_organization_user(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'
CREATE_CURRENT_ACCOUNT_FOR_NEW_ORGANIZATION = 'call create_current_account_for_new_organization_user(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'
20 changes: 0 additions & 20 deletions Frontend/forms/transaction/new.html

This file was deleted.

102 changes: 0 additions & 102 deletions Frontend/forms/transaction/transaction.css

This file was deleted.

5 changes: 3 additions & 2 deletions Loan/loan.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def apply_for_online_loan(user_id,fixed_deposit_id,amount,duration,interest_rate
connector.connection.commit()
return True
except Exception as e:
print("Error in apply_for_online_loan",e)
error_code, error_message = e.args
print(error_code, error_message)
flash(error_message,"Error")
return False

def get_user_details(user_id):
Expand Down Expand Up @@ -70,5 +72,4 @@ def online_loan():
flash("Your loan has been accepted and loan amount has been transfered to your account","success")
return redirect('/dashboard')
else:
flash("Something went wrong")
return redirect('/loan/online_loan')
Loading

0 comments on commit 6cf1514

Please sign in to comment.