-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
5494 lines (5252 loc) · 221 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
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
import os
import json
import time
import pickle
import random
import pathlib
import zipfile
import pymongo
import datetime
import tempfile
import requests
import webbrowser
import customtkinter
from tkinter import *
from PIL import Image
from tkinter import ttk
from location import GPS
from random import randint
from functions import Weather
from functools import lru_cache
from greetMail import greetEmail
from encryption import Encryption
from threading import Thread, Lock
from emailMessage import MailToUser
from functions import UserCredentials
from functions import CredentialManager
from passlib.context import CryptContext
from tkinter import messagebox, filedialog
from functions import device_name, device_Model
from location import ip_based_location, reverseGeocoding
# Current directory of the application
application_directory = os.getcwd()
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
# Class to download the file
# ---------------------------------------------------------------------------------------------------
class Downloaded_Data:
def __init__(self, data: dict, chats, search_history, save_file_path):
self.data = data
self.search_history = search_history
self.chats = chats
self.save_file_path = save_file_path
def create_directory(self, dir_name):
tempfile.tempdir = dir_name
path = tempfile.gettempdir()
return path
def user_personal_details(self):
path = self.create_directory("Personal Details")
file_name = "personal_details.json"
file_path = os.path.join(path, file_name)
file = {
"id": str(self.data.get("_id")),
"user_name": self.data.get("name"),
"phone number": self.data.get("phone number"),
"email": self.data.get("email"),
"gender": self.data.get("gender"),
"data of birth": self.data.get("DOB").timestamp(),
"other_info": self.data.get("personal_info"),
}
jsonfile = json.dumps(file, indent=5)
return jsonfile, file_path
def user_account_details(self):
path = self.create_directory("Account Details")
file_name = "account_details.json"
file_path = os.path.join(path, file_name)
previous_login_list = self.data.get("login_dates")
previous_login_details = []
for doc in previous_login_list:
doc["time"] = doc["time"].timestamp()
previous_login_details.append(doc)
file = {
"previous_passwords": self.data.get("previous_passwords"),
"account_created": self.data.get("ac_date").timestamp(),
"last_login_date": self.data.get("last_login_date").timestamp(),
"last_login_device_model": self.data.get("last_login_device_model"),
"last_login_coordinates": {
"latitude": self.data.get("last_login_coordinates")[0],
"longitude": self.data.get("last_login_coordinates")[1],
},
"last_login_location": self.data.get("last_login_location"),
"last_login_ip": self.data.get("last_login_ip"),
"previous_login_details": previous_login_details,
}
jsonfile = json.dumps(file, indent=4)
return jsonfile, file_path
def parsing_data(self) -> list:
jsonfile_1, directory_1 = self.user_personal_details()
jsonfile_2, directory_2 = self.user_account_details()
data = [
{"file": jsonfile_1, "directory": directory_1},
{"file": jsonfile_2, "directory": directory_2},
]
return data
def createFile(self):
try:
data = self.parsing_data()
file_name = f"mili_{str(self.data.get('email')).replace('@gmail.com', '').strip()}.zip"
zip_file_path = os.path.join(self.save_file_path, file_name)
password = self.data.get("password")
with zipfile.ZipFile(zip_file_path, "w", zipfile.ZIP_DEFLATED) as zip_file:
zip_file.setpassword(password.encode())
for doc in data:
file_path = doc.get("directory")
file = doc.get("file")
zip_file.writestr(file_path, file)
return True
except:
return False
# ---------------------------------------------------------------------------------------------------------
# Class to hash the password and verify the hashed password
# ---------------------------------------------------------------------------------------------------------
class Hash:
def generateHashedPassword(password: str) -> str:
hashed_password = pwd_context.hash(password)
return hashed_password
def verifyCredential(hashedPassword: str, userPassword: str):
return pwd_context.verify(userPassword, hashedPassword)
# ---------------------------------------------------------------------------------------------------------
# This Class finds the size of all cache files present in the directory
# Also deletes the cache files
# ----------------------------------------------------------------------------------------------------------
class Cache:
def __init__(self):
self.path = os.getcwd()
self.cacheFiles = []
self.extensions = (".cache", ".json", ".tmp", ".pyc", ".bin")
self.protectedFiles = (
"Credentials.cache",
"complements.json",
"Grocery items.bin",
"mili_rap_songs.json",
"mili_songs.json",
"poems.json",
"riddles.json",
)
self.temporaryFiles = ("CAPTCHA.png", ".cache", ".google-cookie")
self.cacheMemory = 0
def CacheFiles(self, dir):
all_files = os.listdir(dir)
for file in all_files:
file_dir = os.path.join(dir, file)
if os.path.isfile(file_dir):
extension = pathlib.Path(file_dir).suffix
if extension in self.extensions and file not in self.protectedFiles:
self.cacheFiles.append(file_dir)
elif file in self.temporaryFiles:
self.cacheFiles.append(file_dir)
elif os.path.isdir(file_dir):
self.CacheFiles(file_dir)
def cacheMemorySize(self):
self.CacheFiles(self.path)
for file in self.cacheFiles:
size = os.path.getsize(filename=file)
self.cacheMemory += size
self.cacheMemory = round(self.cacheMemory / 1024, 2)
return self.cacheMemory
def clearCacheMemory(self):
self.CacheFiles(self.path)
for file in self.cacheFiles:
os.remove(file)
def extractCacheFiles(self):
self.CacheFiles(self.path)
print("Cache files")
for file in self.cacheFiles:
print(file)
# ----------------------------------------------------------------------------------------------------------
# This class returns the appliction size of the assistant
# ----------------------------------------------------------------------------------------------------------
class ApplicationSize:
def __init__(self):
self.path = application_directory
self.size = 0
def readfiles(self, path):
files = os.listdir(path)
for file in files:
dir = os.path.join(path, file)
if os.path.isfile(dir):
self.size += os.path.getsize(dir)
else:
self.readfiles(dir)
def memory(self):
self.readfiles(self.path)
return round(self.size / (1024 * 1024), 2)
# ----------------------------------------------------------------------------------------------------------
class GUI(customtkinter.CTk):
def __init__(self):
super().__init__()
self.title("Mili")
self.GUI_geometry()
self.iconbitmap(application_directory + "\\Data\\Images\\GUI\\logo.ico")
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
self.profileFrame = customtkinter.CTkFrame(
self, fg_color="#252525", corner_radius=0
)
self.profileFrame.grid(row=0, column=0, sticky="nsew")
self.weatherFrame = customtkinter.CTkFrame(
self, fg_color="#252525", corner_radius=0
)
self.weatherFrame.grid(row=0, column=0, sticky="nsew")
self.logFrame = customtkinter.CTkFrame(
self, fg_color="#252525", corner_radius=0
)
self.logFrame.grid(row=0, column=0, sticky="nsew")
self.gameConsoleFrame = customtkinter.CTkFrame(
self, fg_color="#252525", corner_radius=0
)
self.gameConsoleFrame.grid(row=0, column=0, sticky="nsew")
# Function which return the ctk object of the image
# url = file path, height = required height of image, width = required width of image
# ---------------------------------------------------------------------------------------------------
def ImageObject(self, url, height, width):
img = Image.open(os.path.join(application_directory, url))
img = customtkinter.CTkImage(img, size=(height, width))
return img
# ---------------------------------------------------------------------------------------------------
# Function which sets the window in the center of screen
# ---------------------------------------------------------------------------------------------------
def GUI_geometry(self):
w = 1100
h = 650
ws = self.winfo_screenwidth()
hs = self.winfo_screenheight()
x = (ws / 2) - (w / 2)
y = (hs / 2) - (h / 2)
self.geometry("%dx%d+%d+%d" % (w, h, x, y))
# ---------------------------------------------------------------------------------------------------
# Function to raise a frame in top level
# ---------------------------------------------------------------------------------------------------
def showFrame(self, frame):
frame.tkraise()
# ---------------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------------
def Profile(self):
# class to download the data
# ----------------------------------------------------------------------------------------------------
class request_model:
def __init__(self):
self.path = None
self.account_data = None
self.chats = None
self.history = None
self.frame = customtkinter.CTkFrame(
download_data_frame, fg_color="#FFF5EE", corner_radius=0
)
self.frame.grid(row=1, column=0, sticky="nsew")
customtkinter.CTkLabel(
self.frame,
text="Download your data",
fg_color="#FFF5EE",
text_color="#111",
font=("Sitka Small", 16, "bold"),
).pack(side=TOP, anchor="center", pady=(30, 0))
customtkinter.CTkLabel(
self.frame,
text="We'll download a file with your information. You can receive\nit in JSON, which may be easier to import to another service.",
fg_color="#FFF5EE",
text_color="#111",
font=("Sitka Small", 12, "normal"),
).pack(side=TOP, anchor="center")
self.progress_bar = customtkinter.CTkProgressBar(
self.frame,
width=300,
height=15,
orientation="horizontal",
mode="determinate",
fg_color="#FFF5EE",
progress_color="#19b04f",
)
download_file_button = customtkinter.CTkButton(
self.frame,
text="Download",
corner_radius=5,
font=("Sitka Small", 15, "bold"),
height=40,
width=270,
text_color="#111",
fg_color="#1ed760",
border_color="#111",
hover_color="#19b04f",
command=lambda: Thread(target=self.download_path).start(),
)
download_file_button.pack(side=BOTTOM, anchor="center", pady=(0, 40))
def download_account_data(self):
self.url = Encryption(
b"gAAAAABkeM77CniuvGNLTxhTXcvvxS4482UUd-YvStyomao17R01SW_7UrXKCjvUfjwrmYRZ-YEztP6Xpb02tF3mDqH42ECzrMYiw2d6hcw2ZeZuIQXzTNvl-ylfk39vReUEseO0KnAIsnkcdJQeHOTvhjufWM5yYEAShBSZ6g_E3qqcy9pWhlA="
).decrypt_text()
client = pymongo.MongoClient(self.url)
db = client["Assistant"]
collection = db["User Credentials"]
data = collection.find_one({"email": gmail})
self.progress_bar.set(0.3)
self.account_data = data
def download_chats(self):
self.progress_bar.set(0.6)
return None
def download_history(self):
self.progress_bar.set(0.8)
return None
def download_data(self):
exit_button.configure(state="disable", hover=False)
self.progress_bar.pack(side=TOP, anchor="center", pady=(30, 20))
self.progress_bar.set(0)
self.download_account_data()
self.download_chats()
self.download_history()
confidence = Downloaded_Data(
self.account_data, self.chats, self.history, self.path
).createFile()
if confidence is True:
messagebox.showwarning(
"Mili",
"Thankyou for using our services. Your data has been downloaded",
)
self.progress_bar.set(1)
else:
messagebox.showwarning("Mili", "Network issue. Please try again.")
exit_button.configure(
state="enable", hover=True, command=securityFrame.tkraise
)
download_userID.delete(0, END)
def download_path(self):
self.path = filedialog.askdirectory()
if len(self.path) != 0:
exit_button.configure(state="disable", hover=False)
thread = Thread(target=self.download_data)
thread.start()
thread.join()
def verify_credentials(self):
if not Hash.verifyCredential(password, download_userID.get()):
messagebox.showwarning(
"Mili", "The password you entered is invalid. Please try again."
)
else:
self.frame.tkraise()
# -------------------------------------------------------------------------------------------------
def showDownloadFrame():
self.showFrame(downloadFrame)
self.showFrame(download_verification_frame)
# class for the application updates
# -------------------------------------------------------------------------------------------------
class Updates:
def __init__(self) -> None:
self.update_url = None
self.file_size = None
self.file_path = application_directory + "\\Data\\Cache\\Updates.hg"
self.file_name = None
# Checking update in the database
# If update available then extracting the url of update package
def checkupdate(self):
url = Encryption(
b"gAAAAABkeM77CniuvGNLTxhTXcvvxS4482UUd-YvStyomao17R01SW_7UrXKCjvUfjwrmYRZ-YEztP6Xpb02tF3mDqH42ECzrMYiw2d6hcw2ZeZuIQXzTNvl-ylfk39vReUEseO0KnAIsnkcdJQeHOTvhjufWM5yYEAShBSZ6g_E3qqcy9pWhlA="
).decrypt_text()
client = pymongo.MongoClient(url)
db = client["Assistant"]
collection = db["Updates"]
doc = collection.find_one({"url_id": "647a5ffcbf4caa2ac124df88"})
if doc is not None:
self.update_url = doc.get("url")
# Storing update history and removing non required files
def installation(self):
data = {
"date": datetime.datetime.strftime(
datetime.datetime.now(), "%A %d %B, %Y"
),
"time": datetime.datetime.strftime(
datetime.datetime.now(), "%I:%M %p"
),
"file size": round(
(self.file_size / 1048576), 2
), # Size of update is in MB
"file_name": self.file_name,
}
if os.path.exists(self.file_path):
with open(self.file_path, "rb+") as file:
list = pickle.load(file)
list.append(data)
file.seek(0)
pickle.dump(list, file)
file.close()
else:
with open(self.file_path, "wb") as file:
pickle.dump([data], file)
file.close()
# Downloading the package
def download_updates(self):
progressBar.stop()
progressBar.configure(mode="determinate")
progressBar.set(0)
data = 0
chunk_size = 1048576
progressLabel.configure(text=f"Downloading {data}%")
progressLabel.pack_configure(anchor="ne")
r = requests.get(url=self.update_url, stream=True)
file_size = int(r.headers.get("Content-Length"))
self.file_size = file_size
self.file_name = self.update_url.split("/")[-1]
with open(self.file_name, "wb") as fd:
for chunk in r.iter_content(chunk_size):
data += (100 * chunk_size) / file_size
progress_status = data / 100
progressBar.set(progress_status)
progressLabel.configure(
text=f"Downloading {int(round(data, 0))}%"
)
progressBar.update_idletasks()
fd.write(chunk)
progressLabel.configure(text="Installing")
def updateFiles(self):
progressLabel.configure(text="Checking for updates...")
progressBar.pack(side=TOP, anchor="nw")
progressBar.start()
updateButton.configure(
command=None,
fg_color="#393939",
border_color="#111",
border_width=1,
text_color="#111",
hover=False,
)
thread = Thread(target=self.checkupdate)
thread.start()
thread.join()
try:
file_name = self.update_url.split("/")[-1]
except:
file_name = None
if self.update_url is None or os.path.exists(file_name):
progressLabel.configure(text="You are up to date")
progressBar.stop()
progressBar.pack_forget()
updateButton.configure(
command=lambda: Thread(target=Updates().updateFiles).start(),
fg_color="#1ed760",
text_color="#111",
hover_color="#19b04f",
border_width=0,
)
else:
thread = Thread(target=self.download_updates)
thread.start()
thread.join()
installThread = Thread(target=self.installation)
installThread.start()
installThread.join()
progressLabel.configure(text=f"You are up to date")
progressLabel.pack_configure(anchor="nw")
updateButton.configure(
command=lambda: Thread(target=Updates().updateFiles).start(),
fg_color="#1ed760",
text_color="#111",
hover_color="#19b04f",
border_width=0,
)
# Function for update history frame
# --------------------------------------------------------------------------------------------------
def updateHistory():
scrollFrame = customtkinter.CTkScrollableFrame(
updateHistoryFrame, fg_color="#252525", corner_radius=0, height=700
)
scrollFrame.pack(side=TOP, anchor="center", fill=BOTH)
customtkinter.CTkButton(
scrollFrame,
fg_color="#911d5a",
text_color="white",
hover_color="#78184A",
border_width=0,
corner_radius=5,
font=("Sitka Small", 13, "normal"),
text="Back",
height=32,
width=60,
command=lambda: self.showFrame(updatesFrame),
).pack(side=TOP, anchor="ne", padx=20, pady=20)
if (
os.path.exists(application_directory + "\\Data\\Cache\\Updates.hg")
is False
):
customtkinter.CTkLabel(
scrollFrame,
text="History Not Available",
fg_color="#252525",
text_color="#7f7f7f",
font=("Sitka Small", 50, "bold"),
).pack(side=TOP, anchor="center", pady=200)
else:
customtkinter.CTkLabel(
scrollFrame,
text="Updates",
fg_color="#252525",
text_color="#fff",
font=("Sitka Small", 15, "bold"),
).pack(side=TOP, anchor="w", padx=30, pady=(30, 20))
with open(
application_directory + "\\Data\\Cache\\Updates.hg", "rb"
) as file:
data = pickle.load(file)
for updates in data:
updateDataFrame = customtkinter.CTkFrame(
scrollFrame, fg_color="#175a99", corner_radius=5
)
updateDataFrame.pack(side=TOP, anchor="center", fill=X, padx=30)
self.showFrame(updateHistoryFrame)
# Function to traverse slider
# --------------------------------------------------------------------------------------------------
def traverse(arrayFrame, currentValue, flag):
big_dot = self.ImageObject("Data\\Images\\Slider\\circle.png", 15, 15)
if flag == 1:
mode = currentValue.pop()
mode = (mode + 1) % len(arrayFrame)
currentValue.append(mode)
self.showFrame(arrayFrame[mode])
else:
mode = currentValue.pop()
mode = mode - 1
if mode == -1:
mode = len(arrayFrame) - 1
currentValue.append(mode)
self.showFrame(arrayFrame[mode])
dots = (dot_a, dot_b, dot_c, dot_d, dot_e, dot_f)
for dot in dots:
if dots.index(dot) == mode:
dot.configure(image=big_dot)
else:
dot.configure(image=dot_image)
# ------------------------------------------------------------------------------------------------
# Function to clear cache memory
# ------------------------------------------------------------------------------------------------
def clearCacheMemory():
Cache().clearCacheMemory()
cacheSizeLabel.configure(text=f"{Cache().cacheMemorySize()} KB")
# ------------------------------------------------------------------------------------------------
# Class to handle settings values
# ------------------------------------------------------------------------------------------------
class SettingCommands:
def __init__(self):
pass
def explicitCommandOption(self):
with open(
application_directory + "\\Data\\Cache\\Mili Settings.settings",
"rb+",
) as file:
settingsData = pickle.load(file)
settingsData.update({"Explicit content": explicitContentVar.get()})
file.seek(0)
pickle.dump(settingsData, file)
file.close()
def productEmailCommand(self):
with open(
application_directory + "\\Data\\Cache\\Mili Settings.settings",
"rb+",
) as file:
settingsData = pickle.load(file)
settingsData.update({"Product emails": productEmailVar.get()})
file.seek(0)
pickle.dump(settingsData, file)
file.close()
# ------------------------------------------------------------------------------------------------
# Function to destroy window
# ------------------------------------------------------------------------------------------------
def destroy_window():
self.destroy()
# ------------------------------------------------------------------------------------------------
# Class to reset the password
# ------------------------------------------------------------------------------------------------
class ResetPasswordBackend:
def __init__(self):
resetButtonVariable.set("Resetting...")
self.url = Encryption(
b"gAAAAABkeM77CniuvGNLTxhTXcvvxS4482UUd-YvStyomao17R01SW_7UrXKCjvUfjwrmYRZ-YEztP6Xpb02tF3mDqH42ECzrMYiw2d6hcw2ZeZuIQXzTNvl-ylfk39vReUEseO0KnAIsnkcdJQeHOTvhjufWM5yYEAShBSZ6g_E3qqcy9pWhlA="
).decrypt_text()
self.client = pymongo.MongoClient(self.url)
self.db = self.client["Assistant"]
self.collection = self.db["User Credentials"]
def model(self):
current_password = resetCurrentPasswordEntry.get()
new_password = resetNewPasswordEntry.get()
previous_passwords = self.collection.find_one(
{"email": gmail}, {"previous_passwords": 1}
).get("previous_passwords")
password_list = []
for element in previous_passwords:
password_list.append(element.get("password"))
if (
current_password is None
or new_password is None
or current_password == ""
or new_password == ""
):
messagebox.showwarning(
title="Mili",
message="The password fields for this app are unfilled.\nPlease enter a password in both fields to proceed.",
)
resetButtonVariable.set("Reset")
else:
if current_password == new_password:
messagebox.showerror(
title="Mili",
message="Your password cannot be reused. Please choose a new password.",
)
resetButtonVariable.set("Reset")
return None
elif not Hash.verifyCredential(password, current_password):
messagebox.showerror(
title="Mili",
message="Please check your current password and try again.",
)
resetButtonVariable.set("Reset")
return None
for pwd in password_list:
if Hash.verifyCredential(pwd, new_password):
messagebox.showerror(
title="Mili",
message="Your password cannot be reused. Please choose a new password.",
)
resetButtonVariable.set("Reset")
return None
else:
new_hashed_password = Hash.generateHashedPassword(new_password)
previous_passwords.append(
{
"timestamp": datetime.datetime.timestamp(
datetime.datetime.now()
),
"password": password,
}
)
self.collection.update_one(
{"email": gmail},
{
"$set": {
"password": new_hashed_password,
"previous_passwords": previous_passwords,
}
},
)
CredentialManager().write_credential(gmail, new_hashed_password)
resetUpdateFrame.tkraise()
resetCurrentPasswordEntry.delete(0, END)
resetNewPasswordEntry.delete(0, END)
resetButtonVariable.set("Reset Password")
# ------------------------------------------------------------------------------------------------
# Class to delete account
# ------------------------------------------------------------------------------------------------
class DeleteAccount:
def __init__(self):
self.url = Encryption(
b"gAAAAABkeM77CniuvGNLTxhTXcvvxS4482UUd-YvStyomao17R01SW_7UrXKCjvUfjwrmYRZ-YEztP6Xpb02tF3mDqH42ECzrMYiw2d6hcw2ZeZuIQXzTNvl-ylfk39vReUEseO0KnAIsnkcdJQeHOTvhjufWM5yYEAShBSZ6g_E3qqcy9pWhlA="
).decrypt_text()
self.client = pymongo.MongoClient(self.url)
self.db = self.client["Assistant"]
self.collection = self.db["User Credentials"]
def deleteAccount(self):
try:
self.collection.delete_one({"email": gmail})
messagebox.showinfo(
"Mili", "Your account has been deleted successfully"
)
CredentialManager().delete_credential()
destroy_window()
except:
messagebox.showerror("Mili", "Connection error\nTry Again")
def passwordConfirmation(self):
enteredPassword = passwordEntry.get()
value = agreeCheckBoxVar.get()
if value == 0:
messagebox.showinfo("Mili", "Please accept self declaration")
elif not Hash.verifyCredential(password, enteredPassword):
messagebox.showinfo("Mili", "You have entered incorrect password")
else:
self.deleteAccount()
# ------------------------------------------------------------------------------------------------
# Class to edit profile
# ------------------------------------------------------------------------------------------------
class EditProfile:
def __init__(self):
self.url = Encryption(
b"gAAAAABkeM77CniuvGNLTxhTXcvvxS4482UUd-YvStyomao17R01SW_7UrXKCjvUfjwrmYRZ-YEztP6Xpb02tF3mDqH42ECzrMYiw2d6hcw2ZeZuIQXzTNvl-ylfk39vReUEseO0KnAIsnkcdJQeHOTvhjufWM5yYEAShBSZ6g_E3qqcy9pWhlA="
).decrypt_text()
self.client = pymongo.MongoClient(self.url)
self.db = self.client["Assistant"]
self.collection = self.db["User Credentials"]
self.userName = None
self.phoneNumber = None
self.gender = None
self.date = None
self.month = None
self.year = None
self.email = gmail
self.data = None
self._DOB = None
def updateDataBase(self):
try:
self.collection.update_one(
{"email": self.email}, {"$set": self.data}
)
savingVar.set("Save Profile")
messagebox.showinfo(
"Mili", "You have sucessfully updated your profile"
)
if self.gender == "Male":
genderIcon = maleGenderIcon
elif self.gender == "Female":
genderIcon = femaleGenderIcon
else:
genderIcon = othersGenderIcon
genderLabel.configure(image=genderIcon)
userNameLabel.configure(text=self.userName)
contactNumberLabel.configure(text=self.phoneNumber)
DOB_Label.configure(
text=f'{datetime.datetime.strftime(self._DOB, "%B %d, %Y")}'
)
except:
messagebox.showerror("Mili", "Connection error\nTry Again")
def updateProfile(self):
self.userName = userNameEntry.get()
self.phoneNumber = contactNumberEntry.get()
self.gender = genderVar.get()
self.month = monthVar.get()
self.date = dateEntry.get()
self.year = yearEntry.get()
if self.userName is None or self.userName == "":
messagebox.showwarning("Mili", "Please enter your name")
elif self.phoneNumber is None or len(self.phoneNumber) != 10:
messagebox.showwarning("Mili", "Please enter valid phone number")
elif self.gender is None or self.gender == "":
messagebox.showwarning("Mili", "Please select your gender")
elif (
self.date is None
or len(self.date) > 2
or len(self.date) <= 0
or int(self.date) > 31
):
messagebox.showwarning("Mili", "Please enter valid date of birth")
elif self.month is None or self.month == "":
messagebox.showwarning("Mili", "Please select month")
elif self.year is None or len(self.year) != 4:
messagebox.showwarning("Mili", "Please enter valid year of birth")
else:
try:
self._DOB = datetime.datetime.strptime(
f"{self.date} {self.month} {self.year}", "%d %B %Y"
)
except:
self._DOB = None
if self._DOB is None:
messagebox.showwarning(
"Mili", "Please enter valid Date of Birth"
)
else:
savingVar.set("Saving Profile")
self.data = {
"name": self.userName,
"phone number": self.phoneNumber,
"gender": self.gender,
"DOB": self._DOB,
}
thread = Thread(target=self.updateDataBase)
thread.start()
# ------------------------------------------------------------------------------------------------
# Function for Option
# --------------------------------------------------------------------------------------------------
def Options(mode):
if mode == "Logout":
response = messagebox.askquestion("Mili", "Are you confirmed?")
if response == "yes":
flag = CredentialManager().delete_credential()
if flag is True:
self.destroy()
else:
messagebox.showerror(
"Mili",
"An error occurred during logout. Please try again later.",
)
elif mode == "Edit Profile":
self.showFrame(editProfileFrame)
elif mode == "Delete Account":
self.showFrame(deleteAccountFrame)
elif mode == "Settings":
self.showFrame(settingsFrame)
elif mode == "Reset Password":
self.showFrame(resetPasswordFrame)
elif mode == "Updates":
self.showFrame(updatesFrame)
# --------------------------------------------------------------------------------------------------
credentials = UserCredentials(None)
ID = credentials.get("_id")
gmail = credentials.get("email")
userName = credentials.get("name")
firstName = userName.split()[0]
contactNumber = credentials.get("phone number")
DOB = credentials.get("DOB")
gender = credentials.get("gender")
password = credentials.get("password")
login_details = credentials.get("login_dates")
last_login_location = credentials.get("last_login_location")
last_login_device_model = credentials.get("last_login_device_model")
last_login_coordinates = credentials.get("last_login_coordinates")
last_login_date = credentials.get("last_login_date")
# ---------------------------------------------------------------------------------------------------
self.profileFrame.configure(fg_color="#252525")
self.profileFrame.grid_columnconfigure(1, weight=1)
self.profileFrame.grid_columnconfigure((2, 3), weight=0)
self.profileFrame.grid_rowconfigure((0, 1, 2), weight=1)
line_style = ttk.Style()
line_style.configure("Line.TSeparator", background="#282828")
# SideBar Frame-------------------------------------------------------------------------------------
sidebar_frame = customtkinter.CTkFrame(
self.profileFrame, width=200, fg_color="#171717", corner_radius=0
)
sidebar_frame.grid(row=0, column=0, sticky="nsew")
sidebar_frame.grid_rowconfigure(5, weight=2)
telebot_frame = customtkinter.CTkFrame(
self.profileFrame, fg_color="#252525", corner_radius=0
)
telebot_frame.grid(row=0, column=1, sticky="nsew")
about_frame = customtkinter.CTkFrame(
self.profileFrame, fg_color="#252525", corner_radius=0
)
about_frame.grid(row=0, column=1, sticky="nsew")
securityFrame = customtkinter.CTkFrame(
self.profileFrame, fg_color="#252525", corner_radius=0
)
securityFrame.grid(row=0, column=1, sticky="nsew")
downloadFrame = customtkinter.CTkFrame(
self.profileFrame, fg_color="#252525", corner_radius=0
)
downloadFrame.grid(row=0, column=1, sticky="n", padx=200, pady=150)
userFrame = customtkinter.CTkFrame(
self.profileFrame, fg_color="#252525", corner_radius=0
)
userFrame.grid(row=0, column=1, sticky="nsew")
editProfileFrame = customtkinter.CTkFrame(
self.profileFrame, fg_color="#252525", corner_radius=0
)
editProfileFrame.grid(row=0, column=1, sticky="nsew")
deleteAccountFrame = customtkinter.CTkFrame(
self.profileFrame, fg_color="#252525", corner_radius=0
)
deleteAccountFrame.grid(row=0, column=1, sticky="nsew")
settingsFrame = customtkinter.CTkFrame(
self.profileFrame, fg_color="#252525", corner_radius=0
)
settingsFrame.grid(row=0, column=1, sticky="nsew")
updatesFrame = customtkinter.CTkFrame(
self.profileFrame, fg_color="#252525", corner_radius=0
)
updatesFrame.grid(row=0, column=1, sticky="nsew")
updateHistoryFrame = customtkinter.CTkFrame(
self.profileFrame, fg_color="#252525", corner_radius=0
)
updateHistoryFrame.grid(row=0, column=1, sticky="nsew")
resetPasswordFrame = customtkinter.CTkFrame(
self.profileFrame, fg_color="#FDB0C0", corner_radius=0
)
resetPasswordFrame.grid(row=0, column=1, sticky="nsew")
resetUpdateFrame = customtkinter.CTkFrame(
self.profileFrame, fg_color="#FDB0C0", corner_radius=0
)
resetUpdateFrame.grid(row=0, column=1, sticky="nsew")
# SideBar FrameCode----------------------------------------------------------------------------------
customtkinter.CTkLabel(
sidebar_frame,
fg_color="#171717",
text="",
image=self.ImageObject("Data\\Images\\GUI\\logo.png", 130, 130),
).grid(row=0, column=0, sticky="nsew", padx=15, pady=(10, 30))
profile_button = customtkinter.CTkButton(
sidebar_frame,
corner_radius=5,
height=35,
image=self.ImageObject("Data\\Images\\GUI\\homeRevert.png", 17, 17),
text="Profile",
compound="left",
anchor="w",
fg_color="#171717",
font=("Sitka Small", 14, "bold"),
hover_color="#252525",
command=lambda: self.showFrame(userFrame),
)
profile_button.grid(row=1, column=0, sticky="n")
security_button = customtkinter.CTkButton(
sidebar_frame,
corner_radius=5,
height=35,
image=self.ImageObject("Data\\Images\\GUI\\privacyRevert.png", 17, 17),
text="Security",
compound="left",
anchor="w",
fg_color="#171717",
font=("Sitka Small", 14, "bold"),
hover_color="#252525",
command=lambda: self.showFrame(securityFrame),
)
security_button.grid(row=2, column=0, sticky="n")
about_button = customtkinter.CTkButton(
sidebar_frame,
corner_radius=5,
height=35,
image=self.ImageObject("Data\\Images\\GUI\\aboutRevert.png", 17, 17),
text="About",
compound="left",