develop #7
@ -2,9 +2,16 @@ import tkinter as tk
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
FONT= ("Verdana", 12)
|
FONT= ("Verdana", 12)
|
||||||
|
FONT_B= ("Verdana", 12, 'bold')
|
||||||
FONT_LARGE= ("Verdana", 20)
|
FONT_LARGE= ("Verdana", 20)
|
||||||
URL = "http://localhost:8000/api/authenticate"
|
URL = "http://localhost:8000/api/authenticate"
|
||||||
|
URL_REGISTER = "http://localhost:8000/api/register"
|
||||||
|
URL_PROFILE = "http://localhost:8000/api/profile"
|
||||||
TOKEN = ""
|
TOKEN = ""
|
||||||
|
USERNAME = ""
|
||||||
|
FIRST_NAME = ""
|
||||||
|
LAST_NAME = ""
|
||||||
|
|
||||||
|
|
||||||
class SmartPicasso(tk.Tk):
|
class SmartPicasso(tk.Tk):
|
||||||
|
|
||||||
@ -22,7 +29,7 @@ class SmartPicasso(tk.Tk):
|
|||||||
|
|
||||||
self.frames = {}
|
self.frames = {}
|
||||||
|
|
||||||
for F in (LoginPage, MainView, RegisterView):
|
for F in (LoginView, MainView, RegisterView, ProfileView):
|
||||||
|
|
||||||
frame = F(container, self)
|
frame = F(container, self)
|
||||||
|
|
||||||
@ -30,7 +37,7 @@ class SmartPicasso(tk.Tk):
|
|||||||
|
|
||||||
frame.grid(row=0, column=0, sticky="nsew")
|
frame.grid(row=0, column=0, sticky="nsew")
|
||||||
|
|
||||||
self.show_frame(LoginPage)
|
self.show_frame(LoginView)
|
||||||
|
|
||||||
def show_frame(self, cont):
|
def show_frame(self, cont):
|
||||||
|
|
||||||
@ -38,7 +45,7 @@ class SmartPicasso(tk.Tk):
|
|||||||
frame.tkraise()
|
frame.tkraise()
|
||||||
|
|
||||||
|
|
||||||
class LoginPage(tk.Frame):
|
class LoginView(tk.Frame):
|
||||||
|
|
||||||
def __init__(self, parent, controller):
|
def __init__(self, parent, controller):
|
||||||
tk.Frame.__init__(self,parent)
|
tk.Frame.__init__(self,parent)
|
||||||
@ -54,7 +61,7 @@ class LoginPage(tk.Frame):
|
|||||||
label2 = tk.Label(self, text='Password:', font=FONT)
|
label2 = tk.Label(self, text='Password:', font=FONT)
|
||||||
label2.pack()
|
label2.pack()
|
||||||
|
|
||||||
input2 = tk.Entry(self)
|
input2 = tk.Entry(self, show="*")
|
||||||
input2.pack()
|
input2.pack()
|
||||||
|
|
||||||
button = tk.Button(self, text="Login", font=FONT, command=lambda: self.login(controller, input1.get(), input2.get()))
|
button = tk.Button(self, text="Login", font=FONT, command=lambda: self.login(controller, input1.get(), input2.get()))
|
||||||
@ -75,6 +82,14 @@ class LoginPage(tk.Frame):
|
|||||||
if (resp.status_code==200):
|
if (resp.status_code==200):
|
||||||
response=resp.json()
|
response=resp.json()
|
||||||
TOKEN = response['token']
|
TOKEN = response['token']
|
||||||
|
|
||||||
|
hed = {'Authorization': 'Bearer ' + TOKEN}
|
||||||
|
resp = requests.get(URL_PROFILE, headers=hed)
|
||||||
|
response=resp.json()
|
||||||
|
USERNAME = response['profile']['username']
|
||||||
|
FIRST_NAME = response['profile']['first_name']
|
||||||
|
LAST_NAME = response['profile']['last_name']
|
||||||
|
|
||||||
controller.show_frame(MainView)
|
controller.show_frame(MainView)
|
||||||
else:
|
else:
|
||||||
print("bad pass")
|
print("bad pass")
|
||||||
@ -87,11 +102,15 @@ class MainView(tk.Frame):
|
|||||||
|
|
||||||
def __init__(self, parent, controller):
|
def __init__(self, parent, controller):
|
||||||
tk.Frame.__init__(self,parent)
|
tk.Frame.__init__(self,parent)
|
||||||
|
self.profile = ProfileView()
|
||||||
label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE)
|
label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE)
|
||||||
label.pack(pady=10,padx=10)
|
label.pack(pady=10,padx=10)
|
||||||
label_u = tk.Label(self, text="Main menu", font=FONT)
|
label_u = tk.Label(self, text="Main menu", font=FONT)
|
||||||
label_u.pack(pady=10,padx=10)
|
label_u.pack(pady=10,padx=10)
|
||||||
|
|
||||||
|
button_profile = tk.Button(self, text="My profile", font=FONT, command=lambda: controller.show_frame(ProfileView))
|
||||||
|
button_profile.pack()
|
||||||
|
|
||||||
|
|
||||||
class RegisterView(tk.Frame):
|
class RegisterView(tk.Frame):
|
||||||
|
|
||||||
@ -102,6 +121,12 @@ class RegisterView(tk.Frame):
|
|||||||
label_u = tk.Label(self, text="Register", font=FONT)
|
label_u = tk.Label(self, text="Register", font=FONT)
|
||||||
label_u.pack(pady=10,padx=10)
|
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 = tk.Label(self, text='Login:', font=FONT)
|
||||||
label1.pack()
|
label1.pack()
|
||||||
|
|
||||||
@ -111,17 +136,72 @@ class RegisterView(tk.Frame):
|
|||||||
label2 = tk.Label(self, text='Password:', font=FONT)
|
label2 = tk.Label(self, text='Password:', font=FONT)
|
||||||
label2.pack()
|
label2.pack()
|
||||||
|
|
||||||
input2 = tk.Entry(self)
|
input2 = tk.Entry(self, show="*")
|
||||||
input2.pack()
|
input2.pack()
|
||||||
|
|
||||||
label3 = tk.Label(self, text='Email:', font=FONT)
|
label3 = tk.Label(self, text='First name:', font=FONT)
|
||||||
label3.pack()
|
label3.pack()
|
||||||
|
|
||||||
input3 = tk.Entry(self)
|
input3 = tk.Entry(self)
|
||||||
input3.pack()
|
input3.pack()
|
||||||
|
|
||||||
button = tk.Button(self, text="Register", font=FONT, command=lambda: controller.show_frame(RegisterView))
|
label4 = tk.Label(self, text='Last name:', font=FONT)
|
||||||
button.pack()
|
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)
|
||||||
|
resp = requests.post(URL_REGISTER, json=data)
|
||||||
|
print(resp)
|
||||||
|
if (resp.status_code==201):
|
||||||
|
response=resp.json()
|
||||||
|
controller.show_frame(LoginView)
|
||||||
|
else:
|
||||||
|
print("sth wrong")
|
||||||
|
badPassLabel = tk.Label(self, text='Something went wrong!', font=FONT)
|
||||||
|
badPassLabel.pack()
|
||||||
|
return()
|
||||||
|
|
||||||
|
|
||||||
|
class ProfileView(tk.Frame):
|
||||||
|
|
||||||
|
def __init__(self, parent, controller):
|
||||||
|
|
||||||
|
tk.Frame.__init__(self,parent)
|
||||||
|
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)
|
||||||
|
label_l2 = tk.Label(self, text=USERNAME, font=FONT)
|
||||||
|
label_l2.pack(pady=10,padx=10)
|
||||||
|
label_n1 = tk.Label(self, text="Name:", font=FONT_B)
|
||||||
|
label_n1.pack(pady=10,padx=10)
|
||||||
|
label_n2 = tk.Label(self, text=FIRST_NAME, font=FONT)
|
||||||
|
label_n2.pack(pady=10,padx=10)
|
||||||
|
label_ln1 = tk.Label(self, text="Last name", font=FONT_B)
|
||||||
|
label_ln1.pack(pady=10,padx=10)
|
||||||
|
label_ln2 = tk.Label(self, text=LAST_NAME, font=FONT)
|
||||||
|
label_ln2.pack(pady=10,padx=10)
|
||||||
|
|
||||||
|
|
||||||
|
button_profile = tk.Button(self, text="Back", font=FONT, command=lambda: controller.show_frame(MainView))
|
||||||
|
button_profile.pack()
|
||||||
|
|
||||||
|
|
||||||
app = SmartPicasso()
|
app = SmartPicasso()
|
||||||
|
Loading…
Reference in New Issue
Block a user