register_profile_views #6
356
client/app.py
356
client/app.py
@ -1,128 +1,228 @@
|
|||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
import requests
|
|
||||||
|
import requests
|
||||||
FONT= ("Verdana", 12)
|
|
||||||
FONT_LARGE= ("Verdana", 20)
|
FONT = ("Verdana", 12)
|
||||||
URL = "http://localhost:8000/api/authenticate"
|
FONT_B = ("Verdana", 12, 'bold')
|
||||||
TOKEN = ""
|
FONT_LARGE = ("Verdana", 20)
|
||||||
|
URL = "http://localhost:8000/api/authenticate"
|
||||||
class SmartPicasso(tk.Tk):
|
URL_REGISTER = "http://localhost:8000/api/register"
|
||||||
|
URL_PROFILE = "http://localhost:8000/api/profile"
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
|
|
||||||
tk.Tk.__init__(self, *args, **kwargs)
|
class SmartPicasso(tk.Tk):
|
||||||
container = tk.Frame(self)
|
|
||||||
self.title('SmartPicasso')
|
def __init__(self, *args, **kwargs):
|
||||||
self.geometry('610x460')
|
tk.Tk.__init__(self, *args, **kwargs)
|
||||||
|
container = tk.Frame(self)
|
||||||
container.pack(side="top", fill="both", expand = True)
|
self.title('SmartPicasso')
|
||||||
|
self.geometry('610x460')
|
||||||
container.grid_rowconfigure(0, weight=1)
|
|
||||||
container.grid_columnconfigure(0, weight=1)
|
container.pack(side="top", fill="both", expand=True)
|
||||||
|
|
||||||
self.frames = {}
|
container.grid_rowconfigure(0, weight=1)
|
||||||
|
container.grid_columnconfigure(0, weight=1)
|
||||||
for F in (LoginPage, MainView, RegisterView):
|
|
||||||
|
self.frames = {}
|
||||||
frame = F(container, self)
|
|
||||||
|
for F in (LoginView, MainView, RegisterView):
|
||||||
self.frames[F] = frame
|
frame = F(container, self)
|
||||||
|
|
||||||
frame.grid(row=0, column=0, sticky="nsew")
|
self.frames[F] = frame
|
||||||
|
|
||||||
self.show_frame(LoginPage)
|
frame.grid(row=0, column=0, sticky="nsew")
|
||||||
|
|
||||||
def show_frame(self, cont):
|
self.show_frame(LoginView)
|
||||||
|
|
||||||
frame = self.frames[cont]
|
def show_frame(self, view, token=None):
|
||||||
frame.tkraise()
|
frame = self.frames[view]
|
||||||
|
frame.tkraise()
|
||||||
|
|
||||||
class LoginPage(tk.Frame):
|
if token:
|
||||||
|
frame.token = token
|
||||||
def __init__(self, parent, controller):
|
|
||||||
tk.Frame.__init__(self,parent)
|
|
||||||
label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE)
|
class LoginView(tk.Frame):
|
||||||
label.pack(pady=10,padx=10)
|
|
||||||
|
def __init__(self, parent, controller):
|
||||||
label1 = tk.Label(self, text='Login:', font=FONT)
|
tk.Frame.__init__(self, parent)
|
||||||
label1.pack()
|
label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE)
|
||||||
|
label.pack(pady=10, padx=10)
|
||||||
input1 = tk.Entry(self)
|
|
||||||
input1.pack()
|
label1 = tk.Label(self, text='Login:', font=FONT)
|
||||||
|
label1.pack()
|
||||||
label2 = tk.Label(self, text='Password:', font=FONT)
|
|
||||||
label2.pack()
|
input1 = tk.Entry(self)
|
||||||
|
input1.pack()
|
||||||
input2 = tk.Entry(self)
|
|
||||||
input2.pack()
|
label2 = tk.Label(self, text='Password:', font=FONT)
|
||||||
|
label2.pack()
|
||||||
button = tk.Button(self, text="Login", font=FONT, command=lambda: self.login(controller, input1.get(), input2.get()))
|
|
||||||
button.pack()
|
input2 = tk.Entry(self, show="*")
|
||||||
|
input2.pack()
|
||||||
button2 = tk.Button(self, text="Register", font=FONT, command=lambda: controller.show_frame(RegisterView))
|
|
||||||
button2.pack()
|
button = tk.Button(self, text="Login", font=FONT,
|
||||||
|
command=lambda: self.login(controller, input1.get(), input2.get()))
|
||||||
def login(self, controller, login, passw,):
|
button.pack()
|
||||||
print(login)
|
|
||||||
print(passw)
|
button2 = tk.Button(self, text="Register", font=FONT, command=lambda: controller.show_frame(RegisterView))
|
||||||
data = {
|
button2.pack()
|
||||||
"email": str(login),
|
|
||||||
"password": str(passw)
|
def login(self, controller, login, password):
|
||||||
}
|
print(login)
|
||||||
resp = requests.post(URL, json=data)
|
print(password)
|
||||||
print(resp)
|
data = {
|
||||||
if (resp.status_code==200):
|
"email": str(login),
|
||||||
response=resp.json()
|
"password": str(password)
|
||||||
TOKEN = response['token']
|
}
|
||||||
controller.show_frame(MainView)
|
resp = requests.post(URL, json=data)
|
||||||
else:
|
print(resp)
|
||||||
print("bad pass")
|
if resp.status_code == 200:
|
||||||
badPassLabel = tk.Label(self, text='Wrong login/password!', font=FONT)
|
response = resp.json()
|
||||||
badPassLabel.pack()
|
token = response['token']
|
||||||
return()
|
|
||||||
|
controller.show_frame(MainView, token)
|
||||||
|
else:
|
||||||
class MainView(tk.Frame):
|
print("bad pass")
|
||||||
|
bad_pass_label = tk.Label(self, text='Wrong login/password!', font=FONT)
|
||||||
def __init__(self, parent, controller):
|
bad_pass_label.pack()
|
||||||
tk.Frame.__init__(self,parent)
|
return ()
|
||||||
label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE)
|
|
||||||
label.pack(pady=10,padx=10)
|
|
||||||
label_u = tk.Label(self, text="Main menu", font=FONT)
|
class MainView(tk.Frame):
|
||||||
label_u.pack(pady=10,padx=10)
|
|
||||||
|
def __init__(self, parent, controller):
|
||||||
|
tk.Frame.__init__(self, parent)
|
||||||
class RegisterView(tk.Frame):
|
self.frames = {}
|
||||||
|
self.token = ''
|
||||||
def __init__(self, parent, controller):
|
for F in (ProfileView,):
|
||||||
tk.Frame.__init__(self,parent)
|
frame = F(parent, controller)
|
||||||
label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE)
|
|
||||||
label.pack(pady=10,padx=10)
|
self.frames[F] = frame
|
||||||
label_u = tk.Label(self, text="Register", font=FONT)
|
|
||||||
label_u.pack(pady=10,padx=10)
|
frame.grid(row=0, column=0, sticky="nsew")
|
||||||
|
label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE)
|
||||||
label1 = tk.Label(self, text='Login:', font=FONT)
|
label.pack(pady=10, padx=10)
|
||||||
label1.pack()
|
label_u = tk.Label(self, text="Main menu", font=FONT)
|
||||||
|
label_u.pack(pady=10, padx=10)
|
||||||
input1 = tk.Entry(self)
|
|
||||||
input1.pack()
|
button_profile = tk.Button(self, text="My profile", font=FONT,
|
||||||
|
command=lambda: self.show_frame(ProfileView))
|
||||||
label2 = tk.Label(self, text='Password:', font=FONT)
|
button_profile.pack()
|
||||||
label2.pack()
|
|
||||||
|
def show_frame(self, view):
|
||||||
input2 = tk.Entry(self)
|
frame = self.frames[view]
|
||||||
input2.pack()
|
frame.tkraise()
|
||||||
|
|
||||||
label3 = tk.Label(self, text='Email:', font=FONT)
|
if self.token:
|
||||||
label3.pack()
|
print(self.token)
|
||||||
|
frame.token = self.token
|
||||||
input3 = tk.Entry(self)
|
frame.start()
|
||||||
input3.pack()
|
|
||||||
|
|
||||||
button = tk.Button(self, text="Register", font=FONT, command=lambda: controller.show_frame(RegisterView))
|
class RegisterView(tk.Frame):
|
||||||
button.pack()
|
|
||||||
|
def __init__(self, parent, controller):
|
||||||
|
tk.Frame.__init__(self, parent)
|
||||||
app = SmartPicasso()
|
label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE)
|
||||||
app.mainloop()
|
label.pack(pady=10, padx=10)
|
||||||
|
label_u = tk.Label(self, text="Register", font=FONT)
|
||||||
|
label_u.pack(pady=10, padx=10)
|
||||||
|
|
||||||
|
label0 = tk.Label(self, text='Email:', font=FONT)
|
||||||
|
label0.pack()
|
||||||
|
|
||||||
|
input0 = tk.Entry(self)
|
||||||
|
input0.pack()
|
||||||
|
|
||||||
|
label1 = tk.Label(self, text='Login:', font=FONT)
|
||||||
|
label1.pack()
|
||||||
|
|
||||||
|
input1 = tk.Entry(self)
|
||||||
|
input1.pack()
|
||||||
|
|
||||||
|
label2 = tk.Label(self, text='Password:', font=FONT)
|
||||||
|
label2.pack()
|
||||||
|
|
||||||
|
input2 = tk.Entry(self, show="*")
|
||||||
|
input2.pack()
|
||||||
|
|
||||||
|
label3 = tk.Label(self, text='First name:', font=FONT)
|
||||||
|
label3.pack()
|
||||||
|
|
||||||
|
input3 = tk.Entry(self)
|
||||||
|
input3.pack()
|
||||||
|
|
||||||
|
label4 = tk.Label(self, text='Last name:', font=FONT)
|
||||||
|
label4.pack()
|
||||||
|
|
||||||
|
input4 = tk.Entry(self)
|
||||||
|
input4.pack()
|
||||||
|
|
||||||
|
button1 = tk.Button(self, text="Register", font=FONT,
|
||||||
|
command=lambda: self.register(controller, input0.get(), input1.get(), input2.get(),
|
||||||
|
input3.get(), input4.get()))
|
||||||
|
button1.pack()
|
||||||
|
|
||||||
|
button2 = tk.Button(self, text="Cancel", font=FONT, command=lambda: controller.show_frame(LoginView))
|
||||||
|
button2.pack()
|
||||||
|
|
||||||
|
def register(self, controller, email, login, passw, name, lastname):
|
||||||
|
data = {
|
||||||
|
"email": str(email),
|
||||||
|
"password": str(passw),
|
||||||
|
"profile": {
|
||||||
|
"username": str(login),
|
||||||
|
"first_name": str(name),
|
||||||
|
"last_name": str(lastname)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print(data)
|
||||||
|
response = requests.post(URL_REGISTER, json=data)
|
||||||
|
print(response)
|
||||||
|
if response.status_code == 201:
|
||||||
|
response = response.json()
|
||||||
|
controller.show_frame(LoginView)
|
||||||
|
else:
|
||||||
|
print("sth wrong")
|
||||||
|
bad_pass_label = tk.Label(self, text='Something went wrong!', font=FONT)
|
||||||
|
bad_pass_label.pack()
|
||||||
|
return ()
|
||||||
|
|
||||||
|
|
||||||
|
class ProfileView(tk.Frame):
|
||||||
|
|
||||||
|
def __init__(self, parent, controller):
|
||||||
|
tk.Frame.__init__(self, parent)
|
||||||
|
self.token = ''
|
||||||
|
label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE)
|
||||||
|
label.pack(pady=10, padx=10)
|
||||||
|
label_l1 = tk.Label(self, text="Login:", font=FONT_B)
|
||||||
|
label_l1.pack(pady=10, padx=10)
|
||||||
|
self.label_username = tk.Label(self, text='', font=FONT)
|
||||||
|
self.label_username.pack(pady=10, padx=10)
|
||||||
|
label_n1 = tk.Label(self, text="Name:", font=FONT_B)
|
||||||
|
label_n1.pack(pady=10, padx=10)
|
||||||
|
self.label_first_name = tk.Label(self, text='', font=FONT)
|
||||||
|
self.label_first_name.pack(pady=10, padx=10)
|
||||||
|
label_ln1 = tk.Label(self, text="Last name", font=FONT_B)
|
||||||
|
label_ln1.pack(pady=10, padx=10)
|
||||||
|
self.label_last_name = tk.Label(self, text='', font=FONT)
|
||||||
|
self.label_last_name.pack(pady=10, padx=10)
|
||||||
|
|
||||||
|
button_profile = tk.Button(self, text="Back", font=FONT,
|
||||||
|
command=lambda: controller.show_frame(MainView, self.token))
|
||||||
|
button_profile.pack()
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
headers = {'Authorization': 'Bearer ' + self.token}
|
||||||
|
resp = requests.get(URL_PROFILE, headers=headers)
|
||||||
|
response = resp.json()
|
||||||
|
print(response)
|
||||||
|
self.label_username['text'] = response['profile']['username']
|
||||||
|
self.label_first_name['text'] = response['profile']['first_name']
|
||||||
|
self.label_last_name['text'] = response['profile']['last_name']
|
||||||
|
|
||||||
|
|
||||||
|
app = SmartPicasso()
|
||||||
|
app.mainloop()
|
||||||
|
2
client/requirements.txt
Normal file
2
client/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
tkinter
|
||||||
|
requests
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user