From 5080ab5c8d9b4fe8732552132e2292734ebf0287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20=C5=81aganowski?= Date: Mon, 14 Dec 2020 07:02:08 +0100 Subject: [PATCH 1/2] Updated client app with 2 new views --- client/app.py | 334 +++++++++++++++++++++++++++++++------------------- 1 file changed, 207 insertions(+), 127 deletions(-) diff --git a/client/app.py b/client/app.py index 22bca28..f36f084 100644 --- a/client/app.py +++ b/client/app.py @@ -1,128 +1,208 @@ -import tkinter as tk -import requests - -FONT= ("Verdana", 12) -FONT_LARGE= ("Verdana", 20) -URL = "http://localhost:8000/api/authenticate" -TOKEN = "" - -class SmartPicasso(tk.Tk): - - def __init__(self, *args, **kwargs): - - tk.Tk.__init__(self, *args, **kwargs) - container = tk.Frame(self) - self.title('SmartPicasso') - self.geometry('610x460') - - container.pack(side="top", fill="both", expand = True) - - container.grid_rowconfigure(0, weight=1) - container.grid_columnconfigure(0, weight=1) - - self.frames = {} - - for F in (LoginPage, MainView, RegisterView): - - frame = F(container, self) - - self.frames[F] = frame - - frame.grid(row=0, column=0, sticky="nsew") - - self.show_frame(LoginPage) - - def show_frame(self, cont): - - frame = self.frames[cont] - frame.tkraise() - - -class LoginPage(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) - - 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) - input2.pack() - - button = tk.Button(self, text="Login", font=FONT, command=lambda: self.login(controller, input1.get(), input2.get())) - button.pack() - - button2 = tk.Button(self, text="Register", font=FONT, command=lambda: controller.show_frame(RegisterView)) - button2.pack() - - def login(self, controller, login, passw,): - print(login) - print(passw) - data = { - "email": str(login), - "password": str(passw) - } - resp = requests.post(URL, json=data) - print(resp) - if (resp.status_code==200): - response=resp.json() - TOKEN = response['token'] - controller.show_frame(MainView) - else: - print("bad pass") - badPassLabel = tk.Label(self, text='Wrong login/password!', font=FONT) - badPassLabel.pack() - return() - - -class MainView(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_u = tk.Label(self, text="Main menu", font=FONT) - label_u.pack(pady=10,padx=10) - - -class RegisterView(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_u = tk.Label(self, text="Register", font=FONT) - label_u.pack(pady=10,padx=10) - - 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) - input2.pack() - - label3 = tk.Label(self, text='Email:', font=FONT) - label3.pack() - - input3 = tk.Entry(self) - input3.pack() - - button = tk.Button(self, text="Register", font=FONT, command=lambda: controller.show_frame(RegisterView)) - button.pack() - - -app = SmartPicasso() +import tkinter as tk +import requests + +FONT= ("Verdana", 12) +FONT_B= ("Verdana", 12, 'bold') +FONT_LARGE= ("Verdana", 20) +URL = "http://localhost:8000/api/authenticate" +URL_REGISTER = "http://localhost:8000/api/register" +URL_PROFILE = "http://localhost:8000/api/profile" +TOKEN = "" +USERNAME = "" +FIRST_NAME = "" +LAST_NAME = "" + + +class SmartPicasso(tk.Tk): + + def __init__(self, *args, **kwargs): + + tk.Tk.__init__(self, *args, **kwargs) + container = tk.Frame(self) + self.title('SmartPicasso') + self.geometry('610x460') + + container.pack(side="top", fill="both", expand = True) + + container.grid_rowconfigure(0, weight=1) + container.grid_columnconfigure(0, weight=1) + + self.frames = {} + + for F in (LoginView, MainView, RegisterView, ProfileView): + + frame = F(container, self) + + self.frames[F] = frame + + frame.grid(row=0, column=0, sticky="nsew") + + self.show_frame(LoginView) + + def show_frame(self, cont): + + frame = self.frames[cont] + frame.tkraise() + + +class LoginView(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) + + 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() + + button = tk.Button(self, text="Login", font=FONT, command=lambda: self.login(controller, input1.get(), input2.get())) + button.pack() + + button2 = tk.Button(self, text="Register", font=FONT, command=lambda: controller.show_frame(RegisterView)) + button2.pack() + + def login(self, controller, login, passw,): + print(login) + print(passw) + data = { + "email": str(login), + "password": str(passw) + } + resp = requests.post(URL, json=data) + print(resp) + if (resp.status_code==200): + response=resp.json() + 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) + else: + print("bad pass") + badPassLabel = tk.Label(self, text='Wrong login/password!', font=FONT) + badPassLabel.pack() + return() + + +class MainView(tk.Frame): + + def __init__(self, parent, controller): + tk.Frame.__init__(self,parent) + self.profile = ProfileView() + 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) + 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): + + 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_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) + 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() \ No newline at end of file -- 2.20.1 From fb65e04600c6ff4eff87321ae6f4fa76b881425d Mon Sep 17 00:00:00 2001 From: s460930 Date: Mon, 14 Dec 2020 13:24:23 +0100 Subject: [PATCH 2/2] SMART-43 implemented user profile view --- client/app.py | 194 ++++++++++-------- client/requirements.txt | 2 + rest-app/db.sqlite3 | Bin 172032 -> 172032 bytes .../__pycache__/urls.cpython-38.pyc | Bin 1065 -> 1065 bytes .../__pycache__/models.cpython-38.pyc | Bin 1266 -> 1266 bytes 5 files changed, 109 insertions(+), 87 deletions(-) create mode 100644 client/requirements.txt diff --git a/client/app.py b/client/app.py index f36f084..d16504d 100644 --- a/client/app.py +++ b/client/app.py @@ -1,36 +1,31 @@ import tkinter as tk + import requests -FONT= ("Verdana", 12) -FONT_B= ("Verdana", 12, 'bold') -FONT_LARGE= ("Verdana", 20) +FONT = ("Verdana", 12) +FONT_B = ("Verdana", 12, 'bold') +FONT_LARGE = ("Verdana", 20) URL = "http://localhost:8000/api/authenticate" URL_REGISTER = "http://localhost:8000/api/register" URL_PROFILE = "http://localhost:8000/api/profile" -TOKEN = "" -USERNAME = "" -FIRST_NAME = "" -LAST_NAME = "" class SmartPicasso(tk.Tk): def __init__(self, *args, **kwargs): - tk.Tk.__init__(self, *args, **kwargs) container = tk.Frame(self) self.title('SmartPicasso') self.geometry('610x460') - container.pack(side="top", fill="both", expand = True) + container.pack(side="top", fill="both", expand=True) container.grid_rowconfigure(0, weight=1) container.grid_columnconfigure(0, weight=1) self.frames = {} - for F in (LoginView, MainView, RegisterView, ProfileView): - + for F in (LoginView, MainView, RegisterView): frame = F(container, self) self.frames[F] = frame @@ -39,123 +34,139 @@ class SmartPicasso(tk.Tk): self.show_frame(LoginView) - def show_frame(self, cont): - - frame = self.frames[cont] + def show_frame(self, view, token=None): + frame = self.frames[view] frame.tkraise() - + if token: + frame.token = token + + class LoginView(tk.Frame): def __init__(self, parent, controller): - tk.Frame.__init__(self,parent) + tk.Frame.__init__(self, parent) label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE) - label.pack(pady=10,padx=10) - + label.pack(pady=10, padx=10) + 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() - - 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())) button.pack() button2 = tk.Button(self, text="Register", font=FONT, command=lambda: controller.show_frame(RegisterView)) button2.pack() - def login(self, controller, login, passw,): + def login(self, controller, login, password): print(login) - print(passw) + print(password) data = { "email": str(login), - "password": str(passw) + "password": str(password) } resp = requests.post(URL, json=data) print(resp) - if (resp.status_code==200): - response=resp.json() - 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) + if resp.status_code == 200: + response = resp.json() + token = response['token'] + + controller.show_frame(MainView, token) else: print("bad pass") - badPassLabel = tk.Label(self, text='Wrong login/password!', font=FONT) - badPassLabel.pack() - return() + bad_pass_label = tk.Label(self, text='Wrong login/password!', font=FONT) + bad_pass_label.pack() + return () class MainView(tk.Frame): def __init__(self, parent, controller): - tk.Frame.__init__(self,parent) - self.profile = ProfileView() + tk.Frame.__init__(self, parent) + self.frames = {} + self.token = '' + for F in (ProfileView,): + frame = F(parent, controller) + + self.frames[F] = frame + + frame.grid(row=0, column=0, sticky="nsew") 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.pack(pady=10,padx=10) - - button_profile = tk.Button(self, text="My profile", font=FONT, command=lambda: controller.show_frame(ProfileView)) + label_u.pack(pady=10, padx=10) + + button_profile = tk.Button(self, text="My profile", font=FONT, + command=lambda: self.show_frame(ProfileView)) button_profile.pack() + def show_frame(self, view): + frame = self.frames[view] + frame.tkraise() + + if self.token: + print(self.token) + frame.token = self.token + frame.start() + class RegisterView(tk.Frame): def __init__(self, parent, controller): - tk.Frame.__init__(self,parent) + tk.Frame.__init__(self, parent) 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="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.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 = 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), @@ -164,45 +175,54 @@ class RegisterView(tk.Frame): "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() + 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") - badPassLabel = tk.Label(self, text='Something went wrong!', font=FONT) - badPassLabel.pack() - return() - - + 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) + tk.Frame.__init__(self, parent) + self.token = '' label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE) - label.pack(pady=10,padx=10) + 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_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) - label_n2 = tk.Label(self, text=FIRST_NAME, font=FONT) - label_n2.pack(pady=10,padx=10) + 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) - label_ln2 = tk.Label(self, text=LAST_NAME, font=FONT) - label_ln2.pack(pady=10,padx=10) + 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)) + 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() \ No newline at end of file +app.mainloop() diff --git a/client/requirements.txt b/client/requirements.txt new file mode 100644 index 0000000..7819b5f --- /dev/null +++ b/client/requirements.txt @@ -0,0 +1,2 @@ +tkinter +requests diff --git a/rest-app/db.sqlite3 b/rest-app/db.sqlite3 index 683cf594817d08386bf594a78edadb42d6b60fcf..d864fe3c5e86be76a82c7f9267861324c9416e76 100644 GIT binary patch delta 584 zcmZoTz}0YoYl1YR$3z)tMvumXtqF`v{`0W#RxMUp2{}mia~QZlRI+ z8Rj85hRIoZQGppD5s5yTAkC+clal5Y>eesQDOFFL^24gInyV~GZh21&SBs`#lM#SIscr^ zf&~ry(6G<}UeQv?qS-&6+vrTm_JZ}_HeY;5HV4`pHV6_)iCH8eLj zNj6GKN=r>LF)=kUwoFVmH%Ut~NdX3#xn)wSS7M%betBX}adsvlXMt?p{>F|;0_v?v zK#$$w-wyJYD#%-etYVoy$)Bl+{28XBjWo0%jVnpvhA znI)y9S(sQF8e15pnxy3CB$g!V6(p7vRq|vTJEZ3(X6EQ6=jU#hn@~fyY`!W(TboxYjredJhwG8~H_}B73=YPIgu%Ll|`UHI@9s!U|$QDgs zqt6t<#mx7HfqyB#C*PZmjraJrzp-PIVB`W@J_%^~cA)+i{^^tanTjBSU>AV}SwIe& ju3*okuzg!Rlb-=l{uTrO3;tXDUxD&x_^02R&!h$bt{Ztd diff --git a/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc index 1e0968f9032eb5f779cf4ecaa43d3b76d1d3b828..74531e51a90c6aab03055b11e1b628ef6f40e6ef 100644 GIT binary patch delta 20 acmZ3MT-?Yl#{vK^D+GN2 diff --git a/rest-app/smartpicasso/app/user_profile/__pycache__/models.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/__pycache__/models.cpython-38.pyc index f6fe6fc5f81ca8a878a11923aabea00bc4c40b8d..615a5950e9d2ebf7c76a343adbdb1d744eb65d7e 100644 GIT binary patch delta 20 acmeyw`H7P|l$V!_0SG2BT;It3oCN?mt_6z# delta 20 acmeyw`H7P|l$V!_0SI>MT-?b0oCN?ow*}e& -- 2.20.1