-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
443 lines (388 loc) · 17.6 KB
/
app.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
from message.getMessage import getmessages
from BlinkskyAPI.sendReward import SendReward
from users.Rewards import GetRewardDetails
from projects.rate_task import rateProject
from message.sendMessage import sendmessage
from projects.submitIdea import submit_idea
from projects.submitTask import submit_task
from users.GetEmployeeFromCompany import CompanyEmployees
from projects.idea_submission_details import business_idea
from projects.task_submission_details import submission_details
from projects.add_task import Create_task
from projects.projectDetails import project_details
from flask import Flask, render_template, request, redirect, session
from Authorization.registeration import register_user
from Authorization.login import employee_login
from Authorization.resetPassword import reset_password
from FirebaseCredentials.Firebase import auth,db
from projects.addProject import CreateProject
app = Flask(__name__)
app.secret_key="thisisblinkathonhackathon"
@app.route("/")
def Landing():
return render_template("landing.html")
@app.route("/dashboard")
def index():
try:
session['usr']
all_users = db.child("Users").get()
for user in all_users.each():
employee_id=user.key()
path="Users/"+employee_id+"/session/session_id"
customer_session=db.child(path).get().val()
if (customer_session==session['usr']) :
user_name=db.child("Users").child(employee_id).child("profile/name").get().val()
user_status=db.child("Users").child(employee_id).child("profile/status").get().val()
user_id=employee_id
if (user_status=="admin"):
if db.child("Users").child(user_id).child("messages").get().val() is not None:
msgss=getmessages(user_id)
return render_template("index.html", name = user_name,msgss=msgss,msg=True)
else:
return render_template("index.html", name = user_name)
else :
return render_template("index_member.html", name=user_name)
except KeyError:
return redirect("/login")
@app.route("/registeration",methods=["GET","POST"])
def registeration():
if request.method=="POST":
email=request.form["email"]
password=request.form["password"]
employeeCode=request.form["employee_code"]
mobile=request.form["mobile"]
employee_company=request.form["employee_company"]
employee_name=request.form["employee_name"]
admin=request.form["admin"]
print(admin)
register_user(email,password,employeeCode,mobile,employee_company,employee_name,admin)
return redirect("/dashboard")
return render_template("Registeration.html")
@app.route("/login",methods=["GET","POST"])
def login():
if request.method=="POST":
try:
email=request.form["email"]
password=request.form["password"]
employee_login(email,password)
user=auth.sign_in_with_email_and_password(email,password)
user = auth.refresh(user['refreshToken'])
user_id = user['idToken']
session['usr'] = user_id
all_users = db.child("Users").get()
for user in all_users.each():
employee_id=user.key()
path="Users/"+employee_id+"/profile/email"
user_email=db.child(path).get().val()
if (user_email==email) :
db.child("Users").child(employee_id).child("session").update({"session_id":session['usr']})
return redirect("/dashboard")
except:
err_msg="Wrong Credentials!"
return render_template("Login.html",sweetalert=True,err_msg=err_msg)
return render_template("Login.html")
@app.route("/forgot-password",methods=["GET","POST"])
def forgot_password():
if request.method=="POST":
try:
email=request.form["email"]
reset_password(email)
except:
err_msg="Email was not found linked with any user"
return render_template("forgot-password.html", sweetalert=True, err_msg=err_msg)
return render_template("forgot-password.html")
@app.route("/add-project",methods=["GET","POST"])
def add_project():
try:
session['usr']
all_users = db.child("Users").get()
for user in all_users.each():
employee_id=user.key()
path="Users/"+employee_id+"/session/session_id"
customer_session=db.child(path).get().val()
if (customer_session==session['usr']) :
user_name=db.child("Users").child(employee_id).child("profile/name").get().val()
user_company=db.child("Users").child(employee_id).child("profile/company").get().val()
user_id=employee_id
employees=CompanyEmployees(user_company)
if request.method=="POST":
project_name=request.form["project_name"]
project_id=request.form["project_id"]
project_members=request.form["members"]
project_description=request.form["project_description"]
CreateProject(project_name,project_id,project_members,project_description,user_id)
return render_template("add_project.html", name = user_name,employees=employees)
except KeyError:
return redirect("/login")
@app.route("/add-task",methods=["GET","POST"])
def add_task():
try:
session['usr']
all_users = db.child("Users").get()
for user in all_users.each():
employee_id=user.key()
path="Users/"+employee_id+"/session/session_id"
customer_session=db.child(path).get().val()
if (customer_session==session['usr']) :
user_name=db.child("Users").child(employee_id).child("profile/name").get().val()
user_id=employee_id
if request.method=="POST":
task_name=request.form["task_name"]
task_id=request.form["task_id"]
task_project_id=request.form["task_project_id"]
task_description=request.form["task_description"]
Create_task(task_name,task_id,task_project_id,task_description,user_id)
return render_template("add_task.html", name = user_name)
except KeyError:
return redirect("/login")
@app.route("/projects")
def projects():
try:
session['usr']
all_users = db.child("Users").get()
for user in all_users.each():
employee_id=user.key()
path="Users/"+employee_id+"/session/session_id"
customer_session=db.child(path).get().val()
if (customer_session==session['usr']) :
user_name=db.child("Users").child(employee_id).child("profile/name").get().val()
user_id=employee_id
if db.child("Users/"+user_id+"/Projects").get().val() is not None:
projects_info=project_details(user_id)
return render_template("projects.html",name=user_name,projects=projects_info)
else:
return render_template("projects.html",name=user_name,message="No Running Projects were found")
except KeyError:
return redirect("/login")
@app.route("/check-idea")
def check_idea():
return render_template("check_idea.html")
@app.route("/idea_submissions")
def idea_submissions():
try:
session['usr']
all_users = db.child("Users").get()
for user in all_users.each():
employee_id=user.key()
path="Users/"+employee_id+"/session/session_id"
customer_session=db.child(path).get().val()
if (customer_session==session['usr']) :
user_name=db.child("Users").child(employee_id).child("profile/name").get().val()
user_id=employee_id
if db.child("Users/"+user_id+"/ideaSubmission").get().val() is not None:
idea_details=business_idea(user_id)
return render_template("idea_submissions.html",name=user_name,ideas=idea_details)
else:
return render_template("idea_submissions.html",name=user_name,message="No Business Ideas Found")
except KeyError:
return redirect("/login")
@app.route("/submissions")
def submissions():
try:
session['usr']
all_users = db.child("Users").get()
for user in all_users.each():
employee_id=user.key()
path="Users/"+employee_id+"/session/session_id"
customer_session=db.child(path).get().val()
if (customer_session==session['usr']) :
user_name=db.child("Users").child(employee_id).child("profile/name").get().val()
user_id=employee_id
if db.child("Users/"+user_id+"/task_submissions").get().val() is not None:
task_details=submission_details(user_id)
return render_template("submissions.html",name=user_name,tasks=task_details)
else:
return render_template("submissions.html",message="No Submissions Found")
except KeyError:
return redirect("/login")
@app.route("/reward-history")
def reward_history():
try:
session['usr']
all_users = db.child("Users").get()
for user in all_users.each():
employee_id=user.key()
path="Users/"+employee_id+"/session/session_id"
customer_session=db.child(path).get().val()
if (customer_session==session['usr']) :
user_name=db.child("Users").child(employee_id).child("profile/name").get().val()
user_id=employee_id
if db.child("Users/"+user_id+"/rewards").get().val() is not None:
reward=GetRewardDetails(user_id)
return render_template("history.html",name=user_name,rewards=reward)
else:
return render_template("history.html",name=user_name,message="No Gift Cards has been issued")
except KeyError:
return redirect("/login")
@app.route("/rate-submissions",methods=["GET","POST"])
def rate_submissions():
try:
session['usr']
all_users = db.child("Users").get()
for user in all_users.each():
employee_id=user.key()
path="Users/"+employee_id+"/session/session_id"
customer_session=db.child(path).get().val()
if (customer_session==session['usr']) :
user_name=db.child("Users").child(employee_id).child("profile/name").get().val()
user_id=employee_id
if request.method=="POST":
rating=request.form["rating"]
emp_id=request.form["employee_id"]
task_id=request.form["task_id"]
rateProject(rating,emp_id,task_id,user_id)
return redirect("/submissions")
return render_template("rate_project.html",name=user_name)
except KeyError:
return redirect("/login")
@app.route("/give-reward",methods=["GET","POST"])
def give_reward():
try:
session['usr']
all_users = db.child("Users").get()
for user in all_users.each():
employee_id=user.key()
path="Users/"+employee_id+"/session/session_id"
customer_session=db.child(path).get().val()
if (customer_session==session['usr']) :
user_name=db.child("Users").child(employee_id).child("profile/name").get().val()
user_id=employee_id
adminPhone=db.child("Users").child(user_id).child("profile/mobile").get().val()
company=db.child("Users").child(user_id).child("profile/company").get().val()
if request.method=="POST":
emp_id=request.form["employee_id"]
emp_phone=db.child("Users").child(emp_id).child("profile/mobile").get().val()
emp_name=db.child("Users").child(emp_id).child("profile/name").get().val()
gift_card_value=request.form["reward_value"]
link=SendReward(company,adminPhone,emp_phone,gift_card_value,emp_id,emp_name,user_id)
return render_template("reward_submissions.html",name=user_name,sweetalert=True,link=link)
return render_template("reward_submissions.html",name=user_name)
except KeyError:
return redirect("/login")
#admin_pages
############################################
# members_pages
@app.route("/dashboard-member")
def member_dashboard():
return render_template("index_member.html")
@app.route("/member-projects")
def memberProjects():
try:
session['usr']
all_users = db.child("Users").get()
for user in all_users.each():
employee_id=user.key()
path="Users/"+employee_id+"/session/session_id"
customer_session=db.child(path).get().val()
if (customer_session==session['usr']) :
user_name=db.child("Users").child(employee_id).child("profile/name").get().val()
user_id=employee_id
if db.child("Users/"+user_id+"/Projects").get().val() is not None:
projects_info=project_details(user_id)
return render_template("member_projects.html",name=user_name,projects=projects_info)
else:
return render_template("member_projects.html",name=user_name,message="No Running Projects were found")
except KeyError:
return redirect("/login")
@app.route("/tasks",methods=["GET","POST"])
def tasks():
try:
session['usr']
all_users = db.child("Users").get()
for user in all_users.each():
employee_id=user.key()
path="Users/"+employee_id+"/session/session_id"
customer_session=db.child(path).get().val()
if (customer_session==session['usr']) :
user_name=db.child("Users").child(employee_id).child("profile/name").get().val()
user_id=employee_id
if db.child("Users").child(user_id).child("task_submissions").get().val() is None:
if request.method=="POST":
task_name=request.form["task_name"]
task_id=request.form["task_id"]
project_name=request.form["project_name"]
project_id=request.form["project_id"]
submit_task(project_name,project_id,task_name,task_id,user_id)
return redirect("/exercise-portal")
return render_template("member_tasks.html",name=user_name,message="No Submissions found till now")
else:
task_details=submission_details(user_id)
if request.method=="POST":
task_name=request.form["task_name"]
task_id=request.form["task_id"]
project_name=request.form["project_name"]
project_id=request.form["project_id"]
submit_task(project_name,project_id,task_name,task_id,user_id)
return redirect("/exercise-portal")
return render_template("member_tasks.html", name=user_name,tasks=task_details)
except KeyError:
return redirect("/login")
@app.route("/idea",methods=["GET","POST"])
def idea():
try:
session['usr']
all_users = db.child("Users").get()
for user in all_users.each():
employee_id=user.key()
path="Users/"+employee_id+"/session/session_id"
customer_session=db.child(path).get().val()
if (customer_session==session['usr']) :
user_name=db.child("Users").child(employee_id).child("profile/name").get().val()
user_id=employee_id
if request.method=="POST":
idea_tagline=request.form["idea_tagline"]
description=request.form["description"]
business_model=request.form["business_model"]
business_model_link=request.form["business_model_link"]
submit_idea(user_id,idea_tagline,business_model_link,business_model,description)
return render_template("member_submit_idea.html",name=user_name)
except KeyError:
return redirect("/login")
@app.route("/send-message",methods=["GET","POST"])
def send_message():
try:
session['usr']
all_users = db.child("Users").get()
for user in all_users.each():
employee_id=user.key()
path="Users/"+employee_id+"/session/session_id"
customer_session=db.child(path).get().val()
if (customer_session==session['usr']) :
user_name=db.child("Users").child(employee_id).child("profile/name").get().val()
user_id=employee_id
if request.method=="POST":
admin_email=request.form["admin_email"]
gift_card_value=request.form["gift_card_value"]
description=request.form["msg_description"]
sendmessage(description,gift_card_value,admin_email,user_id)
return render_template("send_message.html",name=user_name,sweetalert=True)
return render_template("send_message.html",name=user_name)
except KeyError:
return redirect("/login")
@app.route("/member-reward-history")
def member_reward_history():
try:
session['usr']
all_users = db.child("Users").get()
for user in all_users.each():
employee_id=user.key()
path="Users/"+employee_id+"/session/session_id"
customer_session=db.child(path).get().val()
if (customer_session==session['usr']) :
user_name=db.child("Users").child(employee_id).child("profile/name").get().val()
user_id=employee_id
if db.child("Users/"+user_id+"/Projects").get().val() is not None:
reward=GetRewardDetails(user_id)
return render_template("member_reward_history.html",name=user_name,rewards=reward)
else:
return render_template("member_reward_history.html",name=user_name,message="No Rewards Issued till Now")
except KeyError:
return redirect("/login")
#######################
@app.route("/exercise-portal")
def exercise():
return render_template("yoga_OpenCV.html")
@app.route("/logout")
def logout():
session.clear()
return redirect("/login")