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

Lines changed: 43 additions & 41 deletions
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

Lines changed: 40 additions & 7 deletions
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

0 commit comments

Comments
 (0)