forked from mishty06/FundNestApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
676 lines (536 loc) · 23.1 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
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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
from flask import *
from pymongo import *
from pymongo.server_api import ServerApi
import base64
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
app = Flask(__name__)
app.config['SECRET_KEY'] = 'DiplomatesAtDuHacks3.0'
client = MongoClient("enter mongo db url here", server_api=ServerApi('1'))
db = client.fundnest
collection = db.users
@app.route("/")
def index():
return render_template('index.html')
@app.route("/signup")
def signup():
return render_template('signup.html')
@app.route("/CreatingAccount",methods=['GET','POST'])
def CreatingAccount():
if request.method == 'POST':
first_name = request.form['first_name']
last_name = request.form['last_name']
UserName = request.form['UserName']
email = request.form['email']
password = request.form['password']
occupation = request.form['occupation']
if db.users.find_one({'email': email}) or db.users.find_one({'UserName': UserName}):
return render_template('signup.html', error_message="User already registered with that mail id OR UserID")
else:
user_data = {
'first_name': first_name,
'last_name': last_name,
'UserName':UserName,
'email': email,
'password': password,
'occupation': occupation
}
db.users.insert_one(user_data)
if occupation == 'startup_founder':
return redirect(url_for('startup_info', user_name=UserName))
elif occupation == 'investor':
return redirect(url_for('investor_info', user_name=UserName))
elif occupation=='seller':
return redirect(url_for('seller_info', user_name=UserName))
else:
return redirect(url_for('login'))
else:
return redirect(url_for('signup'))
@app.route("/startup_info/<user_name>", methods=['GET', 'POST'])
def startup_info(user_name):
if request.method == 'POST':
startup_name = request.form['startup_name']
year_of_found = request.form['year_of_found']
last_financial_details = request.form['last_financial_details']
number_of_patents = request.form['number_of_patents']
yearly_turnover = request.form['yearly_turnover']
startup_logo = request.files['startup_logo'].read()
dp_base64 = base64.b64encode(startup_logo).decode('utf-8')
db.users.update_one({'UserName':user_name}, {
'$set': {
'startup_info': {
'startup_name': startup_name,
'year_of_found': year_of_found,
'last_financial_details': last_financial_details,
'number_of_patents': number_of_patents,
'yearly_turnover': yearly_turnover,
'dp': dp_base64
}
}
})
return redirect(url_for('login'))
return render_template('startup_info.html')
@app.route("/seller_info/<user_name>", methods=['GET', 'POST'])
def seller_info(user_name):
if request.method == 'POST':
shop_name = request.form['shop_name']
Type_of_Business = request.form['Type_of_Business']
seller_logo = request.files['seller_logo'].read()
dp_base64 = base64.b64encode(seller_logo).decode('utf-8')
db.users.update_one({'UserName': user_name}, {
'$set': {
'seller_info': {
'shop_name': shop_name ,
'Type_of_Business': Type_of_Business,
'dp':dp_base64
}
}
})
return redirect(url_for('login'))
return render_template('seller_info.html')
@app.route("/investor_info/<user_name>", methods=['GET', 'POST'])
def investor_info(user_name):
if request.method == 'POST':
total_investments = request.form['total_investments']
area_of_interest = request.form['area_of_interest']
investor_image = request.files['investor_image'].read()
dp_base64 = base64.b64encode(investor_image).decode('utf-8')
db.users.update_one({'UserName': user_name}, {
'$set': {
'investor_info': {
'total_investments': total_investments,
'area_of_interest': area_of_interest,
'dp':dp_base64
}
}
})
return redirect(url_for('login'))
return render_template('investor_info.html')
@app.route('/home')
def home():
if 'emailID' in session:
user_data = db.users.find_one({'email': session['emailID']})
if user_data:
first_name = user_data.get('first_name', '')
last_name = user_data.get('last_name', '')
UserName = user_data.get('UserName','')
occupation = user_data.get('occupation', '')
email = user_data.get('email','')
posts = db.posts.find().sort('_id', -1)
if occupation == 'seller':
return render_template('home.html', first_name=first_name, last_name=last_name,UserName = UserName,posts=posts,email = email,is_seller=True)
else:
return render_template('home.html', first_name=first_name, last_name=last_name,UserName = UserName ,posts=posts,email = email,is_seller=False)
else:
return render_template('home.html', error_message="User data not found")
else:
return redirect(url_for('login'))
@app.route('/Notifications')
def Notifications():
if 'emailID' not in session:
return redirect(url_for('login'))
email = session['emailID']
Notifications = db.ReqForMeet.find({'FounderMail':email}).sort('_id', -1)
return render_template('notifications.html',Notifications=Notifications)
@app.route('/RequestingForMeeting', methods=['GET', 'POST'])
def RequestingForMeeting():
if 'emailID' not in session:
return redirect(url_for('login'))
usrData = db.users.find_one({'email':session['emailID']})
Mail = usrData.get('email','')
date = request.form['date']
time = request.form['time']
FounderMail = request.form['fMailID']
ReqForMeet = {
'FounderMail':FounderMail,
'Mail':Mail,
'Date':date,
'Time':time
}
db.ReqForMeet.insert_one(ReqForMeet)
link=f"https://fundnest-video-call-application.onrender.com/room/{FounderMail}"
from_email="fundnestHQ@gmail.com"
password="whcd imno grco cmyo"
subject=f"Invitation to Video Chat on <b>[{date}] at [{time}]</b>"
body=f'''
<h5>Dear Sir / Madam,</h5>
<p>
I hope this email finds you well. I am writing to extend an invitation to a video chat scheduled for <b>{date} at {time}</b>. <br> We have an important matter to discuss, and I believe a video chat would be the most effective way to address it.<br>
<i> To join the video chat, please use the following link: <b> <button><a href="{link}">Link</a></button>.</b> Kindly ensure that you have a stable internet connection and access to a device with a webcam and microphone.</i><br>
If the proposed date and time are not convenient for you, please let me know at your earliest convenience, and we can arrange an alternative time that suits us both.<br>
I look forward to our discussion and appreciate your prompt attention to this matter.<br>
</p>
<p>
Best regards,
FundNest
</p>
'''
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = from_email
msg['To'] = Mail
msg.attach(MIMEText(body, 'html'))
with smtplib.SMTP('smtp.gmail.com', 587) as server:
server.starttls()
server.login(from_email, password)
server.sendmail(from_email, Mail, msg.as_string())
server.sendmail(from_email, FounderMail, msg.as_string())
print("Mail Send Successfully")
return redirect(url_for('home'))
@app.route('/profile/<user_name>')
def profile(user_name):
if 'emailID' not in session:
return redirect(url_for('login'))
user_data = db.users.find_one({'UserName':user_name})
if not user_data:
return render_template('profile.html', error_message="User not found")
first_name = user_data.get('first_name', '')
last_name = user_data.get('last_name', '')
email = user_data.get('email', '')
occupation = user_data.get('occupation', '')
email = user_data.get('email','')
if email == session.get('emailID'):
if occupation=='startup_founder':
additional_info = user_data.get('startup_info', {})
return render_template('profile.html', first_name=first_name, last_name=last_name, occupation=occupation,additional_info=additional_info)
elif occupation=='seller':
additional_info = user_data.get('seller_info', {})
return render_template('profile.html', first_name=first_name, last_name=last_name, occupation=occupation,additional_info=additional_info)
else:
investor_info=user_data.get('investor_info',{})
return render_template('profile.html', first_name=first_name, last_name=last_name, occupation=occupation, additional_info=investor_info)
else:
if occupation=='startup_founder':
additional_info = user_data.get('startup_info', {})
return render_template('profile.html', first_name=first_name, last_name=last_name,email=email,occupation=occupation, additional_info=additional_info, readonly=True)
elif occupation=='seller':
additional_info = user_data.get('seller_info', {})
return render_template('profile.html', first_name=first_name, last_name=last_name, occupation=occupation,additional_info=additional_info, readonly=True)
else:
investor_info =user_data.get('investor_info',{})
return render_template('profile.html', first_name=first_name, last_name=last_name,occupation=occupation,additional_info=investor_info, readonly=True)
@app.route('/updatingProfile', methods=['POST'])
def update_profile():
if 'emailID' not in session:
return redirect(url_for('login'))
email = session['emailID']
first_name = request.form.get('first_name', '')
last_name = request.form.get('last_name', '')
user_data = db.users.find_one({'email': email})
occupation = user_data.get('occupation', '')
if occupation == 'startup_founder':
startup_name = request.form.get('startup_name', '')
year_of_found = request.form.get('year_of_found', '')
last_financial_details = request.form.get('last_financial_details', '')
number_of_patents = request.form.get('number_of_patents', '')
yearly_turnover = request.form.get('yearly_turnover', '')
if 'dp' in request.files:
file = request.files['dp']
if file.filename != '':
print("in if part")
dp = file.read()
dp_base64 = base64.b64encode(dp).decode('utf-8')
print(dp_base64)
else:
print("in else part - No file selected")
dp_base64 = user_data.get('startup_info', {}).get('dp', '')
print(dp_base64)
db.users.update_one({'email': email}, {
'$set': {
'first_name': first_name,
'last_name': last_name,
'startup_info': {
'startup_name': startup_name,
'year_of_found': year_of_found,
'last_financial_details': last_financial_details,
'number_of_patents': number_of_patents,
'yearly_turnover': yearly_turnover,
'dp':dp_base64
}
}
})
elif occupation == 'investor':
total_investments = request.form.get('total_investments', '')
area_of_interest = request.form.get('area_of_interest', '')
if 'dp' in request.files:
file = request.files['dp']
if file.filename != '':
print("in if part")
dp = file.read()
dp_base64 = base64.b64encode(dp).decode('utf-8')
print(dp_base64)
else:
print("in else part - No file selected")
dp_base64 = user_data.get('investor_info', {}).get('dp', '')
print(dp_base64)
db.users.update_one({'email': email}, {
'$set': {
'first_name': first_name,
'last_name': last_name,
'investor_info': {
'total_investments': total_investments,
'area_of_interest': area_of_interest,
'dp':dp_base64
}
}
})
else:
shop_name= request.form.get('shop_name' , '')
Type_of_Business = request.form.get('Type_of_Business' , '')
if 'dp' in request.files:
file = request.files['dp']
if file.filename != '':
print("in if part")
dp = file.read()
dp_base64 = base64.b64encode(dp).decode('utf-8')
print(dp_base64)
else:
print("in else part - No file selected")
dp_base64 = user_data.get('seller_info', {}).get('dp', '')
print(dp_base64)
db.users.update_one({'email': email}, {
'$set': {
'first_name': first_name,
'last_name': last_name,
'seller_info': {
'shop_name': shop_name,
'Type_of_Business': Type_of_Business,
'dp':dp_base64
}
}
})
return redirect(url_for('profile', user_name=user_data.get('UserName','')))
@app.route('/AddPost')
def AddPost():
if 'emailID' not in session:
return redirect(url_for('login'))
return render_template('AddPost.html')
@app.route('/AddIngPost', methods=['POST'])
def AddIngPost():
if 'emailID' not in session:
return redirect(url_for('login'))
if request.method == 'POST':
title = request.form.get('title')
description = request.form.get('description')
img = request.files['image'].read()
dp_base64 = base64.b64encode(img).decode('utf-8')
email_id = session['emailID']
usr_data = db.users.find_one({'email':email_id})
if db.posts.find_one({}, sort=[('id', -1)]):
last_post = db.posts.find_one({}, sort=[('id', -1)])
print(last_post)
last_post_id = int(last_post['id'])
new_post_id = last_post_id + 1
else:
new_post_id = 1
usrName = usr_data.get('UserName','')
db.posts.insert_one({
'id': new_post_id,
'UserName':usrName,
'email': email_id,
'title': title,
'description': description,
'img':dp_base64
})
return redirect(url_for('posts'))
return redirect(url_for('posts'))
@app.route('/YourPosts')
def posts():
if 'emailID' not in session:
return redirect(url_for('login'))
email_id = session['emailID']
user_posts = db.posts.find({'email': email_id}).sort('_id', -1)
print(user_posts)
return render_template('posts.html', user_posts=user_posts)
@app.route('/deletingPost', methods = ['POST','GET'])
def deletingPost():
if 'emailID' not in session:
return redirect(url_for('login'))
Post_ID = int(request.form['pID'])
print("post id",Post_ID)
db.posts.find_one_and_delete({'id': Post_ID})
return redirect(url_for('home'))
@app.route('/login')
def login():
return render_template('login.html')
@app.route('/logout')
def logout():
session.pop('emailID', None)
return redirect(url_for('login'))
@app.route('/loggingIn',methods=['POST'])
def loggingIn():
emailID = request.form['email']
PassWd = request.form['pass']
if db.users.find_one({'email': emailID, 'password': PassWd}):
session['emailID'] = emailID
return redirect(url_for('home'))
else:
return redirect(url_for('login'))
@app.route('/add_product', methods=['GET', 'POST'])
def add_product():
if 'emailID' not in session:
return redirect(url_for('login'))
if request.method == 'POST':
product_name = request.form['name']
product_description = request.form['description']
product_id = request.form['product_id']
product_price = request.form['price']
product_seller = session['emailID']
product_field = request.form['field']
product_payment_link = request.form['payment_link']
if db.products.find_one({'product_id': product_id}):
return render_template('add_products.html', error_message="This product id already exists")
else:
product_data = {
'name': product_name,
'description': product_description,
'product_id': product_id,
'price': product_price,
'seller': product_seller,
'field': product_field,
'payment_link':product_payment_link
}
db.products.insert_one(product_data)
return redirect('/home')
return render_template('add_products.html')
@app.route('/update_products', methods=['GET'])
def update_products_page():
if 'emailID' not in session:
return redirect(url_for('login'))
seller_email = session['emailID']
seller_products = db.products.find({'seller': seller_email})
return render_template('update_products.html', products=seller_products)
@app.route('/update_product/<product_id>', methods=['GET','POST'])
def update_product(product_id):
if 'emailID' not in session:
return redirect(url_for('login'))
seller_email = session['emailID']
print(seller_email)
product = db.products.find_one({'product_id': product_id, 'seller': seller_email})
print(product)
if not product:
return render_template('update_products.html', error_message="Product not found or you are not authorized to update it")
if request.method == 'POST':
updated_product = {
'name': request.form['name'],
'description': request.form['description'],
'price': request.form['price'],
'field': request.form['field']
}
db.products.update_one({'product_id': product_id, 'seller': seller_email}, {'$set': updated_product})
return redirect('/home')
return render_template('update_product_form.html', product=product)
@app.route('/delete_product', methods=['GET'])
def delete_product_page():
if 'emailID' not in session:
return redirect(url_for('login'))
seller_email = session['emailID']
seller_products = db.products.find({'seller': seller_email})
return render_template('delete_products.html', products=seller_products)
@app.route('/delete_product/<product_id>', methods=['POST'])
def delete_product(product_id):
if 'emailID' not in session:
return redirect(url_for('login'))
seller_email = session['emailID']
result = db.products.delete_one({'product_id': product_id, 'seller': seller_email})
if result.deleted_count == 1:
return redirect('/home')
else:
return render_template('delete_products.html', error_message="Product not found or you are not authorized to delete it")
@app.route('/products')
def products():
if 'emailID' not in session:
return redirect(url_for('login'))
field_filter = request.args.get('field', '')
if field_filter:
products = db.products.find({'field': field_filter})
else:
products = db.products.find()
return render_template('products.html', products=products)
@app.route('/submit_order', methods=['POST'])
def submit_order():
if request.method == 'POST':
print("In Post Method")
product_id = request.form['product_id']
seller_mail = db.products.find({'product_id':product_id}).next()['seller']
quantity = request.form['quantity']
email=session.get('emailID')
UserName = db.users.find( {'email': email}).next()['UserName']
p_Data = db.products.find_one({'product_id':product_id})
link_for_payment = p_Data['payment_link']
order_data = {
"usernm":UserName,
'user_email':session.get('emailID'),
'seller_email':seller_mail,
'product_id': product_id,
'quantity': quantity
}
print(order_data)
db.orders.insert_one(order_data)
return redirect(link_for_payment)
else:
return render_template('products.html')
@app.route('/orders')
def orders():
if 'emailID' not in session:
return redirect(url_for('login'))
email=session.get('emailID')
orders = db.orders.find({'seller_email':email})
return render_template('seller_side_orders.html',orders=orders)
@app.route ('/privacy_policy',methods = ['GET'])
def policy():
return render_template('privacy_policy.html')
@app.route('/info',methods=['POST','GET'])
def Contact():
if request.method=="POST":
email = request.form['email']
name = request.form['name']
phone = request.form['phone']
sub = request.form['sub']
description = request.form['description']
Contact = {
'email': email,
'name': name,
'phone': phone,
'sub': sub,
'description': description
}
db.contact.insert_one(Contact)
flash("Your Message has been Sent to Admin")
from_email="fundnestHQ@gmail.com"
password="whcd imno grco cmyo"
subject="Issues faced by the users"
body=f'''
<h5>Dear Owners</h5>
<p>
The users of your dearest site are having some issues with it .
<br> And they are trying to reach to you .<br>
According to one of the user Naming <b>{name}</b> <br>having email : <b>{email}</b>,<br> Phone number : <b>{phone}</b> . <br>
The problem of <i>{name}</i> is <b><i>{sub}</i></b> and the deatailed explanation for this issue is :<br> <b>{description}</b>. <br><br>
So kindly review the problems of your dearest users.
</p>
<p>
Best regards,
Your Users
</p>
'''
Mail="fundnestHQ+contactus@gmail.com"
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = from_email
msg['To'] = Mail
msg.attach(MIMEText(body, 'html'))
with smtplib.SMTP('smtp.gmail.com', 587) as server:
server.starttls()
server.login(from_email, password)
server.sendmail(from_email, Mail, msg.as_string())
print("Mail Send Successfully")
return redirect('/info')
return render_template('contact_us.html')
@app.route('/AboutUs' , methods =['POST' , 'GET'])
def AboutUs():
return render_template('About.html')
if __name__ =="__main__":
app.run(debug=True)