-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
1122 lines (1045 loc) · 50.4 KB
/
Copy pathmain.py
File metadata and controls
1122 lines (1045 loc) · 50.4 KB
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
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# COMPILE PROJECTS 2020
# KYLE HALO
# IMPORT FILES #
import os
import os.path as op
import json
import datetime
from functools import wraps
from flask_cors import CORS
from flask_login import LoginManager, current_user, login_user, login_required, logout_user
from flask import Flask, request, render_template, redirect, flash, url_for, make_response, session, Markup, flash, Response, jsonify
from flask_jwt import JWT, jwt_required, current_identity
from sqlalchemy.exc import IntegrityError
from datetime import timedelta
from models import db, user, product, orders, wish_list
from forms import invoice_fields, product_fields, bill_fields, SignUp, LogIn, EditEmail, EditUsername, EditName, EditPassword, SendLostPasswordLink, EditPassword_reset, EmailSend
from flask_weasyprint import HTML, render_pdf
from flask_uploads import UploadSet, configure_uploads, IMAGES
import qrcode
from flask_qrcode import QRcode
from flask_admin import Admin, AdminIndexView
from flask_admin.contrib.sqla import ModelView
from flask_admin.contrib.fileadmin import FileAdmin
from flask_mail import Mail, Message
from itsdangerous import URLSafeTimedSerializer, SignatureExpired, BadTimeSignature
# Login Manager #
login_manager = LoginManager()
@login_manager.user_loader
def load_user(user_id):
return user.query.get(user_id)
# Admin Manager Custom Decorator #
def admin_required(func):
@wraps(func)
def decorated_function(*args, **kwargs):
if current_user.is_admin:
return func(*args, **kwargs)
else:
flash('Account does not have Administrator Privileges')
return redirect(url_for('index'))
return decorated_function
# Default User Manager Custom Decorator #
def default_required(func):
@wraps(func)
def decorated_function(*args, **kwargs):
if not current_user.is_premium:
return func(*args, **kwargs)
else:
flash('Account is already Premium')
return redirect(url_for('index'))
return decorated_function
# Premium User Manager Custom Decorator #
def premium_required(func):
@wraps(func)
def decorated_function(*args, **kwargs):
if current_user.is_premium:
return func(*args, **kwargs)
else:
flash('Account does not have Premium')
return redirect(url_for('premium'))
return decorated_function
# Server Init #
def create_app():
app = Flask(__name__, static_url_path='')
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ["DATABASE_URL"]
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.config['SECRET_KEY'] = os.environ["APP_KEY"]
app.config['RECAPTCHA_PUBLIC_KEY'] = os.environ["RE_SITE_KEY"]
app.config['RECAPTCHA_PRIVATE_KEY'] = os.environ["RE_SITE_SECRET_KEY"]
app.config['UPLOADED_IMAGES_DEST'] = 'uploads/images'
app.config['MAIL_SERVER'] = 'smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
app.config['MAIL_USERNAME'] = os.environ["EMAIL_USER"]
app.config['MAIL_PASSWORD'] = os.environ["EMAIL_PASS"]
app.config['MAIL_DEFAULT_SENDER'] = ('Compile Projects Support', os.environ["EMAIL_USER"])
app.config['MAIL_MAX_EMAILS'] = None
app.config['MAIL_ASCII_ATTACHMENTS'] = False
CORS(app)
QRcode(app)
login_manager.init_app(app)
db.init_app(app)
return app
app = create_app()
app.app_context().push()
images = UploadSet('images', IMAGES)
configure_uploads(app, images)
mail = Mail(app)
app.jinja_env.add_extension('jinja2.ext.loopcontrols')
# Flask Admin Setup #
class MyModelView(ModelView):
column_display_pk = True
def is_accessible(self):
return current_user.is_authenticated and current_user.is_admin
def inaccessible_callback(self, name, **kwargs):
return redirect(url_for('login'))
class MyAdminIndexView(AdminIndexView):
def is_accessible(self):
return current_user.is_authenticated and current_user.is_admin
def inaccessible_callback(self, name, **kwargs):
return redirect(url_for('login'))
# First Setup Admin View Pages#
#admin = Admin(app)
#admin.add_view(ModelView(user, db.session))
# Normal Admin View Pages #
admin = Admin(app, index_view=MyAdminIndexView())
admin.add_view(MyModelView(user, db.session))
admin.add_view(MyModelView(product, db.session))
admin.add_view(MyModelView(orders, db.session))
admin.add_view(MyModelView(wish_list, db.session))
path = op.join(op.dirname(__file__), 'static')
admin.add_view(FileAdmin(path, '/static/', name='Static Folder'))
# Email Confirmation Links Setup #
s = URLSafeTimedSerializer(app.config['SECRET_KEY'])
# Merge Items In Session Function #
def MergeDicts(dict1, dict2):
if isinstance(dict1, list) and isinstance(dict2, list):
return dict1 + dict2
elif isinstance(dict1, dict) and isinstance(dict2, dict):
list1 = list(dict1.items())
list2 = list(dict2.items())
return dict (list1 + list2)
return False
# ALL SERVER ROUTES #
# Main Routes #
@app.route('/', methods=['GET'])
def index():
agreement = request.cookies.get ('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
return render_template('main.html', agreement=resp)
@app.route('/products', methods=['GET'])
def products():
agreement = request.cookies.get ('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
return render_template('main_products.html', agreement=resp)
@app.route('/aboutus', methods=['GET'])
def aboutus():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
return render_template('main_about_us.html', agreement=resp)
@app.route('/websites', methods=['GET'])
def websites():
agreement = request.cookies.get ('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
web_prod = product.query.filter_by(catagory="WEBSITES")
return render_template('main_websites.html', products = web_prod, agreement=resp)
@app.route('/premium', methods=['GET'])
@login_required
@default_required
def premium():
agreement = request.cookies.get ('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
return render_template('main_premium.html', agreement=resp)
@app.route('/premium/buy', methods=['GET'])
@login_required
@default_required
def premium_buy():
agreement = request.cookies.get ('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
prem_user = user.query.get(current_user.id)
prem_user.is_premium = True
db.session.commit()
absolute_total = 500
absolute_total = "{:.2f}".format(absolute_total)
new_item = orders(user_id = current_user.id, prod_id = 13, is_completed = True, AMT = 1, total_cost = 500, total_monthly = 0, total_downpayment = 0, monthly_due = False, downpayment_due = False, final_due = False)
db.session.add(new_item)
db.session.commit()
msg = Message(subject = "Hey " + current_user.first_name + " we've Recieved Your Order!", recipients=[current_user.email])
about_us_link = url_for('aboutus', _external = True)
contact_us_link = url_for('message_us', _external = True)
privacy_link = url_for('legal', _external = True)
FAQ_link = url_for('legal', _external = True)
FB_link = url_for('FB_compile', _external = True)
Twit_link = url_for('Twitter_compile', _external = True)
IG_link = url_for('IG_compile', _external = True)
GIT_link = url_for('GIT_compile', _external = True)
icons_8_link = url_for('icons_8', _external = True)
msg.html = render_template('mail_prem_bill.html', name = current_user.first_name, absolute_total = absolute_total, monthly_total = 0, down = 0,about_us_link = about_us_link, contact_us_link = contact_us_link, privacy_link = privacy_link, FAQ_link = FAQ_link, FB_link = FB_link, Twit_link = Twit_link, IG_link = IG_link, GIT_link = GIT_link,icons_8_link=icons_8_link)
mail.send(msg)
msg_2 = Message(subject = current_user.first_name + " welcome to Premium!", recipients=[current_user.email])
link = url_for('profile_page', _external = True)
msg_2.html = render_template('mail_prem.html', name = current_user.first_name, absolute_total = absolute_total, monthly_total = 0, down = 0,about_us_link = about_us_link, contact_us_link = contact_us_link, privacy_link = privacy_link, FAQ_link = FAQ_link, FB_link = FB_link, Twit_link = Twit_link, IG_link = IG_link, GIT_link = GIT_link,icons_8_link=icons_8_link, link = link)
mail.send(msg_2)
msg_ky = Message(subject= current_user.first_name + " Made An Order!", recipients=[os.environ["EMAIL_USER"]])
msg_ky.html = render_template('mail_kyle_prem.html', name = current_user.first_name, email = current_user.email,number = current_user.phone_number , absolute_total = absolute_total, monthly_total = 0, down = 0, about_us_link = about_us_link, contact_us_link = contact_us_link, privacy_link = privacy_link, FAQ_link = FAQ_link, FB_link = FB_link, Twit_link = Twit_link, IG_link = IG_link, GIT_link = GIT_link,icons_8_link = icons_8_link)
mail.send(msg_ky)
message = Markup("<strong> ACCOUNT UPGRADE SUCCESSFULL! </strong>")
flash(message + 'Your account has been upgraded to Premium!!')
return redirect(url_for('profile_page_orders_done'))
@app.route('/invoice', methods=['GET'])
def invoice():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
return render_template('main_invoice.html', agreement=resp)
@app.route('/bill', methods=['GET'])
def bill():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
return render_template('main_bill.html', agreement=resp)
@app.route('/order', methods=['GET'])
def order():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
return render_template('main_order.html', agreement=resp)
@app.route('/filters', methods=['GET'])
def filters():
agreement = request.cookies.get ('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
filter_prod = product.query.filter_by(catagory="FILTERS")
return render_template('main_filters.html', products = filter_prod, agreement=resp)
@app.route('/legal', methods=['GET'])
def legal():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
return render_template('main_privacy.html', agreement=resp)
@app.route('/legal/purchase', methods=['GET'])
def legal_purchase():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
return render_template('main_legal_purchasing.html', agreement=resp)
@app.route('/legal/free_app', methods=['GET'])
def legal_free_app():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
return render_template('main_legal_free_app.html', agreement=resp)
@app.route('/faq', methods=['GET'])
def FAQ():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
return render_template('main_FAQ.html', agreement=resp)
@app.route('/FAQ', methods=['GET'])
def FAQ_2():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
return render_template('main_FAQ.html', agreement=resp)
@app.route('/offline', methods=['GET'])
def offline():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
return render_template('main_offline.html', agreement=resp)
@app.route('/commingsoon', methods=['GET'])
def comming_soon():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
return render_template('main_comming_soon.html', agreement=resp)
@app.route('/message_us')
def message_us():
return redirect("https://m.me/compileprojects")
@app.route('/FB_compile')
def FB_compile():
return redirect("https://www.facebook.com/compileprojects")
@app.route('/Twitter_compile')
def Twitter_compile():
return redirect("https://twitter.com/compileproject")
@app.route('/IG_compile')
def IG_compile():
return redirect("https://www.instagram.com/compileprojects")
@app.route('/GIT_compile')
def GIT_compile():
return redirect("https://github.com/CompileProjects")
@app.route('/icons_8')
def icons_8():
return redirect("https://icons8.com")
# User / Login Server Paths #
@app.route('/login', methods=['GET', 'POST'])
def login():
agreement = request.cookies.get ('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
form = LogIn()
if form.validate_on_submit():
data = request.form
User = user.query.filter_by(email = data['email']).first()
if User and User.check_password(data['password']):
login_user(User)
if current_user.login_counter == 0:
flash('Welcome to your new Compile Projects account ' + current_user.first_name + " we hope you'll enjoy your stay. Please confirm your email address via the email in your inbox")
token = s.dumps(data['email'], salt='email-confirm')
msg = Message(subject = "Hey " + current_user.first_name + " please take a few seconds to confirm your Compile Projects account!", recipients=[current_user.email])
link = url_for ('confirm_email', token = token, _external = True)
about_us_link = url_for('aboutus', _external = True)
contact_us_link = url_for('message_us', _external = True)
privacy_link = url_for('legal', _external = True)
FAQ_link = url_for('legal', _external = True)
FB_link = url_for('FB_compile', _external = True)
Twit_link = url_for('Twitter_compile', _external = True)
IG_link = url_for('IG_compile', _external = True)
GIT_link = url_for('GIT_compile', _external = True)
icons_8_link = url_for('icons_8', _external = True)
msg.html = render_template('mail_email_confirm_send.html', name = current_user.first_name, link = link,about_us_link = about_us_link, contact_us_link = contact_us_link, privacy_link = privacy_link, FAQ_link = FAQ_link, FB_link = FB_link, Twit_link = Twit_link, IG_link = IG_link, GIT_link = GIT_link, icons_8_link = icons_8_link)
mail.send(msg)
elif current_user.login_counter != 0:
flash('Welcome Back ' + current_user.first_name)
return redirect(url_for('profile_page'))
else:
flash('Invalid Username or Password for Account, Please try again')
return redirect(url_for('login'))
return render_template('main_login.html', form=form, agreement=resp)
@app.route('/signup', methods=['GET', 'POST'])
def signup():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
form = SignUp()
if form.validate_on_submit():
data = request.form
newuser = user(username=data['username'], first_name=data['first_name'], last_name=data['last_name'] , email=data['email'], phone_number=data['phone'], login_counter = 0, is_admin = False, is_premium = False, email_confirmed = False)
newuser.set_password(data['password'])
db.session.add(newuser)
db.session.commit()
flash('Account Succesfully Created!')
return redirect(url_for('login'))
return render_template('main_signup.html', form=form, agreement=resp)
@app.route('/confirm_email/send', methods=['GET', 'POST'])
@login_required
def confirm_email_send():
token = s.dumps(current_user.email, salt='email-confirm')
msg = Message(subject = "Hey " + current_user.first_name + " please take a few seconds to confirm your Compile Projects account!", recipients=[current_user.email])
link = url_for ('confirm_email', token = token, _external = True)
about_us_link = url_for('aboutus', _external = True)
contact_us_link = url_for('message_us', _external = True)
privacy_link = url_for('legal', _external = True)
FAQ_link = url_for('legal', _external = True)
FB_link = url_for('FB_compile', _external = True)
Twit_link = url_for('Twitter_compile', _external = True)
IG_link = url_for('IG_compile', _external = True)
GIT_link = url_for('GIT_compile', _external = True)
icons_8_link = url_for('icons_8', _external = True)
msg.html = render_template('mail_email_confirm_send.html', name = current_user.first_name, link = link,about_us_link = about_us_link, contact_us_link = contact_us_link, privacy_link = privacy_link, FAQ_link = FAQ_link, FB_link = FB_link, Twit_link = Twit_link, IG_link = IG_link, GIT_link = GIT_link, icons_8_link=icons_8_link)
mail.send(msg)
flash('Confirmation Email sent to '+current_user.email)
return redirect(request.referrer)
@app.route('/confirm_email/<token>', methods=['GET', 'POST'])
@login_required
def confirm_email(token):
try:
email = s.loads(token, salt='email-confirm')
except SignatureExpired:
flash('⚠ Conformation Link Expired')
return redirect(url_for('profile_page'))
except BadTimeSignature:
flash('⚠ Incorrect Conformation Link')
return redirect(url_for('profile_page'))
update_user = user.query.get(current_user.id)
update_user.email_confirmed = True
db.session.commit()
flash('Email Confirmed!')
msg = Message(subject = "The email address for your Compile Projects account has been confirmed!", recipients=[current_user.email])
about_us_link = url_for('aboutus', _external = True)
contact_us_link = url_for('message_us', _external = True)
privacy_link = url_for('legal', _external = True)
FAQ_link = url_for('legal', _external = True)
FB_link = url_for('FB_compile', _external = True)
Twit_link = url_for('Twitter_compile', _external = True)
IG_link = url_for('IG_compile', _external = True)
GIT_link = url_for('GIT_compile', _external = True)
icons_8_link = url_for('icons_8', _external = True)
msg.html = render_template('mail_email_confirm.html', name = current_user.first_name,about_us_link = about_us_link, contact_us_link = contact_us_link, privacy_link = privacy_link, FAQ_link = FAQ_link, FB_link = FB_link, Twit_link = Twit_link, IG_link = IG_link, GIT_link = GIT_link, icons_8_link = icons_8_link)
mail.send(msg)
return redirect(url_for('profile_page'))
@app.route('/admin/send_mail', methods=['GET', 'POST'])
@login_required
@admin_required
def admin_send_mail():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
form = EmailSend()
if form.validate_on_submit():
data = request.form
email = data['email']
sub = data['email_subject']
body = data['email_body']
bot = data['email_bottom']
admin_name = current_user.first_name
msg = Message(subject = sub, recipients=[email], sender=[admin_name+' from Compile Projects', os.environ["EMAIL_USER"]])
about_us_link = url_for('aboutus', _external = True)
contact_us_link = url_for('message_us', _external = True)
privacy_link = url_for('legal', _external = True)
FAQ_link = url_for('legal', _external = True)
FB_link = url_for('FB_compile', _external = True)
Twit_link = url_for('Twitter_compile', _external = True)
IG_link = url_for('IG_compile', _external = True)
GIT_link = url_for('GIT_compile', _external = True)
icons_8_link = url_for('icons_8', _external = True)
msg.html = render_template('mail_admin_send.html',about_us_link = about_us_link, contact_us_link = contact_us_link, privacy_link = privacy_link, FAQ_link = FAQ_link, FB_link = FB_link, Twit_link = Twit_link, IG_link = IG_link, GIT_link = GIT_link, icons_8_link = icons_8_link, admin_name = admin_name, body = body, bot = bot)
mail.send(msg)
flash('Email Sent!')
return render_template('main_profile_mail_send.html', agreement=resp, form = form)
@app.route('/profile', methods=['GET', 'POST'])
@login_required
def profile_page():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
return render_template('main_profile.html', agreement=resp)
@app.route('/profile/orders', methods=['GET', 'POST'])
@login_required
def profile_page_orders_pending():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
test = False
my_prods = db.session.query(orders, product).outerjoin(product, orders.prod_id == product.id).all()
test_query = orders.query.filter_by(user_id = current_user.id).first()
if test_query:
test = True
done_counter = 0
number_of_prods = 0
all_orders_complete = False
for key, item in my_prods:
number_of_prods += 1
if key.is_completed:
done_counter += 1
if done_counter == number_of_prods:
all_orders_complete = True
return render_template('main_profile_orders.html', prods = my_prods, test = test, agreement=resp, all_orders_complete = all_orders_complete)
@app.route('/profile/purchased', methods=['GET', 'POST'])
@login_required
def profile_page_orders_done():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
test = False
my_prods = db.session.query(orders, product).outerjoin(product, orders.prod_id == product.id).all()
test_query = orders.query.filter_by(user_id = current_user.id).first()
if test_query:
test = True
done_counter = 0
number_of_prods = 0
all_orders_complete = False
for key, item in my_prods:
number_of_prods += 1
if key.is_completed:
done_counter += 1
if done_counter != number_of_prods:
all_orders_complete = True
return render_template('main_profile_orders_done.html', prods = my_prods, test = test, agreement=resp,all_orders_complete = all_orders_complete)
@app.route('/profile/wishlist', methods=['GET', 'POST'])
@login_required
def profile_page_wishlist():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
test = False
my_wish_list = db.session.query(wish_list, product).filter(wish_list.user_id == current_user.id).filter(wish_list.prod_id == product.id).all()
test_query = wish_list.query.filter_by(user_id = current_user.id).first()
if test_query:
test = True
return render_template('main_profile_wishlist.html', prods = my_wish_list, test = test, agreement=resp)
@app.route('/wishlist/add/<id>', methods=['GET', 'POST'])
@login_required
def wishlist(id):
test = db.session.query(wish_list).filter(wish_list.user_id == current_user.id).filter(wish_list.prod_id == id).all()
prod = product.query.filter_by(id = id).first()
if test:
flash(prod.name+' is already in '+current_user.first_name+"'s Wishlist...")
if not test:
new_item = wish_list(user_id = current_user.id, prod_id = id)
db.session.add(new_item)
db.session.commit()
flash(prod.name+' added to '+current_user.first_name+"'s Wishlist!...")
return redirect(request.referrer)
@app.route('/wishlist/remove/<id>', methods=['GET', 'DELETE'])
@login_required
def wishlist_del(id):
del_item = wish_list.query.get(id)
del_item_info = product.query.get(id)
db.session.delete(del_item)
db.session.commit()
flash(del_item_info.name+' removed from '+current_user.first_name+"'s Wishlist")
return redirect(request.referrer)
@app.route('/profile/settings', methods=['GET', 'POST'])
@login_required
def profile_page_settings():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
return render_template('main_profile_settings.html', agreement=resp)
@app.route('/profile/email_reset', methods=['GET', 'POST'])
@login_required
def profile_page_email():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
form = EditEmail()
if form.validate_on_submit():
data = request.form
email = data['email']
test = user.query.filter_by(email = email).first()
if test:
flash('The email address '+ email +' already belongs to another person')
return redirect(request.referrer)
if not test:
update = user.query.get(current_user.id)
msg = Message(subject = current_user.first_name +" the email address for your Compile Projects account has been changed", recipients=[current_user.email])
about_us_link = url_for('aboutus', _external = True)
contact_us_link = url_for('message_us', _external = True)
privacy_link = url_for('legal', _external = True)
FAQ_link = url_for('legal', _external = True)
FB_link = url_for('FB_compile', _external = True)
Twit_link = url_for('Twitter_compile', _external = True)
IG_link = url_for('IG_compile', _external = True)
GIT_link = url_for('GIT_compile', _external = True)
icons_8_link = url_for('icons_8', _external = True)
msg.html = render_template('mail_email_change.html', name = current_user.first_name,about_us_link = about_us_link, contact_us_link = contact_us_link, privacy_link = privacy_link, FAQ_link = FAQ_link, FB_link = FB_link, Twit_link = Twit_link, IG_link = IG_link, GIT_link = GIT_link, email = email,icons_8_link=icons_8_link)
mail.send(msg)
update.email = email
update.email_confirmed = False
db.session.commit()
token = s.dumps(current_user.email, salt='email-confirm')
msg = Message(subject = "Hey " + current_user.first_name + " please take a few seconds to confirm your Compile Projects account!", recipients=[current_user.email])
link = url_for ('confirm_email', token = token, _external = True)
msg.html = render_template('mail_email_confirm_send.html', name = current_user.first_name, link = link,about_us_link = about_us_link, contact_us_link = contact_us_link, privacy_link = privacy_link, FAQ_link = FAQ_link, FB_link = FB_link, Twit_link = Twit_link, IG_link = IG_link, GIT_link = GIT_link,icons_8_link=icons_8_link)
mail.send(msg)
flash('Email Updated! Please verify that '+ email +' is your new email through the mail sent to this address')
return redirect(url_for('profile_page'))
return render_template('main_profile_settings_email.html', agreement=resp, form = form)
@app.route('/profile/username_reset', methods=['GET', 'POST'])
@login_required
def profile_page_username():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
form = EditUsername()
if form.validate_on_submit():
data = request.form
username = data['username']
test = user.query.filter_by(username = username).first()
if test:
flash('The username '+ username +' already belongs to another person')
return redirect(request.referrer)
if not test:
update = user.query.get(current_user.id)
msg = Message(subject = current_user.first_name +" the username for your Compile Projects account has been changed", recipients=[current_user.email])
about_us_link = url_for('aboutus', _external = True)
contact_us_link = url_for('message_us', _external = True)
privacy_link = url_for('legal', _external = True)
FAQ_link = url_for('legal', _external = True)
FB_link = url_for('FB_compile', _external = True)
Twit_link = url_for('Twitter_compile', _external = True)
IG_link = url_for('IG_compile', _external = True)
GIT_link = url_for('GIT_compile', _external = True)
icons_8_link = url_for('icons_8', _external = True)
msg.html = render_template('mail_username_change.html', name = current_user.first_name,about_us_link = about_us_link, contact_us_link = contact_us_link, privacy_link = privacy_link, FAQ_link = FAQ_link, FB_link = FB_link, Twit_link = Twit_link, IG_link = IG_link, GIT_link = GIT_link, email = username, icons_8_link=icons_8_link)
mail.send(msg)
update.username = username
db.session.commit()
flash('Username Updated!')
return redirect(url_for('profile_page'))
return render_template('main_profile_settings_user_name.html', agreement=resp, form = form)
@app.route('/profile/name_reset', methods=['GET', 'POST'])
@login_required
def profile_page_name():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
form = EditName()
if form.validate_on_submit():
data = request.form
f_name = data['first_name']
l_name = data['last_name']
update = user.query.get(current_user.id)
msg = Message(subject = current_user.first_name +" your name for your Compile Projects account has been changed", recipients=[current_user.email])
about_us_link = url_for('aboutus', _external = True)
contact_us_link = url_for('message_us', _external = True)
privacy_link = url_for('legal', _external = True)
FAQ_link = url_for('legal', _external = True)
FB_link = url_for('FB_compile', _external = True)
Twit_link = url_for('Twitter_compile', _external = True)
IG_link = url_for('IG_compile', _external = True)
GIT_link = url_for('GIT_compile', _external = True)
icons_8_link = url_for('icons_8', _external = True)
msg.html = render_template('mail_name_change.html', name = current_user.first_name,about_us_link = about_us_link, contact_us_link = contact_us_link, privacy_link = privacy_link, FAQ_link = FAQ_link, FB_link = FB_link, Twit_link = Twit_link, IG_link = IG_link, GIT_link = GIT_link, f_name = f_name, l_name = l_name,icons_8_link=icons_8_link)
mail.send(msg)
update.first_name = f_name
update.last_name = l_name
db.session.commit()
flash("Name Updated! We'll call you " + current_user.first_name + " " + current_user.last_name + " from now on!")
return redirect(url_for('profile_page'))
return render_template('main_profile_settings_name.html', agreement=resp, form = form)
@app.route('/profile/password_reset', methods=['GET', 'POST'])
@login_required
def profile_page_password():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
form = EditPassword()
if form.validate_on_submit():
data = request.form
old_pass = data['old_password']
new_pass = data['new_password']
edit_user = user.query.get(current_user.id)
if not edit_user.check_password(old_pass):
flash('Incorrect old Password')
return redirect(request.referrer)
if edit_user.check_password(old_pass):
msg = Message(subject = current_user.first_name +" the password for your Compile Projects account has been changed", recipients=[current_user.email])
about_us_link = url_for('aboutus', _external = True)
contact_us_link = url_for('message_us', _external = True)
privacy_link = url_for('legal', _external = True)
FAQ_link = url_for('legal', _external = True)
FB_link = url_for('FB_compile', _external = True)
Twit_link = url_for('Twitter_compile', _external = True)
IG_link = url_for('IG_compile', _external = True)
GIT_link = url_for('GIT_compile', _external = True)
icons_8_link = url_for('icons_8', _external = True)
msg.html = render_template('mail_pass_change.html', name = current_user.first_name,about_us_link = about_us_link, contact_us_link = contact_us_link, privacy_link = privacy_link, FAQ_link = FAQ_link, FB_link = FB_link, Twit_link = Twit_link, IG_link = IG_link, GIT_link = GIT_link,icons_8_link=icons_8_link)
mail.send(msg)
edit_user.set_password(new_pass)
db.session.commit()
flash('Password Updated!')
return redirect(url_for('profile_page'))
return render_template('main_profile_settings_pass.html', agreement=resp, form = form)
@app.route('/forgot_pass', methods=['GET', 'POST'])
def forgot_pass():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
form = SendLostPasswordLink()
if form.validate_on_submit():
data = request.form
email = data['email']
token = s.dumps(email, salt='pass-reset')
secure_link = url_for ('reset_pass_token', token = token, _external = True)
msg = Message(subject = " Here is the link to reset the password for your Compile Projects account", recipients=[email])
about_us_link = url_for('aboutus', _external = True)
contact_us_link = url_for('message_us', _external = True)
privacy_link = url_for('legal', _external = True)
FAQ_link = url_for('legal', _external = True)
FB_link = url_for('FB_compile', _external = True)
Twit_link = url_for('Twitter_compile', _external = True)
IG_link = url_for('IG_compile', _external = True)
GIT_link = url_for('GIT_compile', _external = True)
icons_8_link = url_for('icons_8', _external = True)
msg.html = render_template('mail_password_recovery_link.html',about_us_link = about_us_link, contact_us_link = contact_us_link, privacy_link = privacy_link, FAQ_link = FAQ_link, FB_link = FB_link, Twit_link = Twit_link, IG_link = IG_link, GIT_link = GIT_link,icons_8_link=icons_8_link, secure_link = secure_link)
mail.send(msg)
flash('An email was sent to '+email)
return redirect(request.referrer)
return render_template('main_password_recovery_send.html', agreement=resp, form = form)
@app.route('/reset/<token>', methods=['GET', 'POST'])
def reset_pass_token(token):
email = s.loads(token, salt='pass-reset')
expire_date = datetime.datetime.now()
expire_date = expire_date + datetime.timedelta(days=1)
cookie = make_response(redirect(url_for('reset_pass_page')))
cookie.set_cookie('email_name',email, expires=expire_date)
return cookie
@app.route('/reset', methods=['GET', 'POST'])
def reset_pass_page():
agreement = request.cookies.get('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
email = request.cookies.get('email_name')
if email == None:
return redirect(url_for('forgot_pass'))
form = EditPassword_reset()
if form.validate_on_submit():
data = request.form
new_pass = data['new_password']
edit_user = user.query.filter_by(email = email).first()
msg = Message(subject = "Hey "+edit_user.first_name+" The password for your Compile Projects account has been reset", recipients=[edit_user.email])
about_us_link = url_for('aboutus', _external = True)
contact_us_link = url_for('message_us', _external = True)
privacy_link = url_for('legal', _external = True)
FAQ_link = url_for('legal', _external = True)
FB_link = url_for('FB_compile', _external = True)
Twit_link = url_for('Twitter_compile', _external = True)
IG_link = url_for('IG_compile', _external = True)
GIT_link = url_for('GIT_compile', _external = True)
icons_8_link = url_for('icons_8', _external = True)
msg.html = render_template('mail_pass_change.html', name = edit_user.first_name,about_us_link = about_us_link, contact_us_link = contact_us_link, privacy_link = privacy_link, FAQ_link = FAQ_link, FB_link = FB_link, Twit_link = Twit_link, IG_link = IG_link, GIT_link = GIT_link,icons_8_link=icons_8_link)
mail.send(msg)
edit_user.set_password(new_pass)
db.session.commit()
flash('Password Reset!')
return redirect(url_for('login'))
return render_template('main_password_reset.html', agreement=resp, form = form)
@app.route('/logout', methods=['GET', 'POST'])
@login_required
def logout():
this_user = user.query.get(current_user.id)
this_user.login_counter += 1
db.session.commit()
message = Markup("<strong> LOGGED OUT </strong>")
flash (message + 'Goodbye ' + current_user.first_name)
logout_user()
return redirect(url_for('index'))
@app.route('/delete_account', methods=['GET', 'DELETE'])
@login_required
def delete_account():
this_user = user.query.get(current_user.id)
db.session.delete(this_user)
db.session.commit()
message = Markup("<strong> ACCOUNT DELETED </strong>")
flash (message + 'Goodbye ' + current_user.first_name + ' thank you for shopping with us!')
msg = Message(subject = current_user.first_name + " your account has been deleted", recipients=[current_user.email])
about_us_link = url_for('aboutus', _external = True)
contact_us_link = url_for('message_us', _external = True)
privacy_link = url_for('legal', _external = True)
FAQ_link = url_for('legal', _external = True)
FB_link = url_for('FB_compile', _external = True)
Twit_link = url_for('Twitter_compile', _external = True)
IG_link = url_for('IG_compile', _external = True)
GIT_link = url_for('GIT_compile', _external = True)
signup = url_for('signup', _external = True)
icons_8_link = url_for('icons_8', _external = True)
msg.html = render_template('mail_del.html', name = current_user.first_name,about_us_link = about_us_link, contact_us_link = contact_us_link, privacy_link = privacy_link, FAQ_link = FAQ_link, FB_link = FB_link, Twit_link = Twit_link, IG_link = IG_link, GIT_link = GIT_link, signup = signup,icons_8_link=icons_8_link)
mail.send(msg)
logout_user()
return redirect(url_for('index'))
# Shopping Cart Functions #
@app.route('/cart', methods=['GET'])
def cart():
agreement = request.cookies.get ('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
absolute_total = 0
monthly_total = 0
monthly_counter = 0
recomend_products = product.query.all()
if 'ShoppingCart' in session and len(session['ShoppingCart']) > 0:
for key, item in session['ShoppingCart'].items():
absolute_total += item["price_total"]
if item["monthly"] == True:
monthly_counter += item["AMT_IN_CART"]
monthly_total = monthly_counter * 200
return render_template('main_cart.html', recomend_products = recomend_products, absolute_total = absolute_total, monthly_total = monthly_total, agreement=resp)
@app.route('/checkout/menu', methods=['GET', 'POST'])
@login_required
def checkout_menu():
agreement = request.cookies.get ('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
absolute_total = 0
monthly_total = 0
monthly_counter = 0
in_cart_counter = 0
recomend_products = product.query.all()
for key, item in session['ShoppingCart'].items():
in_cart_counter += item["AMT_IN_CART"]
absolute_total += item["price_total"]
if item["monthly"] == True:
monthly_counter += item["AMT_IN_CART"]
US_TOTAL = absolute_total * 0.15
monthly_total = monthly_counter * 200
return render_template('main_check_out.html', recomend_products = recomend_products, absolute_total = absolute_total, monthly_total = monthly_total, agreement=resp, US_TOTAL = US_TOTAL)
@app.route('/checkout', methods=['GET', 'POST'])
@login_required
def checkout():
absolute_total = 0
monthly_total = 0
monthly_counter = 0
if 'ShoppingCart' in session and len(session['ShoppingCart']) > 0:
for key, item in session['ShoppingCart'].items():
absolute_total += item["price_total"]
if item["monthly"] == True:
monthly_counter += item["AMT_IN_CART"]
monthly_total = monthly_counter * 200
downpayment = absolute_total * 20 / 100
downpayment = "{:.2f}".format(downpayment)
absolute_total = "{:.2f}".format(absolute_total)
monthly_total = "{:.2f}".format(monthly_total)
list_x = []
for key, item in session['ShoppingCart'].items():
new_item = orders(user_id = current_user.id, prod_id = item["id"], is_completed = False, AMT = item["AMT_IN_CART"], total_cost = "{:.2f}".format(item["price_total"]), total_monthly = "{:.2f}".format(item["monthly_price"]), total_downpayment = downpayment, monthly_due = False, downpayment_due = True, final_due = False)
db.session.add(new_item)
db.session.commit()
list_x.append(new_item.id)
print(new_item.id)
msg = Message(subject = "Hey " + current_user.first_name + " We've Recieved Your Order!", recipients=[current_user.email])
about_us_link = url_for('aboutus', _external = True)
contact_us_link = url_for('message_us', _external = True)
privacy_link = url_for('legal', _external = True)
FAQ_link = url_for('legal', _external = True)
FB_link = url_for('FB_compile', _external = True)
Twit_link = url_for('Twitter_compile', _external = True)
IG_link = url_for('IG_compile', _external = True)
GIT_link = url_for('GIT_compile', _external = True)
icons_8_link = url_for('icons_8', _external = True)
msg.html = render_template('mail_layout.html', name = current_user.first_name, absolute_total = absolute_total, monthly_total = monthly_total, down = downpayment,about_us_link = about_us_link, contact_us_link = contact_us_link, privacy_link = privacy_link, FAQ_link = FAQ_link, FB_link = FB_link, Twit_link = Twit_link, IG_link = IG_link, GIT_link = GIT_link,icons_8_link=icons_8_link)
mail.send(msg)
msg_ky = Message(subject= current_user.first_name + " Made An Order!", recipients=[os.environ["EMAIL_USER"]])
msg_ky.html = render_template('mail_kyle.html', name = current_user.first_name, email = current_user.email,number = current_user.phone_number, absolute_total = absolute_total, monthly_total = monthly_total, down = downpayment,about_us_link = about_us_link, contact_us_link = contact_us_link, privacy_link = privacy_link, FAQ_link = FAQ_link, FB_link = FB_link, Twit_link = Twit_link, IG_link = IG_link, GIT_link = GIT_link,icons_8_link = icons_8_link, list_x = list_x)
mail.send(msg_ky)
session['ShoppingCart'].clear()
message = Markup("<strong> ORDER SUCCESSFULLY PLACED! </strong>")
flash(message + 'Please check your email, an employee shal contact you soon')
return redirect(url_for('profile_page_orders_pending'))
@app.route('/shop/<id>', methods=['GET'])
def shop(id):
agreement = request.cookies.get ('cookie-policy')
if agreement == None:
resp = 'no'
if agreement == 'AGREE':
resp = 'yes'
amt_in_cart = 0
incart = False
name = "prod_"+id
if 'ShoppingCart' in session and len(session['ShoppingCart']) > 0:
for key, item in session['ShoppingCart'].items():
if key == name:
incart = True
for field in item:
if field == "AMT_IN_CART":
amt_in_cart = item[field]
prod = product.query.get(id)
if prod.in_stock == False:
return redirect (url_for('offline'))
if prod.catagory == "FILTERS":
recomend_products = product.query.filter_by(catagory="FILTERS")
if prod.catagory == "WEBSITES":
recomend_products = product.query.filter_by(catagory="WEBSITES")
return render_template('main_any_prod.html', prod = prod, recomend_products = recomend_products, incart = incart, amt_in_cart = amt_in_cart, agreement=resp)
@app.route('/add_to_cart/<id>/<amt>', methods=['GET'])
def add_to_cart(id, amt):
amt = int(amt)
add_prod = product.query.get(id)
if add_prod.in_stock == False:
return redirect (url_for('offline'))
price_total = add_prod.price * amt
monthly_total = 0
if add_prod.monthly:
monthly_total = 200 * amt
add_cart_item = {"prod_"+id:{"id":id, "price_total": price_total, "price_per": add_prod.price, "name": add_prod.name, "monthly": add_prod.monthly, "desc": add_prod.desc, "catagory": add_prod.catagory, "sub_catagory": add_prod.sub_catagory, "img_url": add_prod.img_url, "feature_1": add_prod.feature_1, "feature_2": add_prod.feature_2, "feature_3": add_prod.feature_3, "feature_4": add_prod.feature_4, "feature_5": add_prod.feature_5, "feature_6": add_prod.feature_6, "feature_7": add_prod.feature_7, "AMT_IN_CART":amt, "monthly_price": monthly_total}}
if 'ShoppingCart' in session:
session['ShoppingCart'] = MergeDicts(session['ShoppingCart'] , add_cart_item)
return redirect(url_for('cart'))
else:
session['ShoppingCart'] = add_cart_item
return redirect(url_for('cart'))
@app.route('/remove_from_cart/<id>', methods=['GET'])
def remove_from_cart(id):
del_name = "prod_"+id
if 'ShoppingCart' not in session and len(session['ShoppingCart']) <= 0:
return redirect(request.referrer)
else:
session.modified = True
for key, item in session['ShoppingCart'].items():
if key == del_name:
session['ShoppingCart'].pop(key, None)
return redirect(request.referrer)
# Cookie Setting Routes #
@app.route('/setcookie', methods=['GET'])
def setcookie_invoice():
expire_date = datetime.datetime.now()
expire_date = expire_date + datetime.timedelta(days=90)
cookie = make_response(redirect(request.referrer))
cookie.set_cookie('cookie-policy','AGREE', expires=expire_date)