diff --git a/luna.py b/luna.py index f960aea..c18e240 100644 --- a/luna.py +++ b/luna.py @@ -318,11 +318,23 @@ def passwordCheck(e): # Takes the input from the password textfield and checks if lunaServerPassword.value == settings.serverPassword: page.session.set("lunaServerPassword", lunaServerPassword.value) page.dialog.open = False - loginDialog() # Calls the login dialog once it has closed the password dialog + displayLoginHub() # Calls the login dialog once it has closed the password dialog else: lunaServerPassword.error_text = "INVALID PASSWORD" lunaServerPassword.update() + def backToLoginHub(e): + page.dialog.open = False + displayLoginHub() + + def loginMenu(e): + page.dialog.open = False + loginDialog() + + def registerMenu(e): + page.dialog.open = False + registerDialog() + # Function for when a user sends a message def sendClick(e): emptyMsg = False @@ -449,7 +461,8 @@ def joinClick(e): lunaUsername = ft.TextField(label="Enter your username", color=messageTypeColor, bgcolor=dialogMessageBoxColor, label_style=ft.TextStyle(size=15, color=messageTypeColor), on_submit=joinClick) lunaPassword = ft.TextField(label="Enter your password", color=messageTypeColor, bgcolor=dialogMessageBoxColor, - label_style=ft.TextStyle(size=15, color=messageTypeColor), on_submit=joinClick, password=True, + label_style=ft.TextStyle(size=15, color=messageTypeColor), on_submit=joinClick, + password=True, can_reveal_password=True) lunaServerPassword = ft.TextField(label="Enter password", color=messageTypeColor, bgcolor=dialogMessageBoxColor, label_style=ft.TextStyle(size=15, color=messageTypeColor), @@ -468,7 +481,9 @@ def joinClick(e): bgcolor=dialogColor, title=ft.Text("Welcome to lunaChat!", color=titleTextColor), content=ft.Column([lunaUsername], tight=True), - actions=[ft.ElevatedButton(text="Login to lunaChat", on_click=joinClick, color=ft.colors.PINK, + actions=[ft.ElevatedButton(text="Back", on_click=backToLoginHub, color=ft.colors.PINK, + bgcolor=dialogButtonColor), + ft.ElevatedButton(text="Login to lunaChat", on_click=joinClick, color=ft.colors.PINK, bgcolor=dialogButtonColor)], actions_alignment="end", ) # Opens the alert dialog welcoming the user to lunaChat and takes the input from the user which is the username @@ -479,7 +494,21 @@ def joinClick(e): bgcolor=dialogColor, title=ft.Text("Register an account on lunaChat!", color=titleTextColor), content=ft.Column([lunaUsername, lunaPassword], tight=True), - actions=[ft.ElevatedButton(text="Join lunaChat", on_click=joinClick, color=ft.colors.PINK, + actions=[ft.ElevatedButton(text="Back", on_click=backToLoginHub, color=ft.colors.PINK, + bgcolor=dialogButtonColor), + ft.ElevatedButton(text="Join lunaChat", on_click=joinClick, color=ft.colors.PINK, + bgcolor=dialogButtonColor)], + actions_alignment="end", + ) + + menu = ft.AlertDialog( + open=True, + modal=True, + bgcolor=dialogColor, + title=ft.Text("lunaChat Login Hub", color=titleTextColor), + actions=[ft.ElevatedButton(text="Login to lunaChat", on_click=loginMenu, color=ft.colors.PINK, + bgcolor=dialogButtonColor), + ft.ElevatedButton(text="Register on lunaChat", on_click=registerMenu, color=ft.colors.PINK, bgcolor=dialogButtonColor)], actions_alignment="end", ) @@ -501,6 +530,16 @@ def loginDialog(): # Display the login alert dialog ) + def registerDialog(): + page.dialog = register + register.open = True + page.update() + + def displayLoginHub(): + page.dialog = menu + menu.open = True + page.update() + def displayPasswordScreen(): # Display the password alert dialog page.dialog = passwordDialog passwordDialog.open = True @@ -509,7 +548,7 @@ def displayPasswordScreen(): # Display the password alert dialog if settings.serverPasswordRequired: # If the server requires a password open up that dialog displayPasswordScreen() else: - loginDialog() + displayLoginHub() # Close the description banner when the user clicks on the close button def closeDisplayDescription(e): @@ -596,20 +635,21 @@ def logOutLunaChat(e): for username in usernamesInUse: writeUsernames.write(username + "\n") + if lunaUsername.value != "": + page.pubsub.send_all(LunaMessage(lunaUser=lunaUsername.value, + lunaText=f"{lunaUsername.value} has logged out of {settings.lunaChatName}'s " + f"lunaChat instance", + lunaMessageType="lunaLoginMessage", lunaKey=0)) + + print(f"LOG (Message Type: lunaLoginMessage) {lunaUsername.value.strip()} has logged out of " + f"{settings.lunaChatName}'s lunaChat instance") + if settings.serverPasswordRequired: # If the server requires a password open up that dialog displayPasswordScreen() else: - loginDialog() - - if lunaUsername.value != "": + displayLoginHub() - page.pubsub.send_all(LunaMessage(lunaUser=lunaUsername.value, - lunaText=f"{lunaUsername.value} has logged out of {settings.lunaChatName}'s " - f"lunaChat instance", - lunaMessageType="lunaLoginMessage", lunaKey=0)) - - print(f"LOG (Message Type: lunaLoginMessage) {lunaUsername.value.strip()} has logged out of " - f"{settings.lunaChatName}'s lunaChat instance") + lunaUsername.value = "" # This the bar on the top of the app that contains the title and icon buttons page.appbar = ft.AppBar( @@ -644,7 +684,6 @@ def onDisconnect(e: ft.PageDisconnectedException): except: print("User wasn't logged in") - page.on_disconnect = onDisconnect diff --git a/lunaData.db b/lunaData.db index 4d116ab..25551cb 100644 Binary files a/lunaData.db and b/lunaData.db differ