-
Notifications
You must be signed in to change notification settings - Fork 1
/
signup.py
235 lines (199 loc) · 8.08 KB
/
signup.py
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
from tkinter import *
from ldap_server import LdapServer
import time
import admin_pwd as admin_pwd
import colors
from PIL import ImageTk, Image
import re
from certificate_authority.ca_client import CaClient, handle_cert_local
from dotenv.main import load_dotenv
import os
load_dotenv()
CA_CLIENT_PATH = os.environ["CA_CLIENT_CERT_DIR"]
class Signup:
def __init__(self, base=None):
self.base = base
def check(self):
if re.match("[^@]+@[^@]+\.[^@]+", self.EMAIL.get()):
return True
else:
return False
def Register(self, event=None):
self.error_label.place(relx=0.65, y=385, anchor=CENTER)
if (
self.USERNAME.get() == ""
or self.PASSWORD.get() == ""
or self.EMAIL.get() == ""
or self.UID.get() == ""
):
self.error_label.config(
text="Please fill out all fields !!!", fg=colors.error, bg="#ff9966"
)
else:
if not self.check():
self.error_label.config(
text="Invalid Email !!!", fg=colors.error, bg="#ff9966"
)
else:
# user object
user_obj = {
"username": self.USERNAME.get(),
"password": self.PASSWORD.get(),
"email": self.EMAIL.get(),
"firstname": self.FIRSTNAME.get(),
"lastname": self.LASTNAME.get(),
"group_id": 5000,
"uid": self.UID.get(), # student id
}
ldap_s = LdapServer(admin_pwd.LDAP_ADMIN_PWD)
result = ldap_s.register(user_obj)
if not result:
client = CaClient(self.USERNAME)
client.connect()
client.request_cert()
result = handle_cert_local(
CA_CLIENT_PATH + self.USERNAME.get() + "_cert.pem"
)
self.loginPage()
self.error_label.config(
text="Sucess", fg=colors.success, bg=colors.success_bg
)
else:
self.error_label.config(
text=result, fg=colors.error, bg=colors.error_bg
)
def loginPage(self):
self.root.withdraw()
self.root.destroy()
from login import LoginPage
login = LoginPage()
# self.root.destroy()
login.main()
def main(self):
# main frame
self.root = Toplevel(self.base)
self.root.geometry("700x400")
self.root.title("Signup Form")
self.root.config(bg=colors.login_bg)
self.USERNAME = StringVar(self.root)
self.EMAIL = StringVar(self.root)
self.PASSWORD = StringVar(self.root)
self.GENDER = StringVar(self.root)
self.UID = StringVar(self.root)
self.FIRSTNAME = StringVar(self.root)
self.LASTNAME = StringVar(self.root)
# backround image
self.img = Image.open("./assets/bg2.jpg").resize((700, 400))
self.bg = ImageTk.PhotoImage(self.img)
label = Label(self.root, image=self.bg)
label.place(x=0, y=0)
label.pack(fill=BOTH, expand=YES)
# Page Title
label_title = Label(self.root, text="WeChat", width=40, font=("bold", 30))
label_title.place(relx=0.5, y=20, anchor=CENTER)
label_title.config(bg=colors.blue_light, fg=colors.blue_dark)
# Registration form
label_signup = Label(self.root, text="SIGNUP", font=("bold", 20))
label_signup.place(relx=0.22, y=100, anchor=CENTER)
label_signup.config(bg=colors.blue_light, fg=colors.blue_2)
# self.FirstName label & entry
label_firstname = Label(
self.root, width=10, text="Firstname :", font=("bold", 13)
)
label_firstname.place(relx=0.5, y=100, anchor=CENTER)
label_firstname.config(bg=colors.blue_light, fg=colors.blue_dark)
input_firstname = Entry(self.root, textvariable=self.FIRSTNAME)
input_firstname.place(relx=0.72, y=100, anchor=CENTER)
input_firstname.config(
bg=colors.input_bg, fg=colors.blue_dark, insertbackground=colors.input_bg
)
# LastName label & entry
label_lastname = Label(
self.root, width=10, text="Lastname :", font=("bold", 13)
)
label_lastname.place(relx=0.5, y=140, anchor=CENTER)
label_lastname.config(bg=colors.blue_light, fg=colors.blue_dark)
input_lastname = Entry(self.root, textvariable=self.LASTNAME)
input_lastname.place(relx=0.72, y=140, anchor=CENTER)
input_lastname.config(
bg=colors.input_bg, fg=colors.blue_dark, insertbackground=colors.input_bg
)
# UserName label & entry
label_username = Label(
self.root, width=10, text="Username :", font=("bold", 13)
)
label_username.place(relx=0.5, y=180, anchor=CENTER)
label_username.config(bg=colors.blue_light, fg=colors.blue_dark)
input_username = Entry(self.root, textvariable=self.USERNAME)
input_username.place(relx=0.72, y=180, anchor=CENTER)
input_username.config(
bg=colors.input_bg, fg=colors.blue_dark, insertbackground=colors.input_bg
)
# self.EMAIL label & entry
label_email = Label(self.root, width=10, text="Email :", font=("bold", 13))
label_email.place(relx=0.5, y=220, anchor=CENTER)
label_email.config(bg=colors.blue_light, fg=colors.blue_dark)
input_email = Entry(self.root, textvariable=self.EMAIL)
input_email.place(relx=0.72, y=220, anchor=CENTER)
input_email.config(
bg=colors.input_bg, fg=colors.blue_dark, insertbackground=colors.input_bg
)
# self.PASSWORD label & entry
label_passwd = Label(self.root, width=10, text="Password :", font=("bold", 13))
label_passwd.place(relx=0.5, y=260, anchor=CENTER)
label_passwd.config(bg=colors.blue_light, fg=colors.blue_dark)
input_passwd = Entry(self.root, textvariable=self.PASSWORD, show="*")
input_passwd.place(relx=0.72, y=260, anchor=CENTER)
input_passwd.config(
bg=colors.input_bg, fg=colors.blue_dark, insertbackground=colors.input_bg
)
# Student Id label & entry
label_StudentId = Label(
self.root, width=10, text="Student Id :", font=("bold", 13)
)
label_StudentId.place(relx=0.5, y=300, anchor=CENTER)
label_StudentId.config(bg=colors.blue_light, fg=colors.blue_dark)
input_StudentId = Entry(self.root, textvariable=self.UID)
input_StudentId.place(relx=0.72, y=300, anchor=CENTER)
input_StudentId.config(
bg=colors.input_bg, fg=colors.blue_dark, insertbackground=colors.input_bg
)
# Error label
self.error_label = Label(self.root, width=30, font=("bold", 12))
self.error_label.place(relx=0.65, y=440, anchor=CENTER)
self.error_label.config(bg=colors.blue_light)
# Submit button
btn = Button(
self.root,
text="Submit",
width=10,
bg=colors.blue_dark,
fg=colors.blue_dark,
command=self.Register,
)
btn.place(relx=0.5, y=340, anchor=CENTER)
btn.bind("<Return>", self.Register)
btn.config(
bg="#35a666",
fg="#FFFFFF",
activebackground="#0AAE2F",
activeforeground=colors.blue_dark,
)
# Submit button
btnlogin = Button(
self.root,
text="Login",
width=10,
bg=colors.blue_dark,
fg=colors.blue_dark,
command=self.loginPage,
)
btnlogin.place(relx=0.7, y=340, anchor=CENTER)
btnlogin.bind("<Return>", self.loginPage)
btnlogin.config(
bg=colors.blue_dark,
fg="#FFFFFF",
activebackground=colors.blue_light,
activeforeground=colors.blue_dark,
)
self.root.mainloop()