I'm new for Taipy. I want to make a simple login process: the default page is login page, after login success, go to the main page. But only single page/multiple pages introduction on Taipy official document pages.
Is there any solution for replacement in Taipy?
You can see here a simple login example. Pages are already built and are not protected. You could use partials to change pages from empty to what they should look like to hide their content.
The mechanism of authentication, authorization, protected pages, and so on is directly integrated into Taipy Enterprise.
from taipy.gui import Gui, notify
login_open = True
username = ''
password = ''
dialog_md = """
<|{login_open}|dialog|title=Login|labels=Create account|on_action=create_account|width=30%|
**Username**
<|{username}|input|label=Username|class_name=fullwidth|>
**Password**
<|{password}|input|password|label=Password|class_name=fullwidth|>
<br/>
<|Sign in|button|class_name=fullwidth plain|on_action=login|>
|>
"""
def create_account(state):
notify(state, "info", "Creating account...")
# Put your own logic to create an account
# Maybe, by opening another dialog
state.username = "Taipy"
state.password = "password"
notify(state, "success", "Account created!")
def login(state):
# Put your own authentication system here
if state.username == "Taipy" and state.password == "password":
state.login_open = False
notify(state, "success", "Logged in!")
else:
notify(state, "error", "Wrong username or password!")
pages = {"/": dialog_md,
"Home": "# Taipy application"}
if __name__ == "__main__":
Gui(pages=pages).run()