Beginning adding OTP verification to client shange screen
This commit is contained in:
@@ -3,12 +3,13 @@ import customtkinter
|
||||
import json
|
||||
import os
|
||||
from config import CONFIG
|
||||
from connection import logout_client, get_client, update_client, get_accounts, format_balance
|
||||
from connection import logout_client, get_client, update_client, get_accounts, format_balance, generate_otp
|
||||
|
||||
# Global variables
|
||||
email_entry = None
|
||||
phone_entry = None
|
||||
address_entry = None
|
||||
otp_entry = None
|
||||
frame = None
|
||||
|
||||
#################
|
||||
@@ -66,10 +67,11 @@ def display_client_info():
|
||||
|
||||
def edit_details():
|
||||
"""Opens a new window for editing client details."""
|
||||
global edit_window, email_entry, phone_entry, address_entry
|
||||
global edit_window, email_entry, phone_entry, address_entry, otp_entry
|
||||
edit_window = customtkinter.CTkToplevel(root)
|
||||
edit_window.title("Edit Details")
|
||||
edit_window.geometry("300x200")
|
||||
edit_window.geometry("300x300")
|
||||
edit_window.iconbitmap("application/luxbank.ico")
|
||||
edit_window.attributes('-topmost', True)
|
||||
|
||||
email_label = customtkinter.CTkLabel(edit_window, text="Email: ")
|
||||
@@ -87,31 +89,38 @@ def edit_details():
|
||||
address_label.pack()
|
||||
address_entry.pack()
|
||||
|
||||
save_button = customtkinter.CTkButton(edit_window, text="Save", command=save_details)
|
||||
# Add MFA verify button and text box
|
||||
mfa_button = customtkinter.CTkButton(edit_window, text="Get OTP Code", command=generate_otp)
|
||||
mfa_button.pack()
|
||||
|
||||
mfa_label = customtkinter.CTkLabel(edit_window, text="OTP Code: ")
|
||||
otp_entry = customtkinter.CTkEntry(edit_window)
|
||||
mfa_label.pack()
|
||||
otp_entry.pack()
|
||||
|
||||
save_button = customtkinter.CTkButton(edit_window, text="Verify MFA and Save", command=save_details)
|
||||
save_button.pack()
|
||||
edit_window.lift()
|
||||
|
||||
def save_details():
|
||||
"""Saves the updated client details."""
|
||||
global edit_window, email_entry, phone_entry, address_entry
|
||||
global edit_window, otp_entry, email_entry, phone_entry, address_entry
|
||||
new_email = email_entry.get() if email_entry.get() != '' else None
|
||||
new_phone = phone_entry.get() if phone_entry.get() != '' else None
|
||||
new_address = address_entry.get() if address_entry.get() != '' else None
|
||||
try:
|
||||
with open('application\\session_data.json', 'r') as f:
|
||||
session_data = json.load(f)
|
||||
client_id = session_data['client_id']
|
||||
if not messagebox.askyesno("Confirmation", "Are you sure you want to update the details?"):
|
||||
return
|
||||
result = update_client(client_id, new_email, new_phone, new_address)
|
||||
if result['success']:
|
||||
display_client_info()
|
||||
else:
|
||||
messagebox.showerror("Update Failed", result.get('message', 'Unknown error'))
|
||||
edit_window.destroy()
|
||||
except Exception as e:
|
||||
messagebox.showerror("Error", f"Could not update details: {e}")
|
||||
|
||||
otp_code = otp_entry.get()
|
||||
with open('application\\session_data.json', 'r') as f:
|
||||
session_data = json.load(f)
|
||||
client_id = session_data['client_id']
|
||||
if not messagebox.askyesno("Confirmation", "Are you sure you want to update the details?"):
|
||||
return
|
||||
result = update_client(client_id, otp_code, new_email, new_phone, new_address)
|
||||
if result['success']:
|
||||
display_client_info()
|
||||
else:
|
||||
messagebox.showerror("Update Failed", result.get('message', 'Unknown error'))
|
||||
edit_window.destroy()
|
||||
|
||||
def populate_table():
|
||||
"""Populates the accounts table with client accounts."""
|
||||
try:
|
||||
@@ -160,9 +169,14 @@ welcome_label.pack(pady=20)
|
||||
|
||||
display_client_info()
|
||||
|
||||
# Create a logout button
|
||||
logout_button = customtkinter.CTkButton(root, text="Logout", command=logout)
|
||||
logout_button.pack(pady=15)
|
||||
|
||||
# Create the MFA button
|
||||
mfa_button = customtkinter.CTkButton(root, text="MFA", command=generate_otp)
|
||||
mfa_button.pack(pady=15, side='left')
|
||||
|
||||
# Create a frame for the table
|
||||
table_frame = ttk.Frame(root)
|
||||
table_frame.pack(side='right', fill='both', expand=True)
|
||||
|
||||
Reference in New Issue
Block a user