From 07e46c904a711b2c83b4c96bec625a5c1de9bb0a Mon Sep 17 00:00:00 2001 From: Vratika Date: Wed, 6 Nov 2024 18:21:56 +0530 Subject: [PATCH] updeted code --- Final_Merged.py | 15 ++-- installer.py | 181 +++++++++++------------------------------------- 2 files changed, 49 insertions(+), 147 deletions(-) diff --git a/Final_Merged.py b/Final_Merged.py index 7ecdcbf..106600f 100644 --- a/Final_Merged.py +++ b/Final_Merged.py @@ -1783,29 +1783,28 @@ def verify_otp(otp, email, window): # 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 + device_info_url = 'http://127.0.0.1:8000/update-device/' # API endpoint + mac_address = get_mac_address() # Function to get MAC address + unique_id = get_unique_id() # Function to 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 + # Make the PUT request to send the device info + response = requests.put(device_info_url, json={ + "user_id": user_profile_id, # Use 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') - 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` diff --git a/installer.py b/installer.py index eb31cb8..e55241c 100644 --- a/installer.py +++ b/installer.py @@ -4,6 +4,7 @@ from tkinter import messagebox import re import webbrowser import requests # Make sure to install this library if you haven't already +import os @@ -41,6 +42,7 @@ def submit_email(): 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) show_otp_verification_window(email) else: messagebox.showwarning("Error", "Failed to send OTP.") @@ -82,6 +84,7 @@ def verify_otp(otp, email, window): # Extract user_profile_id from the response response_data = response.json() user_profile_id = response_data.get("user_profile_id") + print(user_profile_id) messagebox.showinfo("Success", "OTP verified successfully!") @@ -94,32 +97,61 @@ def verify_otp(otp, email, window): messagebox.showwarning("Error", "Invalid or expired OTP.") except Exception as e: messagebox.showerror("Error", f"An error occurred: {str(e)}") - +def print_device_id(): + device_id = os.environ.get('DEVICE_ID') # Retrieve the device ID from the environment variable + if device_id: + print("Device ID from OS environment:", device_id) + messagebox.showinfo("Device ID", f"Device ID: {device_id}") # Show in a message box + else: + print("Device ID not found in OS environment.") # 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)}") 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 + device_info_url = 'http://127.0.0.1:8000/update-device/' # API endpoint + mac_address = get_mac_address() # Function to get MAC address + unique_id = get_unique_id() # Function to 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 + # Make the PUT request to send the device info + response = requests.put(device_info_url, json={ + "user_id": user_profile_id, # Use 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)}") + + # Create the main window root = tk.Tk() root.title("Device Info Checker") @@ -138,133 +170,4 @@ submit_button = tk.Button(root, text="Submit", command=submit_email) # Run the GUI loop root.mainloop() #===========================================================================this is working ============================= -# import webview -# import tkinter as tk -# from tkinter import messagebox -# import requests - -# # 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 '@' in email: # Simple email validation -# messagebox.showinfo("Success", f"Email submitted: {email}") -# api_url = 'http://127.0.0.1:8000/send-otp/' # Replace with your actual API URL - -# try: -# response = requests.post(api_url, data={"email": email}) -# if response.status_code == 200: -# messagebox.showinfo("Success", "OTP sent successfully! Please verify OTP on the web.") -# # Show OTP verification window using PyWebView -# 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 using PyWebView -# def show_otp_verification_window(email): -# # HTML content to show the OTP input window -# html_content = f""" -# -# -# -# -# -# OTP Verification -# -# -# -#

Verify OTP

-#

Please enter the OTP sent to {email}

-# -# -#

- -# -# -# -# """ - -# # Create a PyWebView window -# webview.create_window('OTP Verification', html=html_content, js_api=JSApi()) -# webview.start() - -# # Define a JavaScript API class that will handle Python calls from the web page -# class JSApi: -# def verify_otp(self, otp, email): -# # Verify OTP with the backend -# api_url = 'http://127.0.0.1:8000/verify-second-otp/' -# try: -# response = requests.post(api_url, data={"second_otp": otp, "email": email}) -# if response.status_code == 200: -# return {"message": "OTP verified successfully!"} -# else: -# return {"message": "Invalid or expired OTP."} -# except Exception as e: -# return {"message": f"An error occurred: {str(e)}"} - -# # Create the main window -# root = tk.Tk() -# root.title("Device Info Checker") -# root.geometry("300x300") - -# # Create and pack the button to check the device -# check_button = tk.Button(root, text="Check Device", command=check_device) -# check_button.pack(pady=20) - -# # Label and entry for email input (hidden initially) -# email_label = tk.Label(root, text="Enter your email:") -# email_entry = tk.Entry(root) -# submit_button = tk.Button(root, text="Submit", command=submit_email) - -# # Run the GUI loop -# root.mainloop() +# \ No newline at end of file