updeted code
This commit is contained in:
parent
ffe2f85718
commit
07e46c904a
@ -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`
|
||||
|
||||
181
installer.py
181
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"""
|
||||
# <!DOCTYPE html>
|
||||
# <html lang="en">
|
||||
# <head>
|
||||
# <meta charset="UTF-8">
|
||||
# <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
# <title>OTP Verification</title>
|
||||
# <style>
|
||||
# body {{
|
||||
# font-family: Arial, sans-serif;
|
||||
# text-align: center;
|
||||
# padding-top: 50px;
|
||||
# }}
|
||||
# input {{
|
||||
# padding: 10px;
|
||||
# width: 200px;
|
||||
# margin-top: 20px;
|
||||
# font-size: 16px;
|
||||
# }}
|
||||
# button {{
|
||||
# padding: 10px 20px;
|
||||
# font-size: 16px;
|
||||
# margin-top: 20px;
|
||||
# }}
|
||||
# </style>
|
||||
# </head>
|
||||
# <body>
|
||||
# <h1>Verify OTP</h1>
|
||||
# <p>Please enter the OTP sent to {email}</p>
|
||||
# <input type="text" id="otp" placeholder="Enter OTP">
|
||||
# <button onclick="verifyOTP()">Verify OTP</button>
|
||||
# <p id="result"></p>
|
||||
|
||||
# <script>
|
||||
# function verifyOTP() {{
|
||||
# var otp = document.getElementById('otp').value;
|
||||
# if (otp === '') {{
|
||||
# document.getElementById('result').innerText = 'Please enter OTP.';
|
||||
# return;
|
||||
# }}
|
||||
# // Call Python function to verify OTP
|
||||
# window.pywebview.api.verify_otp(otp, '{email}').then(function(response) {{
|
||||
# document.getElementById('result').innerText = response.message;
|
||||
# }}).catch(function(error) {{
|
||||
# document.getElementById('result').innerText = 'Error: ' + error;
|
||||
# }});
|
||||
# }}
|
||||
# </script>
|
||||
# </body>
|
||||
# </html>
|
||||
# """
|
||||
|
||||
# # 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()
|
||||
#
|
||||
Loading…
Reference in New Issue
Block a user