-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathlogin.py
More file actions
143 lines (128 loc) · 5.02 KB
/
login.py
File metadata and controls
143 lines (128 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import psycopg2
import os
from getpass import getpass
from DB_config import config
import datetime
def DB_pass(username, category):
with psycopg2.connect(**config()) as find_pass:
cur1 = find_pass.cursor()
cur1.execute(f"""
SELECT password FROM {category} WHERE username = '{username.lower()}';
""")
rows = cur1.fetchall()
cur1.close()
find_pass.close()
return rows[0][0]
def login(category, username, password):
logged_in = False
if password == DB_pass(username,category):
logged_in = True
return logged_in
def signup(category, *args):
if category == "admin":
username, fullname, email, date_of_birth, password = args
date_of_birth = datetime.datetime.strptime(date_of_birth,"%Y-%m-%d")
notifications = "Logged in"
with psycopg2.connect(**config()) as default_admin:
cur0 = default_admin.cursor()
cur0.execute("""
INSERT INTO admin (
username,
fullname,
email,
date_of_birth,
password,
notifications
)
VALUES (
%s, %s, %s, DATE %s, %s, %s
) ON CONFLICT(username) DO NOTHING;
""", (username, fullname, email, date_of_birth, password, notifications))
elif category == "doctor":
username, fullname, email, date_of_birth, password, specialty, price = args
date_of_birth = datetime.datetime.strptime(date_of_birth.strip(),"%Y-%m-%d")
notifications = "Logged in"
with psycopg2.connect(**config()) as doctor_signup:
cur1 = doctor_signup.cursor()
cur1.execute("""
INSERT INTO doctor (
username,
fullname,
email,
date_of_birth,
password,
specialty,
price,
notifications
)
VALUES (
%s, %s, %s, DATE %s, %s, %s, %s, %s
) ON CONFLICT(username) DO NOTHING;
""", (username, fullname, email, date_of_birth, password, specialty, price, notifications))
print(cur1.statusmessage)
print("Successfully Signed Up")
cur1.close()
doctor_signup.commit()
doctor_signup.close()
elif category == "patient":
username, fullname, email, date_of_birth, password, problem = args
date_of_birth = datetime.datetime.strptime(date_of_birth.strip(),"%Y-%m-%d")
reports = "(initial_registration++This_frontend_url_will_be_generated_automatically)"
notifications = "Logged in"
requested_doctor_username = None
appointment_timestamp = None
approved_doctor_username = "hpt"
with psycopg2.connect(**config()) as patient_signup:
cur1 = patient_signup.cursor()
cur1.execute("""
INSERT INTO patient (
username,
fullname,
email,
date_of_birth,
password,
problem,
requested_doctor_username,
approved_doctor_username,
appointment_timestamp,
reports,
notifications
)
VALUES (
%s, %s, %s, DATE %s, %s, %s, %s, %s, %s, %s, %s
) ON CONFLICT(username) DO NOTHING;
""", (username, fullname, email, date_of_birth, password, problem, requested_doctor_username, approved_doctor_username, appointment_timestamp, reports, notifications))
print(cur1.statusmessage)
print("Successfully Signed Up")
cur1.close()
patient_signup.commit()
patient_signup.close()
else:
username, fullname, email, date_of_birth, password, work, salary = args
date_of_birth = datetime.datetime.strptime(date_of_birth.strip(),"%Y-%m-%d")
work_of_doctors = "hpt"
notifications = "Logged in"
with psycopg2.connect(**config()) as employee_signup:
cur1 = employee_signup.cursor()
cur1.execute("""
INSERT INTO employee (
username,
fullname,
email,
date_of_birth,
password,
work,
work_of_doctors,
salary,
notifications
)
VALUES (
%s, %s, %s, DATE %s, %s, %s, %s, %s, %s
);
""", (username, fullname, email, date_of_birth, password, work, work_of_doctors, salary, notifications))
print(cur1.statusmessage)
print("Successfully Signed Up")
cur1.close()
employee_signup.commit()
employee_signup.close()
return True