Skip to content
Snippets Groups Projects
Commit 6883312d authored by Nguyễn Minh's avatar Nguyễn Minh
Browse files

Add new code for frontend

parent 91302efb
No related branches found
No related tags found
No related merge requests found
import ttkbootstrap as tb
from ttkbootstrap.constants import *
from tkinter import messagebox
# Function to handle login
def login():
username = entry_username.get()
password = entry_password.get()
if username == "admin" and password == "password": # Dummy credentials
messagebox.showinfo("Login Successful", "Welcome, Admin!")
else:
messagebox.showerror("Login Failed", "Invalid username or password.")
# Create main window
root = tb.Window(themename="superhero") # Try different themes like "darkly", "minty", etc.
root.title("Login Form")
root.geometry("900x800")
# Title Label
label_title = tb.Label(root, text="Login", font=("Helvetica", 18, "bold"))
label_title.pack(pady=10)
# Username Entry
tb.Label(root, text="Username:").pack(pady=5)
entry_username = tb.Entry(root, bootstyle="info")
entry_username.pack(pady=5)
# Password Entry
tb.Label(root, text="Password:").pack(pady=5)
entry_password = tb.Entry(root, bootstyle="info", show="*") # Masked input
entry_password.pack(pady=5)
# Login Button
btn_login = tb.Button(root, text="Login", bootstyle="primary", command=login)
btn_login.pack(pady=15)
# Run the GUI
root.mainloop()
import ttkbootstrap as tb
from ttkbootstrap.constants import *
from tkinter import messagebox
# Function to handle registration
def register():
username = entry_username.get()
email = entry_email.get()
phone_number = entry_phone.get()
password = entry_password.get()
confirm_password = entry_confirm_password.get()
if not username or not email or not phone_number or not password or not confirm_password:
messagebox.showwarning("Input Error", "All fields are required!")
return
if password != confirm_password:
messagebox.showerror("Password Error", "Passwords do not match!")
return
# Dummy registration success message (Replace with DB logic)
messagebox.showinfo("Registration Successful", f"Welcome, {username}!")
# Create main window
root = tb.Window(themename="superhero") # Change to "darkly", "superhero", etc.
root.title("Register")
root.geometry("900x800")
# Title Label
label_title = tb.Label(root, text="Register", font=("Helvetica", 18, "bold"))
label_title.pack(pady=10)
# Username Entry
tb.Label(root, text="Username:").pack(pady=5)
entry_username = tb.Entry(root, bootstyle="info")
entry_username.pack(pady=5)
# Email Entry
tb.Label(root, text="Email:").pack(pady=5)
entry_email = tb.Entry(root, bootstyle="info")
entry_email.pack(pady=5)
# Phone Entry
tb.Label(root, text="Phone Number:").pack(pady=5)
entry_phone = tb.Entry(root, bootstyle="info")
entry_phone.pack(pady=5)
# Password Entry
tb.Label(root, text="Password:").pack(pady=5)
entry_password = tb.Entry(root, bootstyle="info", show="*")
entry_password.pack(pady=5)
# Confirm Password Entry
tb.Label(root, text="Confirm Password:").pack(pady=5)
entry_confirm_password = tb.Entry(root, bootstyle="info", show="*")
entry_confirm_password.pack(pady=5)
# Register Button
btn_register = tb.Button(root, text="Register", bootstyle="success", command=register)
btn_register.pack(pady=15)
# Run the GUI
root.mainloop()
import ttkbootstrap as tb
from ttkbootstrap.constants import *
from tkinter import messagebox
import requests
# Backend API URL
API_URL = "http://127.0.0.1:8000"
# Function to handle registration
def register():
username = entry_username.get()
email = entry_email.get()
phone_number = entry_phone.get()
password = entry_password.get()
confirm_password = entry_confirm_password.get()
if not username or not email or not password or not confirm_password:
messagebox.showwarning("Input Error", "All fields are required!")
return
if password != confirm_password:
messagebox.showerror("Password Error", "Passwords do not match!")
return
# Send registration data to backend
response = requests.post(f"{API_URL}/auth/signup", json={
"username": username,
"email": email,
"phone_number": phone_number,
"password": password
})
try:
response_data = response.json()
if response.status_code == 200:
messagebox.showinfo("Registration Successful", f"Welcome, {username}!")
else:
messagebox.showerror("Registration Failed", response_data.get("detail", "Unknown error"))
except requests.exceptions.JSONDecodeError:
messagebox.showerror("Registration Failed", f"Server returned non-JSON response: {response.text}")
# Function to handle login
def login():
email = entry_email.get()
password = entry_password.get()
# Send login data to backend
response = requests.post(f"{API_URL}/auth/login", json={
"email": email,
"password": password
})
if response.status_code == 200:
messagebox.showinfo("Login Successful", "Welcome!")
else:
messagebox.showerror("Login Failed", response.json().get("detail", "Invalid credentials"))
# Create main window
root = tb.Window(themename="superhero") # Change to "darkly", "superhero", etc.
root.title("Shopping App")
root.geometry("900x800")
# Title Label
label_title = tb.Label(root, text="Shopping App", font=("Helvetica", 18, "bold"))
label_title.pack(pady=10)
# Username Entry
tb.Label(root, text="Username:").pack(pady=5)
entry_username = tb.Entry(root, bootstyle="info")
entry_username.pack(pady=5)
# Email Entry
tb.Label(root, text="Email:").pack(pady=5)
entry_email = tb.Entry(root, bootstyle="info")
entry_email.pack(pady=5)
# Phone Entry
tb.Label(root, text="Phone Number:").pack(pady=5)
entry_phone = tb.Entry(root, bootstyle="info")
entry_phone.pack(pady=5)
# Password Entry
tb.Label(root, text="Password:").pack(pady=5)
entry_password = tb.Entry(root, bootstyle="info", show="*")
entry_password.pack(pady=5)
# Confirm Password Entry
tb.Label(root, text="Confirm Password:").pack(pady=5)
entry_confirm_password = tb.Entry(root, bootstyle="info", show="*")
entry_confirm_password.pack(pady=5)
# Register Button
btn_register = tb.Button(root, text="Register", bootstyle="success", command=register)
btn_register.pack(pady=15)
# Login Button
btn_login = tb.Button(root, text="Login", bootstyle="primary", command=login)
btn_login.pack(pady=15)
# Run the GUI
root.mainloop()
\ No newline at end of file
......@@ -3,6 +3,7 @@ anyio==4.8.0
bcrypt==3.2.2
certifi==2025.1.31
cffi==1.17.1
charset-normalizer==3.4.1
click==8.1.8
colorama==0.4.6
dnspython==2.7.0
......@@ -23,6 +24,7 @@ mdurl==0.1.2
mysql-connector-python==9.2.0
orjson==3.10.15
passlib==1.7.4
pillow==11.1.0
pycparser==2.22
pydantic==2.10.6
pydantic-extra-types==2.10.2
......@@ -33,6 +35,7 @@ PyMySQL==1.1.1
python-dotenv==1.0.1
python-multipart==0.0.20
PyYAML==6.0.2
requests==2.32.3
rich==13.9.4
rich-toolkit==0.13.2
shellingham==1.5.4
......@@ -40,9 +43,12 @@ sniffio==1.3.1
SQLAlchemy==2.0.38
sqlmodel==0.0.23
starlette==0.46.0
ttkbootstrap==1.10.1
typer==0.15.2
typing_extensions==4.12.2
ujson==5.10.0
urllib3==2.3.0
uvicorn==0.34.0
uvloop==0.21.0
watchfiles==1.0.4
websockets==15.0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment