Exemple #1
0
def login(username, password, window, remember):
    if username == '' or password == '':
        messagebox.showerror("Error", "Please fill in all the fields")
    else:
        data = server_local.get_user(username)
        if not data:
            messagebox.showerror("Error", "Invalid username or password")
        else:
            if data['Password'] != password:
                messagebox.showerror("Error", "Invalid username or password")
            else:
                if database_local.get_setting('username') != username:
                    try:
                        database_local.create_and_drop_table()
                        database_local.set_setting('username', username)

                        if os.path.isfile(f'images/profile_image/{username}_profile.jpeg'):
                            database_local.set_setting('profile_image', f"{username}_profile.jpeg")
                        else:
                            database_local.set_setting('profile_image', 'default_profile_image.jpeg')
                    except Exception as e:
                        pass

                if remember.get() == 1:
                    database_local.set_setting('remember', 'True')
                else:
                    database_local.set_setting('remember', 'False')

                window.destroy()
                view.default()
def updatestatus(username):
    root = Tk()
    root.title('Change your Status')

    root.state('zoomed')

    root.configure(background = '#ECE5DD')
    root.iconbitmap('images/logo.ico')

    frame = Frame(root, bg="#25D366", width=2000, height=100)
    frame.place(relx=0.00001, rely=0.0000001)

    backimg = Image.open('images/back.webp')
    backimage = backimg.resize((50, 50), Image.ANTIALIAS)
    openbackimage = ImageTk.PhotoImage(backimage, master=frame)

    backbutton = Button(frame, image=openbackimage, command=lambda: [root.destroy(), settings(username)])

    backbutton["border"] = "0"
    backbutton["bg"] = "#25D366"
    backbutton.place(relx=0.02, rely=0.4, anchor=CENTER)
    backbutton.image = openbackimage

    Label(frame,text="Change your Status",bg="#25D366",fg="white",font=('Helvetica',30,'bold')).place(relx=0.275,rely=0.3)

    userdetails = server_local.get_user(username)

    user_image = f'{username}'+'_profile.jpeg'

    proimg = Image.open(f'images/profile_image/{user_image}')
    profileimg = proimg.resize((200, 200), Image.ANTIALIAS)
    openprofileimage = ImageTk.PhotoImage(profileimg,master=root)

    imageLabel = Label(root,image=openprofileimage)
    imageLabel.place(relx=0.425,rely=0.2)

    imageLabel['border'] = 0
    imageLabel['background'] = '#ECE5DD'

    user = f'{username}'

    Label(root,text=user,bg='#ECE5DD',fg='#075E54',font=('Kalpurush',20,'bold')).place(relx=0.45,rely=0.5)

    Label(root,text='Your Current Status:',bg='#ECE5DD',fg='#075E54',font=('Kalpurush',20,'bold')).place(relx=0.001,rely=0.65)

    current_status = userdetails['Status']

    Label(root,text=current_status,bg='#ECE5DD',fg='#075E54',font=('Kalpurush',15,'bold')).place(relx=0.3,rely=0.66)

    Label(root,text='Enter your new status:',bg='#ECE5DD',fg='#075E54',font=('Kalpurush',20,'bold')).place(relx=0.001,rely=0.75)

    new_statusentry = Entry(root, bg='#BEFAFA', relief='flat', width=90, justify='center')
    new_statusentry.place(relx=0.3, rely=0.775)

    Button(root,text='Confirm your new status', bg='#075E54', fg='white',command = lambda : status_back(current_status,new_statusentry.get())).place(relx=0.4,rely=0.9)

    root.mainloop()
Exemple #3
0
def register(username, email, password, repeat_password, window):

    for x in [username, email, password, repeat_password]:
        if x == '':
            messagebox.showerror("Error", "Please fill in all the fields")
            break
    else:
        if not (re.search(regex, email)):
            messagebox.showerror("Error", "invalid Email")
        else:
            if server_local.get_user(username):
                messagebox.showerror("Error", "This username has already been taken!")
            else:
                if password != repeat_password:
                    messagebox.showerror("Error", "The passwords do not match")
                else:
                    server_local.add_user(username, email, password)
                    window.destroy()

                    database_local.create_and_drop_table()
                    database_local.set_setting('username', username)
                    database_local.set_setting('profile_image', 'default_profile_image.png')

                    view.default()
