Skip to content

Commit f389bee

Browse files
committed
login implemented
1 parent d3ce0d7 commit f389bee

24 files changed

+184
-48
lines changed

__pycache__/models.cpython-39.pyc

-16 Bytes
Binary file not shown.

__pycache__/server1.cpython-39.pyc

2.3 KB
Binary file not shown.

app.py

+43-41
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
import os
77
import socket
88
import time
9+
import re
910

1011

12+
email_regex = '[A-Za-z0-9._%+-]+@ashoka\.edu\.in'
1113
PORT = 2223
1214
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1315
client.connect((socket.gethostname(), PORT))
@@ -18,27 +20,49 @@
1820
height = 750
1921
pos = (0,-20)
2022

21-
23+
client_dir = os.getcwd()
2224

2325
def login_callback(sender, app_data, user_data):
2426

2527
print("Save Clicked")
2628
print(f"sender is {sender}")
2729
print(f"app_data is {app_data}")
2830
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)
3248

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"))
4266

4367

4468

@@ -108,13 +132,14 @@ def send_model_data():
108132
file_size = client.recv(1024).decode()
109133

110134
print(file_size)
111-
file_path = 'receivedFitting.png'
135+
file_path = f'{client_dir}/client_data/receivedFitting.png'
112136
file = open(file_path, "wb")
113137
c = 0
114138
# Starting the time capture.
115139
start_time = time.time()
116140

117141
# Running the loop while file is recieved.
142+
118143
while c < int(file_size):
119144
data = client.recv(1024)
120145
if not (data):
@@ -160,7 +185,7 @@ def send_model_data():
160185
#Receive Report from server
161186
file_size = client.recv(1024).decode()
162187
print(file_size)
163-
file_path = 'sentreport.pdf'
188+
file_path = f'{client_dir}/client_data/sentreport.pdf'
164189
file = open(file_path, "wb")
165190
c = 0
166191
# Starting the time capture.
@@ -192,48 +217,25 @@ def send_model_data():
192217

193218
dpg.delete_item("original")
194219
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" )
196221

197222

198223

199224
def get_model_inputs():
200225
pass
201226

202-
203-
204-
205-
206-
207-
208-
209-
210-
211-
212-
213-
214-
215-
216-
217-
218-
219227
dpg.create_context()
220228
dpg.create_viewport(title="Machine Learning on Server", width=width, height=height, x_pos=0, y_pos=-20)
221229
dpg.setup_dearpygui()
222230

223231

224-
225-
226-
227232
with dpg.window(label="Example Window", width=width, height=height, tag="original", pos=pos):
228233
dpg.add_text("Enter your login credentials")
229234
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)
231236
dpg.add_button(label="Login", callback=login_callback)
232-
# dpg.add_slider_float(label="float")
233-
234-
235-
236237

238+
# dpg.add_slider_float(label="float")
237239

238240
dpg.show_viewport()
239241
dpg.start_dearpygui()

client_data/receivedFitting.png

28.7 KB
Loading

receivedFitting.png

-1.62 KB
Loading

sentreport.pdf

-2.08 KB
Binary file not shown.

server1.py

+40-7
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,60 @@
55
import pandas as pd
66
from utils import *
77
from create_report import *
8+
import re
9+
import hashlib
10+
from threading import *
811

912
PORT = 2223
1013
SERVER = socket.gethostname()
1114
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1215
server.bind((SERVER, PORT))
13-
HEADER = 2048
16+
HEADER = 1024
1417

1518
server_dir = "./server_data/"
1619

20+
user_dic = {}
21+
live_table = []
22+
23+
24+
def password_check(email, pswd):
25+
if email in user_dic:
26+
if user_dic[email] == pswd:
27+
live_table.append(email)
28+
return "Login"
29+
elif user_dic[email] != pswd:
30+
return "Error"
31+
else:
32+
user_dic[email] = pswd
33+
live_table.append(email)
34+
return "Signup"
35+
1736
while True:
1837
server.listen(5)
1938
print(f"[LISTENING] Server is listening on {SERVER}")
2039
conn, addr = server.accept()
2140
print("Connection established with " + str(addr[0]) + ", " + str(addr[1]))
22-
23-
# email = server.recv(HEADER).decode()
41+
# email = conn.recv(HEADER).decode()
2442
# initial = email.split('@')[0]
25-
# password = server.recv(HEADER).decode()
43+
# password = conn.recv(HEADER).decode()
44+
login = False
45+
while login == False:
46+
email = conn.recv(HEADER).decode()
47+
initial = email.split('@')[0]
48+
password = conn.recv(HEADER).decode()
49+
password = hashlib.sha256(password.encode("utf-8")).hexdigest()
50+
pswd_return = password_check(email, password)
51+
print(pswd_return)
52+
if pswd_return == "Login" or pswd_return == "Signup":
53+
conn.send("Thank You!".encode())
54+
login = True
55+
break
56+
else:
57+
conn.send("Error!".encode())
58+
login = False
2659

27-
initial = "jen"
28-
60+
61+
print(email+password)
2962
user_dir = os.path.join(server_dir, initial)
3063
if os.path.isdir(user_dir):
3164
pass
@@ -137,6 +170,6 @@
137170
file.close()
138171
print("[INFO] Report file Transfer Complete.Total time: ", end_time - start_time)
139172

140-
173+
live_table.remove(email)
141174
# Closing the socket.
142175
conn.close()

server_data/SD/received.csv

Whitespace-only changes.

server_data/asdf/received.csv

Whitespace-only changes.

server_data/j/actual_pred.png

35.2 KB
Loading

server_data/j/compare_error.png

