|
6 | 6 | import os
|
7 | 7 | import socket
|
8 | 8 | import time
|
| 9 | +import re |
9 | 10 |
|
10 | 11 |
|
| 12 | +email_regex = '[A-Za-z0-9._%+-]+@ashoka\.edu\.in' |
11 | 13 | PORT = 2223
|
12 | 14 | client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
13 | 15 | client.connect((socket.gethostname(), PORT))
|
|
18 | 20 | height = 750
|
19 | 21 | pos = (0,-20)
|
20 | 22 |
|
21 |
| - |
| 23 | +client_dir = os.getcwd() |
22 | 24 |
|
23 | 25 | def login_callback(sender, app_data, user_data):
|
24 | 26 |
|
25 | 27 | print("Save Clicked")
|
26 | 28 | print(f"sender is {sender}")
|
27 | 29 | print(f"app_data is {app_data}")
|
28 | 30 | print(f"user data is {user_data}")
|
29 |
| - print(dpg.get_value("username")) |
30 |
| - print(dpg.get_value("password")) |
31 |
| - dpg.delete_item("original") |
| 31 | + email = dpg.get_value("username") |
| 32 | + pswd = dpg.get_value("password") |
| 33 | + if not re.search(email_regex, email): |
| 34 | + dpg.delete_item("original") |
| 35 | + with dpg.window(label="Example Window", width=width, height=height, tag="original", pos=pos): |
| 36 | + |
| 37 | + dpg.add_text("Email must end with '@ashoka.edu.in'.") |
| 38 | + dpg.add_text("Login again to continue.") |
| 39 | + |
| 40 | + else: |
| 41 | + |
| 42 | + |
| 43 | + client.send(email.encode()) |
| 44 | + client.send(pswd.encode()) |
| 45 | + |
| 46 | + msg = client.recv(1024).decode() |
| 47 | + print(msg) |
32 | 48 |
|
33 |
| - with dpg.window(label="Example Window", width=width, height=height, tag="original", pos=pos): |
34 |
| - dpg.add_text("you have logged in") |
35 |
| - with dpg.file_dialog(directory_selector=False, show=False, callback=choose_file_callback, id="file_dialog_id"): |
36 |
| - dpg.add_file_extension(".csv") |
37 |
| - # dpg.add_file_extension("", color=(150, 255, 150, 255)) |
38 |
| - # dpg.add_file_extension("Source files (*.cpp *.h *.hpp){.cpp,.h,.hpp}", color=(0, 255, 255, 255)) |
39 |
| - # dpg.add_file_extension(".h", color=(255, 0, 255, 255), custom_text="[header]") |
40 |
| - # dpg.add_file_extension(".py", color=(0, 255, 0, 255), custom_text="[Python]") |
41 |
| - dpg.add_button(label="File Selector", callback=lambda: dpg.show_item("file_dialog_id")) |
| 49 | + if msg == "Error!": |
| 50 | + dpg.delete_item("original") |
| 51 | + with dpg.window(label="Example Window", width=width, height=height, tag="original", pos=pos): |
| 52 | + dpg.add_text("Login Failed!!") |
| 53 | + dpg.add_text("Please re-run to login.") |
| 54 | + else: |
| 55 | + dpg.delete_item("original") |
| 56 | + |
| 57 | + with dpg.window(label="Example Window", width=width, height=height, tag="original", pos=pos): |
| 58 | + dpg.add_text("you have logged in") |
| 59 | + with dpg.file_dialog(directory_selector=False, show=False, callback=choose_file_callback, id="file_dialog_id"): |
| 60 | + dpg.add_file_extension(".csv") |
| 61 | + # dpg.add_file_extension("", color=(150, 255, 150, 255)) |
| 62 | + # dpg.add_file_extension("Source files (*.cpp *.h *.hpp){.cpp,.h,.hpp}", color=(0, 255, 255, 255)) |
| 63 | + # dpg.add_file_extension(".h", color=(255, 0, 255, 255), custom_text="[header]") |
| 64 | + # dpg.add_file_extension(".py", color=(0, 255, 0, 255), custom_text="[Python]") |
| 65 | + dpg.add_button(label="File Selector", callback=lambda: dpg.show_item("file_dialog_id")) |
42 | 66 |
|
43 | 67 |
|
44 | 68 |
|
@@ -108,13 +132,14 @@ def send_model_data():
|
108 | 132 | file_size = client.recv(1024).decode()
|
109 | 133 |
|
110 | 134 | print(file_size)
|
111 |
| - file_path = 'receivedFitting.png' |
| 135 | + file_path = f'{client_dir}/client_data/receivedFitting.png' |
112 | 136 | file = open(file_path, "wb")
|
113 | 137 | c = 0
|
114 | 138 | # Starting the time capture.
|
115 | 139 | start_time = time.time()
|
116 | 140 |
|
117 | 141 | # Running the loop while file is recieved.
|
| 142 | + |
118 | 143 | while c < int(file_size):
|
119 | 144 | data = client.recv(1024)
|
120 | 145 | if not (data):
|
@@ -160,7 +185,7 @@ def send_model_data():
|
160 | 185 | #Receive Report from server
|
161 | 186 | file_size = client.recv(1024).decode()
|
162 | 187 | print(file_size)
|
163 |
| - file_path = 'sentreport.pdf' |
| 188 | + file_path = f'{client_dir}/client_data/sentreport.pdf' |
164 | 189 | file = open(file_path, "wb")
|
165 | 190 | c = 0
|
166 | 191 | # Starting the time capture.
|
@@ -192,48 +217,25 @@ def send_model_data():
|
192 | 217 |
|
193 | 218 | dpg.delete_item("original")
|
194 | 219 | with dpg.window(label="Example Window", width=900, height=750, tag="original", pos=pos):
|
195 |
| - dpg.add_text("Your final report downloaded at location: " + str(file_path)) |
| 220 | + dpg.add_text("Your final report downloaded at location: \n {client_dir}\\client_data\\sentreport.pdf" ) |
196 | 221 |
|
197 | 222 |
|
198 | 223 |
|
199 | 224 | def get_model_inputs():
|
200 | 225 | pass
|
201 | 226 |
|
202 |
| - |
203 |
| - |
204 |
| - |
205 |
| - |
206 |
| - |
207 |
| - |
208 |
| - |
209 |
| - |
210 |
| - |
211 |
| - |
212 |
| - |
213 |
| - |
214 |
| - |
215 |
| - |
216 |
| - |
217 |
| - |
218 |
| - |
219 | 227 | dpg.create_context()
|
220 | 228 | dpg.create_viewport(title="Machine Learning on Server", width=width, height=height, x_pos=0, y_pos=-20)
|
221 | 229 | dpg.setup_dearpygui()
|
222 | 230 |
|
223 | 231 |
|
224 |
| - |
225 |
| - |
226 |
| - |
227 | 232 | with dpg.window(label="Example Window", width=width, height=height, tag="original", pos=pos):
|
228 | 233 | dpg.add_text("Enter your login credentials")
|
229 | 234 | dpg.add_input_text(label="User Name", tag="username")
|
230 |
| - dpg.add_input_text(label="Password", tag="password") |
| 235 | + dpg.add_input_text(label="Password", tag="password", password=True) |
231 | 236 | dpg.add_button(label="Login", callback=login_callback)
|
232 |
| - # dpg.add_slider_float(label="float") |
233 |
| - |
234 |
| - |
235 |
| - |
236 | 237 |
|
| 238 | + # dpg.add_slider_float(label="float") |
237 | 239 |
|
238 | 240 | dpg.show_viewport()
|
239 | 241 | dpg.start_dearpygui()
|
|
0 commit comments