add is_active to login, add account and seating management to user management, redirect to base page on logout
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
from typing import Callable
|
||||
|
||||
from rio import Component, TextStyle, Color, TextInput, Button, Text, Rectangle, Column, Row, Spacer, TextInputChangeEvent
|
||||
from rio import Component, TextStyle, Color, TextInput, Button, Text, Rectangle, Column, Row, Spacer, \
|
||||
EventHandler
|
||||
|
||||
from src.ez_lan_manager.services.UserService import UserService
|
||||
from src.ez_lan_manager.types.SessionStorage import SessionStorage
|
||||
@@ -8,51 +7,49 @@ from src.ez_lan_manager.types.User import User
|
||||
|
||||
|
||||
class LoginBox(Component):
|
||||
status_change_cb: Callable
|
||||
status_change_cb: EventHandler = None
|
||||
TEXT_STYLE = TextStyle(fill=Color.from_hex("02dac5"), font_size=0.9)
|
||||
user_name_input_text: list[str] = [""]
|
||||
password_input_text: list[str] = [""]
|
||||
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[0], self.password_input_text[0]):
|
||||
user: User = await self.session[UserService].get_user(self.user_name_input_text[0])
|
||||
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)
|
||||
await 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
|
||||
await self.force_refresh()
|
||||
|
||||
def build(self) -> Component:
|
||||
def set_user_name_input_text(e: TextInputChangeEvent) -> None:
|
||||
self.user_name_input_text[0] = e.text
|
||||
|
||||
def set_password_input_text(e: TextInputChangeEvent) -> None:
|
||||
self.password_input_text[0] = e.text
|
||||
|
||||
user_name_input = TextInput(
|
||||
text="",
|
||||
text=self.bind().user_name_input_text,
|
||||
label="Benutzername",
|
||||
accessibility_label="Benutzername",
|
||||
min_height=0.5,
|
||||
on_confirm=lambda _: self._on_login_pressed(),
|
||||
on_change=set_user_name_input_text,
|
||||
is_valid=self.user_name_input_is_valid
|
||||
)
|
||||
password_input = TextInput(
|
||||
text="",
|
||||
text=self.bind().password_input_text,
|
||||
label="Passwort",
|
||||
accessibility_label="Passwort",
|
||||
is_secret=True,
|
||||
on_confirm=lambda _: self._on_login_pressed(),
|
||||
on_change=set_password_input_text,
|
||||
is_valid=self.password_input_is_valid
|
||||
)
|
||||
login_button = Button(
|
||||
@@ -91,8 +88,10 @@ class LoginBox(Component):
|
||||
Spacer(),
|
||||
forgot_password_button,
|
||||
proportions=(49, 2, 49)
|
||||
)
|
||||
),
|
||||
margin_bottom=0.5
|
||||
),
|
||||
Text(text="Dieses Konto\nist gesperrt", style=TextStyle(fill=self.session.theme.danger_color, font_size=0.9 if self.is_account_locked else 0), align_x=0.5),
|
||||
spacing=0.4
|
||||
),
|
||||
fill=Color.TRANSPARENT,
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from rio import Component, Column, NumberInput, ThemeContextSwitcher, TextInput, Row, Button, EventHandler
|
||||
|
||||
from src.ez_lan_manager.types.Transaction import Transaction
|
||||
from src.ez_lan_manager.types.User import User
|
||||
|
||||
|
||||
class NewTransactionForm(Component):
|
||||
user: Optional[User] = None
|
||||
input_value: float = 0
|
||||
input_reason: str = ""
|
||||
new_transaction_cb: EventHandler[Transaction] = None
|
||||
|
||||
async def send_debit_transaction(self) -> None:
|
||||
await self.call_event_handler(
|
||||
self.new_transaction_cb,
|
||||
Transaction(
|
||||
user_id=self.user.user_id,
|
||||
value=round(self.input_value * 100),
|
||||
is_debit=True,
|
||||
reference=self.input_reason,
|
||||
transaction_date=datetime.now()
|
||||
)
|
||||
)
|
||||
|
||||
async def send_credit_transaction(self) -> None:
|
||||
await self.call_event_handler(
|
||||
self.new_transaction_cb,
|
||||
Transaction(
|
||||
user_id=self.user.user_id,
|
||||
value=round(self.input_value * 100),
|
||||
is_debit=False,
|
||||
reference=self.input_reason,
|
||||
transaction_date=datetime.now()
|
||||
)
|
||||
)
|
||||
|
||||
def build(self) -> Component:
|
||||
return ThemeContextSwitcher(
|
||||
content=Column(
|
||||
NumberInput(
|
||||
value=self.bind().input_value,
|
||||
label="Betrag",
|
||||
suffix_text="€",
|
||||
decimals=2,
|
||||
thousands_separator=".",
|
||||
margin=1,
|
||||
margin_bottom=0
|
||||
),
|
||||
TextInput(
|
||||
text=self.bind().input_reason,
|
||||
label="Beschreibung",
|
||||
margin=1,
|
||||
margin_bottom=0
|
||||
),
|
||||
Row(
|
||||
Button(
|
||||
content="Entfernen",
|
||||
shape="rectangle",
|
||||
color="danger",
|
||||
margin=1,
|
||||
on_press=self.send_debit_transaction
|
||||
),
|
||||
Button(
|
||||
content="Hinzufügen",
|
||||
shape="rectangle",
|
||||
color="success",
|
||||
margin=1,
|
||||
on_press=self.send_credit_transaction
|
||||
)
|
||||
)
|
||||
),
|
||||
color="primary"
|
||||
)
|
||||
@@ -1,7 +1,7 @@
|
||||
from random import choice
|
||||
from typing import Optional, Callable
|
||||
from typing import Optional
|
||||
|
||||
from rio import Component, TextStyle, Color, Button, Text, Rectangle, Column, Row, Spacer, Link, event
|
||||
from rio import Component, TextStyle, Color, Button, Text, Rectangle, Column, Row, Spacer, Link, event, EventHandler
|
||||
|
||||
from src.ez_lan_manager.components.UserInfoBoxButton import UserInfoBoxButton
|
||||
from src.ez_lan_manager.services.UserService import UserService
|
||||
@@ -38,7 +38,7 @@ class StatusButton(Component):
|
||||
)
|
||||
|
||||
class UserInfoBox(Component):
|
||||
status_change_cb: Callable
|
||||
status_change_cb: EventHandler = None
|
||||
TEXT_STYLE = TextStyle(fill=Color.from_hex("02dac5"), font_size=0.9)
|
||||
user: Optional[User] = None
|
||||
user_balance: Optional[int] = 0
|
||||
@@ -53,6 +53,7 @@ class UserInfoBox(Component):
|
||||
await self.session[SessionStorage].clear()
|
||||
self.user = None
|
||||
await self.status_change_cb()
|
||||
self.session.navigate_to("/")
|
||||
|
||||
@event.on_populate
|
||||
async def async_init(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user