Skip to content

Commit

Permalink
Add login menu popup and fixed duplicate logout issue
Browse files Browse the repository at this point in the history
  • Loading branch information
detectiveren committed Jun 6, 2024
1 parent 70640f6 commit 7436181
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 16 deletions.
71 changes: 55 additions & 16 deletions luna.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand All @@ -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
Expand All @@ -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",
)
Expand All @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -644,7 +684,6 @@ def onDisconnect(e: ft.PageDisconnectedException):
except:
print("User wasn't logged in")


page.on_disconnect = onDisconnect


Expand Down
Binary file modified lunaData.db
Binary file not shown.

0 comments on commit 7436181

Please sign in to comment.