rename lan
This commit was merged in pull request #22.
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
from rio import Component, TextStyle, Color, TextInput, Button, Text, Rectangle, Column, Row, Spacer, \
|
||||
EventHandler
|
||||
|
||||
from src.ezgg_lan_manager.services.LocalDataService import LocalDataService, LocalData
|
||||
from src.ezgg_lan_manager.services.UserService import UserService
|
||||
from src.ezgg_lan_manager.types.SessionStorage import SessionStorage
|
||||
from src.ezgg_lan_manager.types.User import User
|
||||
|
||||
|
||||
class LoginBox(Component):
|
||||
status_change_cb: EventHandler = None
|
||||
user_name_input_text: str = ""
|
||||
password_input_text: str = ""
|
||||
user_name_input_is_valid = True
|
||||
password_input_is_valid = True
|
||||
login_button_is_loading = False
|
||||
is_account_locked: bool = False
|
||||
|
||||
async def _on_login_pressed(self) -> None:
|
||||
if await self.session[UserService].is_login_valid(self.user_name_input_text, self.password_input_text):
|
||||
user: User = await self.session[UserService].get_user(self.user_name_input_text)
|
||||
if not user.is_active:
|
||||
self.is_account_locked = True
|
||||
return
|
||||
self.user_name_input_is_valid = True
|
||||
self.password_input_is_valid = True
|
||||
self.login_button_is_loading = False
|
||||
self.is_account_locked = False
|
||||
await self.session[SessionStorage].set_user_id_and_team_member_flag(user.user_id, user.is_team_member)
|
||||
token = self.session[LocalDataService].set_session(self.session[SessionStorage])
|
||||
self.session[LocalData].stored_session_token = token
|
||||
self.session.attach(self.session[LocalData])
|
||||
self.status_change_cb()
|
||||
else:
|
||||
self.user_name_input_is_valid = False
|
||||
self.password_input_is_valid = False
|
||||
self.login_button_is_loading = False
|
||||
self.is_account_locked = False
|
||||
self.force_refresh()
|
||||
|
||||
def build(self) -> Component:
|
||||
user_name_input = TextInput(
|
||||
text=self.bind().user_name_input_text,
|
||||
label="Benutzername",
|
||||
accessibility_label="Benutzername",
|
||||
min_height=0.5,
|
||||
on_confirm=lambda _: self._on_login_pressed(),
|
||||
is_valid=self.user_name_input_is_valid
|
||||
)
|
||||
password_input = TextInput(
|
||||
text=self.bind().password_input_text,
|
||||
label="Passwort",
|
||||
accessibility_label="Passwort",
|
||||
is_secret=True,
|
||||
on_confirm=lambda _: self._on_login_pressed(),
|
||||
is_valid=self.password_input_is_valid
|
||||
)
|
||||
login_button = Button(
|
||||
Text("LOGIN", fill=Color.from_hex("02dac5"), style=TextStyle(font_size=0.9), justify="center"),
|
||||
shape="rectangle",
|
||||
style="minor",
|
||||
color="secondary",
|
||||
margin_bottom=0.4,
|
||||
on_press=self._on_login_pressed
|
||||
)
|
||||
register_button = Button(
|
||||
Text("REG", fill=Color.from_hex("02dac5"), style=TextStyle(font_size=0.9), justify="center"),
|
||||
shape="rectangle",
|
||||
style="minor",
|
||||
color="secondary",
|
||||
on_press=lambda: self.session.navigate_to("./register")
|
||||
)
|
||||
forgot_password_button = Button(
|
||||
Text("LST PWD", fill=Color.from_hex("02dac5"), style=TextStyle(font_size=0.9), justify="center"),
|
||||
shape="rectangle",
|
||||
style="minor",
|
||||
color="secondary",
|
||||
on_press=lambda: self.session.navigate_to("./forgot-password")
|
||||
)
|
||||
|
||||
return Rectangle(
|
||||
content=Column(
|
||||
user_name_input,
|
||||
password_input,
|
||||
Column(
|
||||
Row(
|
||||
login_button
|
||||
),
|
||||
Row(
|
||||
register_button,
|
||||
Spacer(),
|
||||
forgot_password_button,
|
||||
proportions=(49, 2, 49)
|
||||
),
|
||||
margin_bottom=0.5
|
||||
),
|
||||
Text(text="Dieses Konto\nist gesperrt", fill=self.session.theme.danger_color, style=TextStyle(font_size=0.9 if self.is_account_locked else 0), align_x=0.5),
|
||||
spacing=0.4
|
||||
),
|
||||
fill=Color.TRANSPARENT,
|
||||
min_height=8,
|
||||
min_width=12,
|
||||
align_x=0.5,
|
||||
margin_top=0.3,
|
||||
margin_bottom=2
|
||||
)
|
||||
Reference in New Issue
Block a user