-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
executable file
·286 lines (259 loc) · 8.8 KB
/
run.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
from datetime import datetime
import requests
from pprint import pprint
from API.newsConnection import NewsConnection
from EMAIL import emailKKNYInfo
from DATABASE.retrieve_event_for_photo_gallery import PreviousEvents
from DATABASE.renderMembers import CommitteeMembers
from DATABASE.renderEvents import Events
from AWS_S3_PHOTOS.send_image_to_bucket import Photo_Send_s3
import json
import os
import uuid
import hashlib
from AUTHENTICATION.sign_up import validate_signup
from donors.paypal_donations import retrieve_donors
from flask import Flask, url_for, render_template, request, redirect, session
from flask_login import LoginManager, UserMixin, login_user, logout_user, login_required, current_user
from flask_sqlalchemy import SQLAlchemy
application = Flask(__name__)
application.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////database/users.db'
application.config['SECRET_KEY'] = 'kkny_secrets'
application.config['MAX_CONTENT_LENGTH'] = 25 * 1024 * 1024
db = SQLAlchemy(application)
login_manager = LoginManager()
login_manager.init_app(application)
class User (UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(30), unique=True)
password= db.Column(db.String(35))
first_name = db.Column(db.String(30))
last_name = db.Column(db.String(30))
gender = db.Column(db.String(6))
@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))
"""
HTML Files are in the templates directory
homepage.html is rendered with news articles. The news articles are recieved from the newsConnection module in the API Package.
"""
@application.route("/")
def start():
session.pop('url', None)
newsConnection = NewsConnection()
return render_template('homepage.html', news_articles=newsConnection.retrieveNews())
"""
about.html is rendered.
"""
@application.route("/about")
def renderAboutUs():
committeeMembers = CommitteeMembers()
previous_committee = committeeMembers.retrievePreviousCommittee()
return render_template('about.html', previous_committee=previous_committee);
"""
This method retrieves all members in our MongoDB Database. The module renderMembers in the DATABASE package retrieves all members in our different committees. These different committees are different collections in our MongoDB database.
"""
@application.route("/members")
def renderAllMembers():
committeeMembers = CommitteeMembers()
executive_committee = committeeMembers.retrieveExecutiveCommittee()
contacts = committeeMembers.retrieveContactsList()
cultural_committee = committeeMembers.retrieveCulturalCommittee()
youth_committee = committeeMembers.retrieveYouthCommittee()
food_committee = committeeMembers.retrieveFoodCommittee()
fundraising_committee = committeeMembers.retrieveFundraisingCommittee()
sound_music_committee = committeeMembers.retrieveSoundMusicCommittee()
decorations_committee = committeeMembers.retrieveDecorationsCommittee()
sports_committee = committeeMembers.retrieveSportsCommittee()
return render_template("members.html", contacts=contacts, executive_committee=executive_committee, cultural_committee=cultural_committee, youth_committee=youth_committee, food_committee=food_committee,
fundraising_committee=fundraising_committee, sound_music_committee=sound_music_committee, decorations_committee=decorations_committee, sports_committee=sports_committee)
@application.route('/local_heroes')
def render_local_heros():
volunteer_group_one = [
'Kavya (Coordinator)',
'Keshav (Coordinator)',
'Radhika',
'Ravi',
'Geetha',
'Savitha Navada',
'Gopal Navada',
'Yeshoda',
'Prakash Bhat',
'Pranav Bhat',
'Pushpalatha Bhat',
'Danika',
'Vittal',
'',
'',
'',
'',
'',
'',
''
]
volunteer_group_two = [
'Nagini (Coordinator)',
'Uma Sharath (Coordinator)',
'Ravindra',
'Aditya',
'Sonika',
'Sharath Kengeri',
'Pragna',
'Gopal',
'Achala',
'Purushotam',
'Swaroop Kumble',
'Hamsini Kumble',
'Ojas',
'Arun Kumar',
'Geetha Kumar',
'Ankith kumar',
'Hrishikesh Deshpande',
'Vasumathi',
'',
'',
''
]
volunteer_group_three = [
'Ajit Ganesh (Co-ordinator)',
'Shilpa (Co-ordinator)',
'Ajith Shetty',
'Mahesh',
'Ram',
'Jyothi Babureddy',
'Babu Reddy',
'Veena',
'Subha',
'Anand',
'Chaitra',
'Sreeranjini',
'Arya',
'Ansh',
'Shivkumar',
'Ravindra Kudur',
'Narsi Motagan',
'Anitha',
'Ram Marakula',
'Sudha Marakula'
]
volunteer_group_four = [
'Triveni (Coordinator)',
'Raviteja (Coordinator)',
'Badari Ambati (Coordinator)',
'Shreya Ambati',
'Vinaya',
'Aiysha',
'Ankush',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
''
]
return render_template('local_heroes.html', volunteers=zip(volunteer_group_one, volunteer_group_two, volunteer_group_three, volunteer_group_four))
@application.route("/presidents_message")
def renderPresidentsMessage():
session.pop('url', None)
return render_template('presidents_message.html')
@application.route("/sendSuggestionToSuggestionsBox", methods=['POST'])
def sendEmail():
suggestion = request.get_json()
emailKKNYInfo.email_kkny_account(suggestion)
session.pop('url', None)
return "success"
@application.route("/contact_us", methods=['GET'])
def contact_us():
session.pop('url', None)
return render_template('contact_us_page.html')
@application.route("/upload_pics_page")
def upload_pic_page():
if current_user.is_authenticated:
previous_events = PreviousEvents()
events = previous_events.retrieve_all_event_info()
session.pop('url', None)
return render_template("upload_pictures.html", events=events)
else:
session['url'] = '/upload_pics_page'
print("session set")
return redirect(url_for("login_page"))
@application.route("/upload_pics/<string:event_name>", methods=['POST'])
@login_required
def upload_pics(event_name):
previous_events = PreviousEvents()
event_info = previous_events.retrieve_event_info(event_name=event_name)
upload_to_s3 = Photo_Send_s3()
list_of_files = request.files.getlist("file[]")
return json.dumps(upload_to_s3.send_photo_to_s3(list_of_files, {'email': current_user.email}, event_info))
@application.errorhandler(413)
def request_entity_too_large(error):
return json.dumps({"message": "Please try to restrict the total size of all images to be less than 25 MB"}), 413, {'ContentType': 'application/json'}
@application.route("/login_page")
def login_page():
return render_template("login.html")
@application.route("/login", methods=['POST'])
def login():
user_info = request.get_json()
email = user_info["email"]
password = user_info["password"]
user = User.query.filter_by(email=email).first()
if not user:
return json.dumps({"user_exists": False})
hashed_password, salt = user.password.split(":")
if hashed_password == hashlib.sha256(salt.encode() + password.encode()).hexdigest():
if 'url' in session:
login_user(user)
return json.dumps({"user_exists": True, "redirect_to": session['url']})
login_user(user)
return json.dumps({"user_exists": True})
@application.route("/logout")
@login_required
def logout():
logout_user()
return redirect(url_for("start"))
@application.route("/sign_up_page")
def signup_page():
return render_template("sign_up.html")
@application.route("/sign_up", methods=['POST'])
def signup():
sign_up_info = request.get_json()
validate_signup(sign_up_info)
first_name = sign_up_info["first_name"]
last_name = sign_up_info["last_name"]
gender = sign_up_info["gender"]
email = sign_up_info["email"]
password = sign_up_info["password"]
repeat_password = sign_up_info["repeat_password"]
salt = uuid.uuid4().hex
hashed_password = hashlib.sha256(salt.encode() + password.encode()).hexdigest() + ":" + salt
user = User(email=email, password=hashed_password, first_name=first_name, last_name=last_name, gender=gender)
db.session.add(user)
db.session.commit()
login_user(user)
return json.dumps({"user_signed_up": True})
@application.route('/zoom_events', methods=['GET'])
def render_zoom_events():
return render_template('zoom_events.html')
@application.route("/donate", methods=['GET'])
def donate():
donors = retrieve_donors()
return render_template('donate.html', donors=donors)
@application.route("/photo_gallery")
def render_all_photo_events():
if current_user.is_authenticated:
previous_events = PreviousEvents()
all_previous_events = previous_events.retrieve_all_event_info()
session.pop('url', None)
return render_template('photo_gallery_events.html', previous_events=all_previous_events)
else:
session['url'] = '/photo_gallery'
return redirect(url_for("login_page"))
if __name__ == "__main__":
application.run(host='0.0.0.0')