def default(query=''):
    user = db.get_setting('username')
    n = server_local.get_user(user)

    root = Tk()
    root.state("zoomed")
    root.title("Home Page")
    root.configure(background="#ECE5DD")
    root.iconbitmap('images/logo.ico')

    fra = Frame(root, bg="#25D366", width=2000, height=100)
    fra.place(relx=0.00001, rely=0.0000001)

    if query != '':
        backimg = Image.open('images/back.webp')
        backimage = backimg.resize((50, 50), Image.ANTIALIAS)
        openbackimage = ImageTk.PhotoImage(backimage, master=fra)

        backbutton = Button(fra, image=openbackimage, command=lambda: [root.destroy(), default()])

        backbutton["border"] = "0"
        backbutton["bg"] = "#25D366"
        backbutton.place(relx=0.02, rely=0.4, anchor=CENTER)
        backbutton.image = openbackimage

    else:
        pass

    Label(fra, text="HOME", bg="#25D366", fg="white", font=('Helvetica', 25, 'bold')).place(relx=0.32, rely=0.3)

    menuimg = Image.open('images/menu.webp')
    menuimageopen = menuimg.resize((50, 50), Image.ANTIALIAS)
    openmenuimage = ImageTk.PhotoImage(menuimageopen, master=root)

    button1 = Button(fra, bg='#25D366', image=openmenuimage,
                     command=lambda: [root.destroy(), settings()])
    button1.place(relx=0.65, rely=0.5, anchor=CENTER)
    button1.image = openmenuimage

    button1['border'] = 0

    Button(fra, text="Logout", width=10, bg="#075E54", fg="white",
           command=lambda: [db.set_setting('remember', 'False'), root.destroy(),
                            login()]).place(relx=0.55, rely=0.4)

    backimg = Image.open('images/home.png')
    backimage = backimg.resize((50, 50), Image.ANTIALIAS)
    openbackimage = ImageTk.PhotoImage(backimage, master=fra)

    homebutton = Label(fra, image=openbackimage, bg='#25D366')
    homebutton.place(relx=0.29, rely=0.3)

    username = Label(root, font=('Kalpurush', 20, 'bold'), text=f"{user}", bg="#ECE5DD", fg="#075E54")
    username.place(relx=0.5, rely=0.3, anchor=N)

    status = n['Status']

    statusLabel = Label(root,font=('Kalpurush',12,'bold'),text=status,bg='#ECE5DD',fg='#075E54')
    statusLabel.place(relx=0.425,rely=0.35)

    # x = n['ProfilePicture']
    x = db.get_setting('profile_image')

    userimg = Image.open(f'images/profile_image/{x}')
    userimage = userimg.resize((50, 50), Image.ANTIALIAS)
    openuserimage = ImageTk.PhotoImage(userimage, master=root)

    buttonforuserimage = Button(root, image=openuserimage, bg="#ECE5DD",command=lambda: [updateprofilepic(user, root)])

    buttonforuserimage["border"] = "0"
    buttonforuserimage["bg"] = "#ECE5DD"
    buttonforuserimage.place(relx=0.5, rely=0.24, anchor=CENTER)
    buttonforuserimage.image = openuserimage

    pathVar = StringVar()
    searchbar = Entry(root, bg="pink", fg="blue", justify="center", borderwidth=3, textvariable=pathVar)
    searchbar.place(relx=0.5, rely=0.4, width=250, anchor=CENTER)
    searchbar.bind('<KeyPress>', lambda event: [on_keypress(event.char, root, searchbar.get())])
    searchbar.focus()

    mainframe = Frame(root, bg="#ECE5DD")

    if query != '':
        mainframe.grid(row=18, column=10, rowspan=20, columnspan=5, padx=500, pady=300)
        searchbar.delete(0, END)
        searchbar.insert(0, query)
    else:
        mainframe.grid(row=18, column=10, rowspan=20, columnspan=5, padx=500, pady=300)
    canvas = Canvas(mainframe, height=375, bg="#ECE5DD")

    frame = Frame(canvas, bg="#ECE5DD")

    scroll_y = Scrollbar(mainframe, orient="vertical", command=canvas.yview)

    row = 8

    contacts_image = Image.open('images/add_contacts.png')
    add_contacts_image = contacts_image.resize((80, 80), Image.ANTIALIAS)
    open_add_contacts_image = ImageTk.PhotoImage(add_contacts_image, master=root)

    buttonadd_contact = Button(root, image=open_add_contacts_image, bg="#ECE5DD", command=lambda: [root.destroy(), add_contact()])

    buttonadd_contact["border"] = "0"
    buttonadd_contact["bg"] = "#ECE5DD"
    buttonadd_contact.place(relx=0.7, rely=0.9, anchor=CENTER)
    buttonadd_contact.image = open_add_contacts_image

    contactcount = 0

    if query == '':

        contacts = db.get_all_contacts()
    else:
        contacts = db.search_user(query)

    for contact in contacts:

        Button(frame, bg="#34B7F1", text=f"{contact[1]}\t\t {contact[3]}", width=48, height=2,
               anchor="center", justify="center", command=lambda c=contact: [root.destroy(), click(c)]).grid(row=row, column=4)

        img = Image.open(f'images/profile_image/{contact[4]}')

        image = img.resize((30, 30), Image.ANTIALIAS)
        openimg = ImageTk.PhotoImage(image, master=root)

        conbi = Button(frame, image=openimg, command=lambda c = contact : openimage(c[4],c[1]))

        conbi.grid(row=row, column=3)
        conbi.image = openimg
        contactcount += 1
        row += 1

    if len(contacts) == 0:
        Button(frame, text="No results found !!", bg='yellow', width=60, justify='center').grid(row=5, column=4)

    searchimage = Image.open('images/search.png')
    searchimageopen = searchimage.resize((20, 20), Image.ANTIALIAS)
    opensearchimage = ImageTk.PhotoImage(searchimageopen, master=root)

    button1 = Button(root, image=opensearchimage, command=lambda: [default()])
    button1.place(relx=0.6, rely=0.4, anchor=CENTER)
    button1.image = opensearchimage

    canvas.create_window(0, 0, anchor='nw', window=frame)

    canvas.update_idletasks()

    canvas.configure(scrollregion=canvas.bbox('all'), yscrollcommand=scroll_y.set)

    canvas.grid(row=18, column=12, columnspan=2, rowspan=2,pady=7)
    scroll_y.grid(row=18, column=14, rowspan=2, sticky='ns')

    root.mainloop()
