-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
504 lines (376 loc) · 14.9 KB
/
main.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
from flask import Flask, render_template, request, redirect, url_for, session, flash
app = Flask('app')
app.secret_key = 'secretKey'
# Main menu
def main():
while True:
print("Welcome to inCollege")
print("Please select an option from the menu below")
print("1. Login")
print("2. Sign up")
print("3. Connect with your friends")
print("4. College Student Success Story")
print("5. Exit")
userChoice = input("Enter your choice: ")
if userChoice == "1":
return redirect(url_for('login'))
elif userChoice == "2":
return redirect(url_for('general->SignUp->login'))
elif userChoice == "3":
return redirect(url_for('connect'))
elif userChoice == "4":
return "Thank you for using inCollege. Goodbye"
else:
print("Invalid input, please try again")
# Global dictionary to hold username, passwords, first name, and last name
accounts = {}
# Global dictionary to hold job postings
job_postings = {}
# Global dictionary to hold profile info
profiles = {}
# functions for the homePage
friend_requests = {}
friends = {}
MAX_ACCOUNTS = 10
# Useful Links
@app.route('/')
def index():
story = "College Student Success Story: Stacy, a recent college graduate, used InCollege to network with professionals in her field. She utilized the platform's job search feature and found a position at a company. Now, she's thriving in her career thanks to the connections she made on InCollege."
return render_template('homePage.html', success_story=story)
@app.route('/general') # the name of the page in the url
def general(): # name of the redirection that you are using in the html page
return render_template('homePage->general.html') # address of the html page
@app.route('/browseInCollege')
def browse():
return "Under Construction"
@app.route('/businessSolutions')
def businessSolutions():
return "Under Construction"
@app.route('/directories')
def directories():
return "Under Construction"
#Incollege Important Links
@app.route('/copyrightNotice')
def copyrightNotice():
return "Your personal information is protected and will never be shared with third parties without your consent. We employ industry-standard security measures to safeguard your data. Feel free to reach out to us if you have any concerns about your privacy or data usage at [email protected]."
@app.route('/about2')
def about2():
return "Under Construction"
@app.route('/accessibility')
def accessibility():
return "Under Construction"
@app.route('/agreement')
def agreement():
return "Under Construction"
@app.route('/important->privacyPolicy->guestControls', methods=['GET', 'POST'])
def privacyPolicy():
preferences = {
'Email': True,
'SMS': True,
'Advertising': True,
'Language': 'English'
}
if request.method == 'POST':
# Update preferences based on user input
if 'email' in request.form:
preferences['Email'] = False
if 'sms' in request.form:
preferences['SMS'] = False
if 'advertising' in request.form:
preferences['Advertising'] = False
if 'language' in request.form:
preferences['Language'] = request.form['language']
return render_template('privacyPolicyNewAttempt.html',
preferences=preferences)
@app.route('/cookies')
def cookies():
return "Under Construction"
@app.route('/copyrightPolicy')
def copyrightPolicy():
return "Under Construction"
@app.route('/brand')
def brand():
return "Under Construction"
# functions for the homePage->general page
@app.route('/sign_in_processing')
def sign_in_processing():
return render_template('general->SignUp.html')
@app.route('/help_center')
def help():
return "We’re here to help"
@app.route('/about')
def about():
return "In College: Welcome to In College, the world's largest college student network with many users in many countries and territories worldwide"
@app.route('/press')
def press():
return "In College Pressroom: Stay on top of the latest news, updates, and reports"
@app.route('/blog')
def blog():
return "Under Construction"
@app.route('/careers')
def careers():
return "Under Construction"
@app.route('/developers')
def developers():
return "Under Construction"
@app.route('/general->SignUp->login', methods=['GET', 'POST'])
def login():
error_message = None
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
if username in accounts and accounts[username]['password'] == password:
session['username'] = username
return redirect(url_for('post_menu', username=username))
else:
error_message = "Invalid username or password. Please try again."
return render_template('general->SignUp->login.html',
error_message=error_message)
@app.route('/general->SignUp->login->post_menu/<username>',
methods=['GET', 'POST'])
def post_menu(username):
return render_template('general->SignUp->login->post_menu.html',
username=username)
@app.route('/job_search', methods=['GET', 'POST'])
def job_search():
if request.method == 'POST':
username = request.form.get('username')
if username in accounts:
if len(job_postings.get(username, [])) >= 10:
return "You have reached the maximum number of job postings (10)."
title = request.form['title']
description = request.form['description']
employer = request.form['employer']
location = request.form['location']
salary = request.form['salary']
job_postings.setdefault(username, []).append({
'title':
title,
'description':
description,
'employer':
employer,
'location':
location,
'salary':
salary,
'posted_by':
accounts[username]['first_name'] + ' ' +
accounts[username]['last_name']
})
return redirect(url_for('job_search'))
else:
return render_template('jobSearch.html', job_postings=job_postings)
@app.route('/delete_job', methods=['GET', 'POST'])
def delete_job():
username = session.get('username')
if not username:
return redirect(url_for('login'))
if request.method == 'POST':
job_title = request.form.get('job_title')
# remove job from job_postings
if job_title and username in job_postings:
job_postings[username] = [
job for job in job_postings[username] if job['title'] != job_title
]
return redirect(url_for('post_menu', username=username))
# show the job if its a get request
jobs = job_postings.get(username, [])
return render_template('delete_job.html', jobs=jobs)
@app.route('/find_contacts')
def find_contacts():
return redirect(url_for('connect'))
@app.route('/general->SignUp->login->post_menu->skills/<username>',
methods=['GET', 'POST'])
def skills(username):
if request.method == 'POST':
skill = request.form.get('skill')
if skill:
return f"You have selected {skill}. Under construction"
else:
error_message = "Please select a skill."
return render_template('learningNewSkills.html',
username=username,
error_message=error_message)
return render_template('learningNewSkills.html', username=username)
@app.route('/logout')
def logout():
return "logout"
@app.route('/general->SignUp->SignUp', methods=['GET', 'POST'])
def signup():
error_message = None
success_message = None
if len(accounts) >= 10:
return "Sorry, the maximum number of accounts has been reached."
if request.method == 'POST':
username = request.form['username']
if username in accounts:
error_message = "This username is already taken. Please try again."
else:
password = request.form['password']
password_check = check_password(password)
if password_check is not True:
error_message = password_check
else:
first_name = request.form['first_name']
last_name = request.form['last_name']
accounts[username] = {
'password': password,
'first_name': first_name,
'last_name': last_name
}
success_message = "Account created successfully!"
return render_template('general->SignUp->SignUp.html',
error_message=error_message,
success_message=success_message)
def check_password(password):
# Check if password is at least 8 characters long
if not 8 <= len(password) <= 12:
return "Password must be between 8 and 12 characters long. Please try again"
# Check if password has at least one uppercase letter, one digit, and a special character
if not any(char.isupper() for char in password):
return "Password must contain at least one uppercase letter. Please try again"
if not any(char.isdigit() for char in password):
return "Password must contain at least one digit. Please try again"
if not any(char in "!@#$%^&*()_+-=[]{}|;:,./<>?\\" for char in password):
return "Password must contain at least one special character. Please try again"
return True
@app.route('/general->SignUp->Connect', methods=['GET', 'POST'])
def connect():
connection_result = None
if request.method == 'POST':
first_name = request.form['first_name']
last_name = request.form['last_name']
if any(account['first_name'] == first_name
and account['last_name'] == last_name
for account in accounts.values()):
connection_result = "They are a part of the InCollege system. You can sign up or log in to join."
else:
return "They are not yet a part of the InCollege system."
return render_template('general->SignUp->Connect.html',
connection_result=connection_result)
@app.route('/success_story')
def success_story():
return "College Student Success Story: Stacy, a recent college graduate, used InCollege to network with professionals in her field. She utilized the platform's job search feature and found a position at a company. Now, she's thriving in her career thanks to the connections she made on InCollege."
@app.route('/update_profile', methods=['GET', 'POST'])
def update_profile():
username = session.get('username')
if not username:
return redirect(url_for('login'))
if request.method == 'POST':
# handle form submission for post request
title = request.form.get('title', '')
major = request.form.get('major', '')
university = request.form.get('university', '')
info = request.form.get('info', '')
experience = request.form.get('experience', '').split('\n')
education = request.form.get('education', '').split('\n')
# save the profile information
profiles[username] = {
'title': title,
'major': major,
'university': university,
'info': info,
'experience': experience,
'education': education
}
# Redirect to the profile page for the submitted username
return redirect(url_for('profile_view', username=username))
# if it's a get request, render the form to update the profiles
# get the existing profile information if it exist
profile = profiles.get(username, {})
return render_template('update_profile.html', profile=profile)
@app.route('/search_profile/', methods=['GET', 'POST'])
def search_profile():
if request.method == 'POST':
username = request.form.get('username')
if username in profiles:
return redirect(url_for('profile_view', username=username))
else:
return "Profile not found. Please try again."
# handle get request
return render_template('search_profile.html')
@app.route('/profile/<username>')
def profile_view(username):
# get profile information based on the username
profile = profiles.get(username)
# handle case where profile is not found
if profile is None:
return "Profile not found"
return render_template('profile_view.html', profile=profile)
@app.route('/search_students', methods=['GET', 'POST'])
def search_students():
if request.method == 'POST':
last_name = request.form['last_name']
university = request.form['university']
major = request.form['major']
results = []
for username, profile in profiles.items():
if (last_name == '' or accounts[username]['last_name'] == last_name) and \
(university == '' or profile['university'] == university) and \
(major == '' or profile['major'] == major):
results.append({
'username':
username,
'name':
accounts[username]['first_name'] + ' ' +
accounts[username]['last_name']
})
return render_template('search_results.html', results=results)
return render_template('search_students.html')
@app.route('/friend_requests', methods=['GET', 'POST'])
def show_friend_requests():
username = session.get('username')
if not username:
return redirect(url_for('login'))
pending_requests = friend_requests.get(username, [])
return render_template('friend_requests.html', requests=pending_requests)
@app.route('/send_friend_request/<recipient>', methods=['POST'])
def send_friend_request(recipient):
sender = session.get('username')
if not sender:
flash("You must be logged in to send friend requests.", "warning")
return redirect(url_for('login'))
if recipient not in accounts:
flash("Recipient not found.", "error")
return redirect(request.referrer)
if recipient in friend_requests.get(sender, []):
flash("Friend request already sent.", "info") #will give notif
return redirect(request.referrer)
friend_requests.setdefault(recipient, []).append(sender)
flash("Friend request sent successfully.", "success")
return redirect(request.referrer)
@app.route('/accept_friend_request/<sender>', methods=['GET', 'POST'])
def accept_friend_request(sender):
username = session.get('username')
if not username:
return redirect(url_for('login'))
if sender in friend_requests.get(username, []):
# Accept friend request
friends.setdefault(username, []).append(sender)
friends.setdefault(sender, []).append(username)
# Remove friend request
friend_requests[username].remove(sender)
return "Friend request accepted successfully."
else:
return "No pending friend request from this user."
@app.route('/my_network', methods=['GET', 'POST'])
def show_network():
username = session.get('username')
if not username:
return redirect(url_for('login'))
user_network = friends.get(username, [])
return render_template('my_network.html', network=user_network)
@app.route('/disconnect/<friend>')
def disconnect(friend):
username = session.get('username')
if not username:
return redirect(url_for('login'))
if friend in friends.get(username, []):
friends[username].remove(friend)
friends[friend].remove(username)
return f"You are no longer connected with {friend}."
else:
return f"{friend} is not in your network."
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0', port=8080)