14.2 KB
Loading

server_data/j/fitting.png

28.3 KB
Loading

server_data/j/normalqq.png

45.3 KB
Loading

server_data/j/received.csv

Whitespace-only changes.

server_data/j/report.pdf

2.26 MB
Binary file not shown.

server_data/j/residual_pred.png

24.6 KB
Loading

server_data/jenish/actual_pred.png

32.7 KB
Loading

server_data/jenish/compare_error.png

16 KB
Loading

server_data/jenish/fitting.png

28.7 KB
Loading

server_data/jenish/normalqq.png

44.7 KB
Loading

server_data/jenish/received.csv

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
x,y
2+
32.502345269453031,31.70700584656992
3+
53.426804033275019,68.77759598163891
4+
61.53035802563,62.56238229794
5+
47.475639634786098,71.546632233567777
6+
59.813207869512318,87.230925133687393
7+
55.142188413943821,78.211518270799232
8+
52.211796692214001,79.64197304980874
9+
39.299566694317065,59.171489321869508
10+
48.10504169176825,75.331242297063056
11+
52.550014442733818,71.300879886850353
12+
45.419730144973755,55.165677145959123
13+
54.351634881228918,82.478846757497919
14+
44.164049496773352,62.008923245725825
15+
58.16847071685779,75.392870425994957
16+
56.727208057096611,81.43619215887864
17+
48.955888566093719,60.723602440673965
18+
44.687196231480904,82.892503731453715
19+
60.297326851333466,97.379896862166078
20+
45.618643772955828,48.847153317355072
21+
38.816817537445637,56.877213186268506
22+
66.189816606752601,83.878564664602763
23+
65.41605174513407,118.59121730252249
24+
47.48120860786787,57.251819462268969
25+
41.57564261748702,51.391744079832307
26+
51.84518690563943,75.380651665312357
27+
59.370822011089523,74.765564032151374
28+
57.31000343834809,95.455052922574737
29+
63.615561251453308,95.229366017555307
30+
46.737619407976972,79.052406169565586
31+
50.556760148547767,83.432071421323712
32+
52.223996085553047,63.358790317497878
33+
35.567830047746632,41.412885303700563
34+
42.436476944055642,76.617341280074044
35+
58.16454011019286,96.769566426108199
36+
57.504447615341789,74.084130116602523
37+
45.440530725319981,66.588144414228594
38+
61.89622268029126,77.768482417793024
39+
33.093831736163963,50.719588912312084
40+
36.436009511386871,62.124570818071781
41+
37.675654860850742,60.810246649902211
42+
44.555608383275356,52.682983366387781
43+
43.318282631865721,58.569824717692867
44+
50.073145632289034,82.905981485070512
45+
43.870612645218372,61.424709804339123
46+
62.997480747553091,115.24415280079529
47+
32.669043763467187,45.570588823376085
48+
40.166899008703702,54.084054796223612
49+
53.575077531673656,87.994452758110413
50+
33.864214971778239,52.725494375900425
51+
64.707138666121296,93.576118692658241
52+
38.119824026822805,80.166275447370964
53+
44.502538064645101,65.101711570560326
54+
40.599538384552318,65.562301260400375
55+
41.720676356341293,65.280886920822823
56+
51.088634678336796,73.434641546324301
57+
55.078095904923202,71.13972785861894
58+
41.377726534895203,79.102829683549857
59+
62.494697427269791,86.520538440347153
60+
49.203887540826003,84.742697807826218
61+
41.102685187349664,59.358850248624933
62+
41.182016105169822,61.684037524833627
63+
50.186389494880601,69.847604158249183
64+
52.378446219236217,86.098291205774103
65+
50.135485486286122,59.108839267699643
66+
33.644706006191782,69.89968164362763
67+
39.557901222906828,44.862490711164398
68+
56.130388816875467,85.498067778840223
69+
57.362052133238237,95.536686846467219
70+
60.269214393997906,70.251934419771587
71+
35.678093889410732,52.721734964774988
72+
31.588116998132829,50.392670135079896
73+
53.66093226167304,63.642398775657753
74+
46.682228649471917,72.247251068662365
75+
43.107820219102464,57.812512976181402
76+
70.34607561504933,104.25710158543822
77+
44.492855880854073,86.642020318822006
78+
57.50453330326841,91.486778000110135
79+
36.930076609191808,55.231660886212836
80+
55.805733357942742,79.550436678507609
81+
38.954769073377065,44.847124242467601
82+
56.901214702247074,80.207523139682763
83+
56.868900661384046,83.14274979204346
84+
34.33312470421609,55.723489260543914
85+
59.04974121466681,77.634182511677864
86+
57.788223993230673,99.051414841748269
87+
54.282328705967409,79.120646274680027
88+
51.088719898979143,69.588897851118475
89+
50.282836348230731,69.510503311494389
90+
44.211741752090113,73.687564318317285
91+
38.005488008060688,61.366904537240131
92+
32.940479942618296,67.170655768995118
93+
53.691639571070056,85.668203145001542
94+
68.76573426962166,114.85387123391394
95+
46.230966498310252,90.123572069967423
96+
68.319360818255362,97.919821035242848
97+
50.030174340312143,81.536990783015028
98+
49.239765342753763,72.111832469615663
99+
50.039575939875988,85.232007342325673
100+
48.149858891028863,66.224957888054632
101+
25.128484647772304,53.454394214850524

server_data/jenish/report.pdf

2.26 MB
Binary file not shown.

server_data/jenish/residual_pred.png

21.2 KB
Loading

server_data/received.csv

Whitespace-only changes.

0 commit comments

Comments
 (0)