develop #7

Merged
s460930 merged 12 commits from develop into master 2020-12-14 16:36:47 +01:00
Showing only changes of commit 5080ab5c8d - Show all commits

View File

@ -1,128 +1,208 @@
import tkinter as tk import tkinter as tk
import requests import requests
FONT= ("Verdana", 12) FONT= ("Verdana", 12)
FONT_LARGE= ("Verdana", 20) FONT_B= ("Verdana", 12, 'bold')
URL = "http://localhost:8000/api/authenticate" FONT_LARGE= ("Verdana", 20)
TOKEN = "" URL = "http://localhost:8000/api/authenticate"
URL_REGISTER = "http://localhost:8000/api/register"
class SmartPicasso(tk.Tk): URL_PROFILE = "http://localhost:8000/api/profile"
TOKEN = ""
def __init__(self, *args, **kwargs): USERNAME = ""
FIRST_NAME = ""
tk.Tk.__init__(self, *args, **kwargs) LAST_NAME = ""
container = tk.Frame(self)
self.title('SmartPicasso')
self.geometry('610x460') class SmartPicasso(tk.Tk):
container.pack(side="top", fill="both", expand = True) def __init__(self, *args, **kwargs):
container.grid_rowconfigure(0, weight=1) tk.Tk.__init__(self, *args, **kwargs)
container.grid_columnconfigure(0, weight=1) container = tk.Frame(self)
self.title('SmartPicasso')
self.frames = {} self.geometry('610x460')
for F in (LoginPage, MainView, RegisterView): container.pack(side="top", fill="both", expand = True)
frame = F(container, self) container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames[F] = frame
self.frames = {}
frame.grid(row=0, column=0, sticky="nsew")
for F in (LoginView, MainView, RegisterView, ProfileView):
self.show_frame(LoginPage)
frame = F(container, self)
def show_frame(self, cont):
self.frames[F] = frame
frame = self.frames[cont]
frame.tkraise() frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(LoginView)
class LoginPage(tk.Frame):
def show_frame(self, cont):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent) frame = self.frames[cont]
label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE) frame.tkraise()
label.pack(pady=10,padx=10)
label1 = tk.Label(self, text='Login:', font=FONT) class LoginView(tk.Frame):
label1.pack()
def __init__(self, parent, controller):
input1 = tk.Entry(self) tk.Frame.__init__(self,parent)
input1.pack() label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE)
label.pack(pady=10,padx=10)
label2 = tk.Label(self, text='Password:', font=FONT)
label2.pack() label1 = tk.Label(self, text='Login:', font=FONT)
label1.pack()
input2 = tk.Entry(self)
input2.pack() input1 = tk.Entry(self)
input1.pack()
button = tk.Button(self, text="Login", font=FONT, command=lambda: self.login(controller, input1.get(), input2.get()))
button.pack() label2 = tk.Label(self, text='Password:', font=FONT)
label2.pack()
button2 = tk.Button(self, text="Register", font=FONT, command=lambda: controller.show_frame(RegisterView))
button2.pack() input2 = tk.Entry(self, show="*")
input2.pack()
def login(self, controller, login, passw,):
print(login) button = tk.Button(self, text="Login", font=FONT, command=lambda: self.login(controller, input1.get(), input2.get()))
print(passw) button.pack()
data = {
"email": str(login), button2 = tk.Button(self, text="Register", font=FONT, command=lambda: controller.show_frame(RegisterView))
"password": str(passw) button2.pack()
}
resp = requests.post(URL, json=data) def login(self, controller, login, passw,):
print(resp) print(login)
if (resp.status_code==200): print(passw)
response=resp.json() data = {
TOKEN = response['token'] "email": str(login),
controller.show_frame(MainView) "password": str(passw)
else: }
print("bad pass") resp = requests.post(URL, json=data)
badPassLabel = tk.Label(self, text='Wrong login/password!', font=FONT) print(resp)
badPassLabel.pack() if (resp.status_code==200):
return() response=resp.json()
TOKEN = response['token']
class MainView(tk.Frame): hed = {'Authorization': 'Bearer ' + TOKEN}
resp = requests.get(URL_PROFILE, headers=hed)
def __init__(self, parent, controller): response=resp.json()
tk.Frame.__init__(self,parent) USERNAME = response['profile']['username']
label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE) FIRST_NAME = response['profile']['first_name']
label.pack(pady=10,padx=10) LAST_NAME = response['profile']['last_name']
label_u = tk.Label(self, text="Main menu", font=FONT)
label_u.pack(pady=10,padx=10) controller.show_frame(MainView)
else:
print("bad pass")
class RegisterView(tk.Frame): badPassLabel = tk.Label(self, text='Wrong login/password!', font=FONT)
badPassLabel.pack()
def __init__(self, parent, controller): return()
tk.Frame.__init__(self,parent)
label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE)
label.pack(pady=10,padx=10) class MainView(tk.Frame):
label_u = tk.Label(self, text="Register", font=FONT)
label_u.pack(pady=10,padx=10) def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
label1 = tk.Label(self, text='Login:', font=FONT) self.profile = ProfileView()
label1.pack() label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE)
label.pack(pady=10,padx=10)
input1 = tk.Entry(self) label_u = tk.Label(self, text="Main menu", font=FONT)
input1.pack() label_u.pack(pady=10,padx=10)
label2 = tk.Label(self, text='Password:', font=FONT) button_profile = tk.Button(self, text="My profile", font=FONT, command=lambda: controller.show_frame(ProfileView))
label2.pack() button_profile.pack()
input2 = tk.Entry(self)
input2.pack() class RegisterView(tk.Frame):
label3 = tk.Label(self, text='Email:', font=FONT) def __init__(self, parent, controller):
label3.pack() tk.Frame.__init__(self,parent)
label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE)
input3 = tk.Entry(self) label.pack(pady=10,padx=10)
input3.pack() label_u = tk.Label(self, text="Register", font=FONT)
label_u.pack(pady=10,padx=10)
button = tk.Button(self, text="Register", font=FONT, command=lambda: controller.show_frame(RegisterView))
button.pack() label0 = tk.Label(self, text='Email:', font=FONT)
label0.pack()
app = SmartPicasso() 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)
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.mainloop() app.mainloop()