1
0
Fork 0
forked from Fuji/Fuji

Add logging out

This commit is contained in:
mily 2025-04-18 23:42:34 +02:00
parent 8c2ab10eb1
commit 1866f61b05
2 changed files with 36 additions and 3 deletions

View file

@ -1,13 +1,26 @@
import flet as ft
from constants import *
from utils import setthemecolor, setlanguage, restart
from utils import setthemecolor, setlanguage, restart, logout
from i18n import _, set_language
def SettingsPage(page):
# Create the main container to hold everything
main_container = ft.Container()
# Create a custom notification that we'll show/hide
def handle_logout(e):
logout()
restart(e.page)
logout_modal = ft.AlertDialog(
modal=True,
title=ft.Text(_("Logout")),
content=ft.Text(_("Do you want to logout?")),
actions=[
ft.TextButton("Yes", on_click=handle_logout),
ft.TextButton("No", on_click=lambda e: page.close(logout_modal)),
],
actions_alignment=ft.MainAxisAlignment.END,
)
notification = ft.Container(
visible=False,
bgcolor=ft.colors.AMBER_100,
@ -103,6 +116,12 @@ def SettingsPage(page):
on_change=onthemechange
)
]),
ft.Row([
ft.ElevatedButton(
_("Logout"),
on_click=lambda e: page.open(logout_modal)
),
]),
]),
expand=True # Make this container expand to push the notification to the bottom
),

View file

@ -107,3 +107,17 @@ def get_current_month_dates():
def getinitials(full_name):
initials = ''.join([part[0].upper() for part in full_name.split()])
return initials
def logout():
config = configparser.ConfigParser()
config.read(f"{getconfigpath()}/config.ini")
config["Settings"]["islogged"] = "False"
config["User"]["fullname"] = ""
config["User"]["grade"] = ""
config["User"]["semester"] = "1"
if os.path.exists("database.db"):
os.remove("database.db")
with open(f"{getconfigpath()}/config.ini", "w") as file:
config.write(file)