Add logging out
This commit is contained in:
parent
8c2ab10eb1
commit
1866f61b05
2 changed files with 36 additions and 3 deletions
|
@ -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()
|
||||
|
||||
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,
|
||||
)
|
||||
|
||||
# Create a custom notification that we'll show/hide
|
||||
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
|
||||
),
|
||||
|
|
16
src/utils.py
16
src/utils.py
|
@ -106,4 +106,18 @@ def get_current_month_dates():
|
|||
|
||||
def getinitials(full_name):
|
||||
initials = ''.join([part[0].upper() for part in full_name.split()])
|
||||
return initials
|
||||
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)
|
Loading…
Add table
Reference in a new issue