From 35973a0ecfa975c9d6af6952a8ec68c39ebfb981 Mon Sep 17 00:00:00 2001 From: Vratika Date: Mon, 28 Oct 2024 19:46:26 +0530 Subject: [PATCH] update device check --- Final_Merged.py | 162 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 145 insertions(+), 17 deletions(-) diff --git a/Final_Merged.py b/Final_Merged.py index 3b05f67..0dcd7fd 100644 --- a/Final_Merged.py +++ b/Final_Merged.py @@ -27,7 +27,10 @@ import joblib from sklearn.preprocessing import StandardScaler import sklearn.ensemble._forest from threading import Thread, Event - +from tkinter import messagebox +import re +import webbrowser +import requests @@ -1616,26 +1619,137 @@ def is_auth(): return False -def device_check(): +# def device_check(): - if not is_auth(): +# if not is_auth(): +# try: +# subprocess.run(['python3', 'installer.py'], check=True) +# device_check_completed = True # Set the flag once device check is complete +# return True +# except subprocess.CalledProcessError as e: +# print(f"Error running device check script: {e}") +# messagebox.showerror("Error", "Device check failed. The wizard will not start.") +# return False +# return True +# Function to get the device MAC address +def get_mac_address(): + return '13:bb:81:47:b2:e6' + +# Function to generate a 16-digit unique ID +def get_unique_id(): + return 'cf4650bb871111ef' + +# Function to handle the "Check Device" button +def check_device(): + response = messagebox.askyesno("Check Device", "Do you want to check your device?") + if response: # User clicked "Yes" + email_label.pack() + email_entry.pack() + submit_button.pack() + +# Function to validate and submit the entered email and call the send-otp API +def submit_email(): + email = email_entry.get() + if re.match(r"[^@]+@[^@]+\.[^@]+", email): # Simple email validation + messagebox.showinfo("Success", f"Email submitted: {email}") + # with open('authenticated', 'w') as flag: + # flag.write('Authenticated!') + + # Replace 'your_api_url' with the actual URL of your API + api_url = 'http://127.0.0.1:8000/send-otp/' try: - subprocess.run(['python3', 'installer.py'], check=True) - device_check_completed = True # Set the flag once device check is complete - return True - except subprocess.CalledProcessError as e: - print(f"Error running device check script: {e}") - messagebox.showerror("Error", "Device check failed. The wizard will not start.") - return False - return True + response = requests.post(api_url, data={"email": email}) # Adjust the payload as needed + if response.status_code == 200: + messagebox.showinfo("Success", "OTP sent successfully! Please verify OTP on the web.") + webbrowser.open('http://127.0.0.1:8000/signup') + + # Show OTP verification window after successful OTP request + root.after(600000, show_otp_verification_window, email) + else: + messagebox.showwarning("Error", "Failed to send OTP.") + except Exception as e: + messagebox.showerror("Error", f"An error occurred: {str(e)}") + else: + messagebox.showwarning("Error", "Invalid email entered") + +# Function to show OTP verification window +def show_otp_verification_window(email): + otp_window = tk.Toplevel(root) + otp_window.title("Verify OTP") + otp_window.geometry("300x200") + + otp_label = tk.Label(otp_window, text="Enter the OTP:") + otp_label.pack(pady=10) + + # Entry field for OTP + otp_entry = tk.Entry(otp_window) + otp_entry.pack(pady=10) + + # Button to verify OTP + verify_button = tk.Button(otp_window, text="Verify OTP", command=lambda: verify_otp(otp_entry.get(), email, otp_window)) + verify_button.pack(pady=10) + + # Focus on the OTP entry field + otp_entry.focus_set() + +def verify_otp(otp, email, window): + api_url = 'http://127.0.0.1:8000/verify-second-otp/' + try: + # Include the second_otp and email in the payload + response = requests.post(api_url, data={ + "second_otp": otp, + + }) + + if response.status_code == 200: + # Extract user_profile_id from the response + response_data = response.json() + user_profile_id = response_data.get("user_profile_id") + + messagebox.showinfo("Success", "OTP verified successfully!") + + window.destroy() # Close OTP window on successful verification + + # After OTP is verified, send device info with user_profile_id + send_device_info(user_profile_id) + + else: + messagebox.showwarning("Error", "Invalid or expired OTP.") + except Exception as e: + messagebox.showerror("Error", f"An error occurred: {str(e)}") + +# Function to send the device information after OTP is verified +def send_device_info(user_profile_id): + device_info_url = 'http://127.0.0.1:8000/send-device-info/' # Adjust to the correct API endpoint + mac_address = get_mac_address() # Get MAC address + unique_id = get_unique_id() # Get unique ID + + try: + # Make the POST request to send the device info + response = requests.post(device_info_url, json={ + "user_profile_id": user_profile_id, # Use the user_profile_id from OTP verification + "mac_address": mac_address, + "unique_id": unique_id + }) + + if response.status_code == 200: + + messagebox.showinfo("Success", "Device info sent successfully!") + webbrowser.open('http://127.0.0.1:8000/home') + root.destroy() + else: + messagebox.showwarning("Error", f"Failed to send device info. {response.json().get('error')}") + + except Exception as e: + messagebox.showerror("Error", f"An error occurred while sending device info: {str(e)}") import tkinter as tk from tkinter import ttk # Requires `pip install ttkthemes` def create_wizard_window(): - global root + global root,email_label, email_entry, submit_button root = tk.Tk() root.title("File Conversion and Disassembly Wizard") root.geometry("700x450") @@ -1688,6 +1802,16 @@ def create_wizard_window(): label1.pack(pady=40) desc_label1 = tk.Label(frame1, text="This wizard will guide you through the steps.", bg="#ffffff", font=("Arial", 12)) desc_label1.pack(pady=10) + + check_button = tk.Button(frame1, text="Check Device", command=check_device) + check_button.pack(pady=20) + + # Label and entry for email input (initially hidden) + email_label = tk.Label(frame1, text="Enter your email:") + email_entry = tk.Entry(frame1) + submit_button = tk.Button(frame1, text="Submit", command=submit_email) + + next_button1 = ttk.Button(frame1, text="Next ➡️", command=lambda: [update_progress(2), show_frame(frame2)]) next_button1.pack(pady=20) @@ -1800,15 +1924,19 @@ def create_wizard_window(): def on_closing(): root.quit() -if device_check(): + # If device check is successful, initialize the Tkinter window create_wizard_window() -else: - # If the device check fails, show an error message and exit - print("Device check failed. Exiting program.") - messagebox.showerror("Error", "Device check failed. The wizard will not start.") +# # # Main logic to run the device check before starting the wizard +if __name__ == "__main__": + + # If device check is successful, initialize the Tkinter window + + create_wizard_window() + root.mainloop() +