def settings(user=db.get_setting('username')):
    s = Tk()
    s.state('zoomed')
    s.title('Settings')
    s.configure(background='#ECE5DD')

    print(server_local.get_user(user))

    s.iconbitmap('images/logo.ico')

    userdetails = server_local.get_user(user)

    frame = Frame(s,bg="#25D366",width=2000,height=100)
    frame.place(relx=0.00001,rely=0.0000001)

    Label(frame,text="SETTINGS",bg="#25D366",fg="white",font=('Helvetica',15,'bold')).place(relx=0.32,rely=0.25)

    backimg = Image.open('images/back.webp')
    backimage = backimg.resize((50, 50), Image.ANTIALIAS)
    openbackimage = ImageTk.PhotoImage(backimage, master=frame)

    backbutton = Button(frame, image=openbackimage,command=lambda: [s.destroy(), default()] )

    backbutton["border"] = "0"
    backbutton["bg"] = "#25D366"
    backbutton.place(relx=0.02, rely=0.4, anchor=CENTER)
    backbutton.image = openbackimage

    x = userdetails['ProfilePicture']

    print(x)

    userimg = Image.open(f'images/profile_image/{x}')
    userimage = userimg.resize((50, 50), Image.ANTIALIAS)
    openuserimage = ImageTk.PhotoImage(userimage, master=s)

    buttonforuserimage = Button(s, image=openuserimage)

    buttonforuserimage["border"] = "0"
    buttonforuserimage["bg"] = "#ECE5DD"
    buttonforuserimage.place(relx=0.5, rely=0.24, anchor=CENTER)
    buttonforuserimage.image = openuserimage

    Label(s, text=f"{user}", bg='#ECE5DD', fg='#075E54', font=('Kalpurush', 20, 'bold')).place(relx=0.45, rely=0.3)

    b = Button(s,text='Change your Password',bg="#ECE5DD",fg="#075E54",font=('Kalpurush', 20, 'bold'),width=90,relief='flat',anchor='w', command = lambda : [s.destroy(),changepassword(user)])
    b.place(relx=0.04,rely=0.4)

    menuimg = Image.open('images/password.jpg')
    menuimageopen = menuimg.resize((50, 50), Image.ANTIALIAS)
    openmenuimage = ImageTk.PhotoImage(menuimageopen, master=s)

    button1 = Button(s, bg="#ECE5DD", image=openmenuimage, anchor = 'w',command= lambda : [s.destroy(),changepassword(user)])
    button1.place(relx=0.02, rely=0.45, anchor=CENTER)
    button1.image = openmenuimage

    b = Button(s,text='Change your Profile Picture',bg="#ECE5DD",fg="#075E54",font=('Kalpurush', 20, 'bold'),width=90,relief='flat',anchor='w')#command = lambda : [s.destroy(),updateprofilepic(user)])
    b.place(relx=0.00001,rely=0.5)

    b = Button(s,text='Change the Theme',bg="#ECE5DD",fg="#075E54",font=('Kalpurush', 20, 'bold'),width=90,relief='flat',anchor='w', command = lambda : [s.destroy(),changetheme()])
    b.place(relx=0.00001,rely=0.6)

    b = Button(s,text='Turn off Notifications',bg="#ECE5DD",fg="#075E54",font=('Kalpurush', 20, 'bold'),width=90,relief='flat',anchor='w')
    b.place(relx=0.00001,rely=0.7)

    b = Button(s,text='Change your status',bg="#ECE5DD",fg="#075E54",font=('Kalpurush', 20, 'bold'),width=90,relief='flat',anchor='w',command = lambda : [s.destroy(),updatestatus(user)])
    b.place(relx=0.00001,rely=0.8)

    b = Button(s,text='About Us',bg="#ECE5DD",fg="#075E54",font=('Kalpurush', 20, 'bold'),width=90,relief='flat',anchor='w',command = lambda : [s.destroy(),aboutus()])
    b.place(relx=0.00001,rely=0.9)


    s.mainloop()
