fabriquedoc-frontend/login_form.py

23 lines
1 KiB
Python

import streamlit as st
import requests
def login_form():
with st.form(key='authentication'):
username = st.text_input("Username")
password = st.text_input("Password", type="password")
submit_button = st.form_submit_button(label='Login')
if submit_button:
# Send a POST request to your authentication endpoint
response = requests.post(f"{st.session_state['fabriquedoc_endpoint']}/token/",
data={"username": username, "password": password})
if response.status_code == 200:
st.write("Connexion réussie!")
bearer_token = response.json()["access_token"]
# Store the bearer token in the session state
st.session_state['bearer_token'] = bearer_token
st.session_state['logged_in'] = True
else:
st.error("Connexion échouée!")
st.session_state['bearer_token'] = ""
st.session_state['logged_in'] = False