Hi i made login page with MySQL DB and after a succesfull login it supposed to show a form where i should put number from which i run query on GraphQL to search for correct results. After this there should be a list of option to choose what to do, but i’m stuck at moment when i give a number because when i provide a number a space for number disapeer and nothing happens
app.py
def make_hashes(password):
return hashlib.md5(str.encode(password)).hexdigest()
def check_hashes(password,hashed_text):
if make_hashes(password) == hashed_text:
return hashed_text
return False
def init_connection():
return mysql.connector.connect(**st.secrets["mysql"])
conn = init_connection()
c = conn.cursor()
def login_user(username,password):
c.execute("SELECT * FROM users WHERE username = %s AND password = %s",(username,password))
data = c.fetchall()
return data
def main():
st.set_page_config(page_title='Net-Tools', layout="wide")
st.markdown(hide_menu_style, unsafe_allow_html=True)
# if 'market_name' not in st.session_state:
# st.session_state['market_name'] = 'EMPTY'
col1, col2, col3 = st.columns(3)
with col1:
st.write(' ')
with col2:
image = Image.open('path')
st.image(image)
with col3:
st.write(' ')
col4, col5, col6 = st.columns(3)
with col4:
st.write("")
with col5:
username = st.text_input("Username")
password = st.text_input("Password", type='password')
if st.button("Login"):
hashed_pswd = make_hashes(password)
result = login_user(username,check_hashes(password,hashed_pswd))
if result:
st.success("Succesfull {}".format(username))
wybor()
else:
st.warning("Bad Login")
with col6:
st.write("")
def wybor():
try:
market_ip = choose_market()
except IndexError:
st.error("There is no shop with that number")
except UnboundLocalError:
st.text(" ")
try:
if (market_ip):
if connect_to_market(ssh, market_ip):
select_page(ssh)
except UnboundLocalError:
st.text(" ")
utils.py
def choose_market():
shop_number = st.text_input('Shop number', '')
is_number = re.match("^[0-9]{5}$",shop_number)
if not is_number and shop_number:
st.error('Incorrect shop number')
return None
if is_number:
transport = AIOHTTPTransport(url="api-url")
client = Client(transport=transport, fetch_schema_from_transport=False)
params = {"shop_number":shop_number}
query = gql(
"""
query getLocations($shop_number: Int!) {
locations
{
getMany(filters:{shop_number:$shop_number})
{
edges
{
node
{
shop_number
internal_ip
name
}
}
}
}
}
"""
)
try:
result = client.execute(query,variable_values=params)
nodes = result['locations']['getMany']['edges']
if not nodes:
return None
node = nodes[0]['node']
return_result = {
'shop_number': str(node['shop_number']),
'shop_name': str(node['name']),
'ip': node['internal_ip'].replace('100','225')
}
st.session_state['market_name'] = str(node['name'])
return return_result['ip']
except Exception as e:
st.error(f"Bad query: {e}")
def connect_to_market(ssh,market_ip):
print(market_ip)
try:
ssh.connect(hostname=str(market_ip), port=22, username='user',
password='password', allow_agent=False, timeout=None, compress=False)
st.text('Connected!')
st.text(st.session_state['market_name'])
return True
except Exception as e:
st.text('Error ')
return False
def select_page(ssh):
page = st.selectbox("Choose option", tuple(pages))
pages[page](ssh)