def changepassword(user):

    root = Tk()
    root.title('Change your Password')
    root.state('zoomed')
    root.configure(background='#ECE5DD')
    root.iconbitmap('images/logo.ico')

    fra = Frame(root, bg="#25D366", width=1500, height=120)
    fra.place(relx=0.00001, rely=0.0000001)

    Label(fra, text='Change your Password', bg='#25D366', fg='white', font=('Helvetica', 20, 'bold')).place(relx=0.32, rely=0.4)

    backimg = Image.open('images/back.webp')
    backimage = backimg.resize((50, 50), Image.ANTIALIAS)
    openbackimage = ImageTk.PhotoImage(backimage, master=fra)

    backbutton = Button(fra, image=openbackimage, command=lambda: [root.destroy(), settings()])

    backbutton["border"] = "0"
    backbutton["bg"] = "#25D366"
    backbutton.place(relx=0.02, rely=0.4, anchor=CENTER)
    backbutton.image = openbackimage

    userdetails = server_local.get_user(user)

    profileimage = userdetails['ProfilePicture']

    profileimg = Image.open(f'images/profile_image/{profileimage}')
    profileimage = profileimg.resize((50, 50), Image.ANTIALIAS)
    openprofileimage = ImageTk.PhotoImage(profileimage, master=fra)

    ProfileImage = Button(root, image=openprofileimage)

    ProfileImage["border"] = "0"
    ProfileImage["bg"] = "#ECE5DD"
    ProfileImage.place(relx=0.5, rely=0.3, anchor=CENTER)
    ProfileImage.image = openprofileimage

    profilename = userdetails['Username']

    Label(root, bg='#ECE5DD', text=profilename, fg='#075E54', font=('Kalpurush', 20, 'bold')).place(relx=0.45, rely=0.4)

    currentpassword = '******'*len(userdetails['Password'])

    # Label(root, text='Your Current Password', bg='#ECE5DD',fg='#075E54',font=('Kaplurush',15,'bold')).place(relx=0.02,rely=0.5)

    Label(root, text='Your current password', bg='#ECE5DD', fg='#075E54', font=('Kalpurush', 13, 'bold')).place(relx=0.01, rely=0.6)

    Label(root, text=currentpassword, bg='#ECE5DD', fg='#075E54', font=('Kalpurush', 10, 'normal')).place(relx=0.4, rely=0.6)

    Label(root, text='Enter your new password here:', bg='#ECE5DD', fg='#075E54', font=('Kalpurush', 13, 'bold')).place(relx=0.01, rely=0.7)

    passwordentry = Entry(root, bg='#BEFAFA', relief='flat', width=90, justify='center', show='*')
    passwordentry.place(relx=0.4, rely=0.7)

    Label(root, text='Confirm your password entry:', bg='#ECE5DD', fg='#075E54', font=('Kalpurush', 13, 'bold')).place(relx=0.01, rely=0.8)

    confirmpasswordentry = Entry(root, bg='#BEFAFA', relief='flat', width=90, justify='center', show='*')
    confirmpasswordentry.place(relx=0.4,rely=0.8)

    passimg = Image.open('images/change_password.webp')
    passimage = passimg.resize((50, 50), Image.ANTIALIAS)
    openpassimage = ImageTk.PhotoImage(passimage, master=root)

    passimagebutton = Button(root, image=openpassimage)

    passimagebutton["border"] = "0"
    passimagebutton["bg"] = "#ECE5DD"
    passimagebutton.place(relx=0.4, rely=0.9)
    passimagebutton.image = openpassimage

    Button(root, text='Change your password', bg='#075E54', fg='white',
           command=lambda: [password_back(passwordentry.get(), confirmpasswordentry.get())]).place(relx=0.45, rely=0.925)