Added login app page added, dashboard app page added with logout

This commit is contained in:
Lucas Mathews
2024-05-26 13:14:46 +02:00
parent c1e0674087
commit 241ab8529b
6 changed files with 127 additions and 12 deletions

1
api.py
View File

@@ -8,7 +8,6 @@
import connexion # Imports connexion module
from config import CONFIG # Imports the configuration file
from manager import * # Imports the Manager file that contains the functions for the API
from flask import Flask, session, jsonify, request # Imports the Flask module
from flask_session import Session # Imports the session module
#################

View File

@@ -1,3 +1,10 @@
[server]
ip=0.0.0.0
port=81
port=81
url=http://127.0.0.1:81
[preferences]
dark_theme=system
# Modes: system, light, dark
theme=dark-blue
# Themes: blue, dark-blue, green

View File

@@ -2,7 +2,45 @@
# Banking System App Connection file
import requests
from requests.models import PreparedRequest, Response
from config import CONFIG
import json
def get_connection():
return requests.get(CONFIG["api"]["url"]) # Returns the connection to the API
def authenticate_client(client_id, client_password):
try:
# Send a POST request to the /Client/Login endpoint with the client_id and password
response = requests.post(CONFIG["server"]["url"] + "/Client/Login", params={'client_id': client_id, 'password': client_password})
# Return the response from the API
return response
except requests.exceptions.RequestException as e:
# If a RequestException is raised, print the exception message
print(f"RequestException: {e}")
# Create a new Response object with a status code of 500 and the error message in the JSON body
response = Response()
response.status_code = 500
response._content = b'{"success": false, "message": "Could not connect to the server. Please try again later."}'
return response
def logout_client():
try:
# Load the session cookie from the file
with open('application\\session_cookie.json', 'r') as f:
cookies = json.load(f)
# Send a POST request to the /Client/Logout endpoint
response = requests.post(CONFIG["server"]["url"] + "/Client/Logout", cookies=cookies)
# Return the response from the API
return response
except requests.exceptions.RequestException as e:
# If a RequestException is raised, print the exception message
print(f"RequestException: {e}")
# Create a new Response object with a status code of 500 and the error message in the JSON body
response = Response()
response.status_code = 500
response._content = b'{"success": false, "message": "Could not connect to the server. Please try again later."}'
return response

37
application/dashboard.py Normal file
View File

@@ -0,0 +1,37 @@
# Lucas Mathews - Fontys Student ID: 5023572
# Banking System Dashboard Page
import tkinter as tk
from tkinter import messagebox
import customtkinter
from connection import logout_client
def logout():
response = logout_client() # Call the logout_client function
json_response = response.json() # Convert the response content to JSON
if json_response['success'] == True:
messagebox.showinfo("Logout", "You have been logged out.")
root.destroy()
else:
messagebox.showerror("Logout failed", json_response['message'])
# Create the main window
root = customtkinter.CTk()
# Set the window title, icon, and size
root.title("Luxbank Dashboard")
root.iconbitmap("application/luxbank.ico")
root.geometry("800x600")
# Create a label with a welcome message
welcome_label = customtkinter.CTkLabel(root, text="Welcome to the Luxbank Dashboard!", font=("Helvetica", 24))
welcome_label.pack(pady=20)
# Create a Logout button
logout_button = customtkinter.CTkButton(root, text="Logout", command=logout)
logout_button.pack(pady=15)
# Start the main loop
root.mainloop()

View File

@@ -1,12 +1,41 @@
# Lucas Mathews - Fontys Student ID: 5023572
# Banking System App Login Page
from tkinter import *
from tkinter import messagebox
import customtkinter
import os
import json
from connection import *
#################
### Functions ###
#################
def login():
client_id = entry_username.get()
client_password = entry_password.get()
try:
response = authenticate_client(client_id, client_password) # Authenticate the client
json_response = response.json() # Convert the response content to JSON
if json_response["success"] == True: # If the authentication is successful, open the dashboard
# Save the session cookie to a file
with open('application\\session_cookie.json', 'w') as f:
json.dump(response.cookies.get_dict(), f)
root.destroy()
os.system("python application\\dashboard.py")
else:
messagebox.showerror("Login failed", json_response["message"]) # If the authentication fails, show an error message
except requests.exceptions.RequestException as e:
# If a RequestException is raised, show an error message that includes the exception message
messagebox.showerror("Login failed", "Could not connect to the server. Please try again later. Error: " + str(e))
customtkinter.set_appearance_mode("System") # Modes: system (default), light, dark
customtkinter.set_default_color_theme("dark-blue") # Themes: blue (default), dark-blue, green
##############
### Layout ###
##############
customtkinter.set_appearance_mode((CONFIG["preferences"]["dark_theme"])) # Modes: system (default), light, dark
customtkinter.set_default_color_theme((CONFIG["preferences"]["theme"])) # Themes: blue (default), dark-blue, green
root = customtkinter.CTk()
@@ -17,12 +46,16 @@ root.geometry("400x300")
label = customtkinter.CTkLabel(root, text="Luxbank", font=("Helvetica", 24))
label.pack(pady=20)
username = customtkinter.CTkEntry(root, placeholder_text="Client ID")
username.pack(pady=20)
password = customtkinter.CTkEntry(root, placeholder_text="Password", show="*")
password.pack(pady=10)
entry_username = customtkinter.CTkEntry(root, placeholder_text="Client ID")
entry_username.pack(pady=20)
entry_password = customtkinter.CTkEntry(root, placeholder_text="Password", show="*")
entry_password.pack(pady=10)
login_button= customtkinter.CTkButton(root, text="Login", command=lambda: print("Login"))
login_button= customtkinter.CTkButton(root, text="Login", command=login)
login_button.pack(pady=15)
###########
### Run ###
###########
root.mainloop()

View File

@@ -0,0 +1 @@
{"session": "rZS5tQOS4nXGJu-WXEg6_Ls5q8njy3GNiZ3s8N3YHEA"}