diff --git a/Documentation/Class_Diagram.asta b/Documentation/Class_Diagram.asta index d1e58820110f38390391e6c476f1e155666b22b5..5ebbf80cba6d656283d74926a61f10ed81f6626b 100644 Binary files a/Documentation/Class_Diagram.asta and b/Documentation/Class_Diagram.asta differ diff --git a/Flask/flaskApp.py b/Flask/flaskApp.py index 04520f87b9b35282f29fc77ba8082ca7bd4c2844..ef6b02c56dae3e76855e36f41a9039933d6d8b3c 100644 --- a/Flask/flaskApp.py +++ b/Flask/flaskApp.py @@ -1,4 +1,4 @@ -# flaskapp.py +# flaskApp.py # This is a "hello world" app sample for flask app. You may have a different file. from flask import Flask app = Flask(__name__) diff --git a/README.md b/README.md index 1ed025d4e0999452af846d75c2238f21b806b7fc..492dae73a8beadf267b3c30ea301c7aca515113b 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,13 @@ # **TRANSFERS R US** TODO; +ADMIN PAGE LOGOUT BUTTON -TRANSFER VALUE CHECK WITH TROY AND SUFI Refactor UML -Talk about user system with develop team, add to design if wanted. - Talk about following class diagram with develop team. - ## 🚀 **Getting Started** 'Transfers R Us' is a web-based tool for calculating a football player's transfer value, this value is based on how their team has performed in previous league matches. This repository contains all the code neccesary to run the website as well as information about how we have worked together to create said website. Below is some useful information about running the website and references to any further modules you would need. diff --git a/main.py b/main.py index 557f55c856c12158040d5e46f32b0b311f74de91..74a14a1ef6ee7a50c6f4742c1580deb2d8afae49 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,4 @@ -# Version 0.4 of SD Project +# Version 1 of SD Project # Sude Fidan 21068639, William Barnes 21031340, Fiorella Scarpino 21010043, Jack Douet 21025153, Troy Akbulut 21015976 # Imports (pip install flask), (pip install flask-mysql), (pip install pymsql) @@ -15,8 +15,6 @@ from footballHelper import Player, findAverage import json from werkzeug.security import generate_password_hash, check_password_hash -import datetime - # Flask boilerplate app = Flask(__name__) @@ -123,7 +121,7 @@ def request_player(playerName): if not playerData: msg = ("No Player found") return render_template('homepage.html', msg=msg) - #print("Here is playuer Data",playerData) + #print("Here is player Data",playerData) # Results from database is a string so we have to convert playerData['gamesWon'] = int(playerData['gamesWon']) playerData['gamesLost'] = int( @@ -208,7 +206,8 @@ def playerCompare(): isAdmin=session['isAdmin'] except: loggedIn = False - isAdmin = False + isAdmin = False + # Empty array for all players players = [] @@ -268,7 +267,7 @@ def playerComparison(): def login(): try: loggedIn = session['loggedin'] - isAdmin=session['isAdmin'] + isAdmin = session['isAdmin'] except: loggedIn = False isAdmin = False @@ -279,45 +278,46 @@ def login(): msg = '' if request.method == 'POST': - # Creating varibles for easy use later on? + # Creating variables for easy use later on password = request.form['password'] username = (request.form.get('username')) - #Make sure the account actually exsists in the database + + #Make sure the account actually exists in the database print("Username", username) cursor.execute('SELECT * FROM Users WHERE Username = %s', (username)) #Fetch the record and return the result of said record - account = cursor.fetchone() cursor.close() conn.close() + + # if account does not exist, kick back to login screen + if not account: + msg = 'Incorrect username or password' + return render_template('login.html', msg = msg) + + # Check password entered against hashed value result = False - try: - db_hashed = account['Password'] - result = check_password_hash(db_hashed, password)#Will need to fetch the hash database value and compare it to the form value() - except TypeError: - msg = "Username does not exist" - # Will set X equal to the is Admin Collum - try: - x = account["Priviledge"] - except: - pass - if result == True: - if account: - session['loggedin'] = True - session['loggedInID'] = account['Username'] - session['Email'] = account['Email'] - # If X is equal to 1/True its going to set the session isAdmin to true - if x == 1: - session['isAdmin'] = True - else: - session['isAdmin'] = False - return redirect(url_for('profile')) - # If neither results are satisfied it will tell the user either the username or password is incorrect - else: - msg = 'Incorrect username or password' + db_hashed = account['Password'] + result = check_password_hash(db_hashed, password) + + # if password wrong, kick back to login screen + if not result: + msg = "Incorrect password" + return render_template('login.html', msg = msg) + + session['loggedin'] = True + session['loggedInID'] = account['Username'] + session['Email'] = account['Email'] + + # If privilege is equal to 1/True its going to set the session isAdmin to true + if account['Privilege'] == 1: + session['isAdmin'] = True else: - msg ='Incorrect username or password' - return render_template('login.html', msg = msg, loggedIn=loggedIn, isAdmin=isAdmin) + session['isAdmin'] = False + + return redirect(url_for('profile')) + else: + return render_template('login.html', msg = msg) @app.route('/profile', methods=('GET', 'POST')) @@ -331,19 +331,12 @@ def profile(): conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) - #print(session['loggedin']) # Booo-lay-ann Value if user is logged in or not - #print(session['loggedInID']) # Users Username - #print(session['Email']) # Users Email - #print(session['isAdmin']) # Booo-lay-ann Value if user is admin if loggedIn == True: players = [] cursor.execute("SELECT * FROM Favorites WHERE User = %s", session['loggedInID']) totalFav = cursor.fetchall() conn.close() - # Get all players from the session - #for player in session['allPlayerData']: - #players.append(Player(player)) for row in totalFav: for player in session['allPlayerData']: @@ -394,7 +387,7 @@ def register(): totalEmail = cursor.execute("SELECT * FROM Users WHERE Email = %s", email) if (totalUsers == 0): if (totalEmail == 0): - cursor.execute("INSERT INTO `Users` (`Username`, `Password`, `Email`, `Priviledge`) VALUES (%s, %s, %s, '%s');", (usernames, hashed_password, email, 0)) #auto increment + cursor.execute("INSERT INTO `Users` (`Username`, `Password`, `Email`, `Privilege`) VALUES (%s, %s, %s, '%s');", (usernames, hashed_password, email, 0)) #auto increment conn.commit() print("Committed") cursor.close() @@ -411,7 +404,7 @@ def register(): @app.route('/addNewFavorite/<string:x>', methods=['POST']) def addNewFavorite(x): - # Grabs the users favourite and stores it + # Grabs the users favorite and stores it x = json.loads(x) conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) @@ -429,7 +422,7 @@ def addNewFavorite(x): conn.close() else: print("User has already added this as a fave") - return ('Info Received Sucsesfully') + return ('Info Received Successfully') @app.route('/removeFave/<string:x>', methods=['POST']) def removeFave(x): diff --git a/templates/admin.html b/templates/admin.html index 12faf5d463bcd5fba02149c98b32aacbd08ee119..053adc223d2706a0935d6355e2450697c4f50a8c 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -5,7 +5,7 @@ {% block content %} <div class="container"> - <div class="card text-white bg-dark mb-3 mx-auto"> + <div class="text-white bg-dark mb-3 mx-auto"> <div class="row"><h1>Admin View</h1></div> <div class="row"> <h2> Modify or Delete Players</h2></div> <div class="row g-3"> @@ -58,8 +58,8 @@ <td> <input type="hidden" class="submit" id="playerName" name="playerName" placeholder="" value="{{player.name}}"> - <input type="submit" class="submit" id="submit" name="submit" value="Modify"> - <input type="submit" name="submit" id="submit" class="submit" value="Delete"> + <input type="submit" class="btn btn-info" id="submit" name="submit" value="Modify"> + <input type="submit" name="submit" id="submit" class="btn btn-danger" value="Delete"> </form> </tr> {% endfor %} diff --git a/templates/adminFunction.html b/templates/adminFunction.html index b2bcad0fb9ed0ea10862ca35fb7c582fd298fa90..fdb8730eadf52731c474ede68a6ec1d3f3fef386 100644 --- a/templates/adminFunction.html +++ b/templates/adminFunction.html @@ -6,7 +6,7 @@ {% if operation == 'Modify' %} <div class="container"> - <div class="card text-white bg-dark mb-3 mx-auto"> + <div class="text-white bg-dark mb-3 mx-auto"> <div class="row"><h1>Modify Player</h1></div> <form action="modifyPlayer" method="POST"> <div class="row g-3"> @@ -48,7 +48,7 @@ <input type="text" name="salary" id="salary" placeholder={{player.salary}}> </td> <td> - <input type="submit" name="submit" id="submit" class="submit" value="Submit"> + <input type="submit" name="submit" id="submit" class="btn btn-info" value="Submit"> </td> </tbody> </form> @@ -61,13 +61,13 @@ {% if operation == 'Delete' %} <div class="container"> - <div class="card text-white bg-dark mb-3 mx-auto"> + <div class="text-white bg-dark mb-3 mx-auto"> <div class="row"><h1>Delete Player</h1></div> <div class="row"><h2>Are you sure you want to delete {{player.name}}?</h2></div> <div class="row"> <form action="deletePlayer" method="POST"> <input type="hidden" name="playerName" id="playerName" value={{player.name}}> - <input type="submit" class="submit" value="Submit"> + <input type="submit" class="btn btn-danger" value="Submit"> </form> </div> </div> diff --git a/templates/homepage.html b/templates/homepage.html index e15db84142ab11553533cb9e6293c79fbce01466..bf374620e1617cdb1bd98e7d4753c1e5c11fa9b6 100644 --- a/templates/homepage.html +++ b/templates/homepage.html @@ -3,18 +3,26 @@ <!-- {% block title %} Players R Us {% endblock title %} --> {% block content %} -<div class="content"> +<br> +<br> +<br> +<br> +<br> +<br> + + +<div class="content container pt-5"> <div class="row"></div> <div class="row"> - <div class="col-12"></div> + <div class="col-12 card-header"></div> <h1>Players R Us</h1> <h2>Football Searcher</h2> - <div> + <div class="card-body"> <form method="POST"> <select class="form-control" id="playerName" name="playerName"> {% for player in players %} diff --git a/templates/login.html b/templates/login.html index cfb9c8623ed700f5c9f2fb98d29db555829d9df2..7bab051a7b09ce1048f1d6949e04bbf42fdaa4b3 100644 --- a/templates/login.html +++ b/templates/login.html @@ -3,7 +3,7 @@ <div class="centreContent"> <div class="container pt-5 "> - <div class="card text-white bg-dark mb-3" style="max-width: 26rem;"> + <div class="text-white bg-dark mb-3" style="max-width: 26rem;"> <div class="card-header"> <h1>Login</h1> </div> diff --git a/templates/loginSuccess.html b/templates/loginSuccess.html index 07984085ea17a0fbe542ed2070bc88e080d2bdf5..4519aafa2a16cc0472c785cf5c3dfa5d22c4a705 100644 --- a/templates/loginSuccess.html +++ b/templates/loginSuccess.html @@ -1,7 +1,7 @@ {% include "base.html" %} {% block content %} -<h1>Player Favourites</h1> +<h1>Favorite Players</h1> <table class="table table-striped table-dark text-center"> <thead class="thead"> <tr> diff --git a/templates/playerCompare.html b/templates/playerCompare.html index 5ca791bb906026b711e00832573692d84aaa87bc..bd162f41b3616cd97fb8d002fd466e257126f44e 100644 --- a/templates/playerCompare.html +++ b/templates/playerCompare.html @@ -5,7 +5,7 @@ <div class="centreContent"> <div class="container pt-5"> - <div class="card text-white bg-dark mb-3" style="max-width: 26rem;"> + <div class="text-white bg-dark mb-3" style="max-width: 26rem;"> <div class="card-header"><h1>Choose Two Players to Compare</h1></div> <div class="card-body">